✨ ARCANUM RUNE DIFFICULTY: Adept Behavioral

The Strategy: The Tactician's Tome

Define a family of algorithms, encapsulate each one, and make them interchangeable at runtime.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Strategy
ARCANUM SCHOOL: Divination // Tactics
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CODEX INCANTATION //
class_name PathfindingStrategy extends RefCounted
func find_path(start: Vector2, end: Vector2) -> Array[Vector2]:
    return []

class_name AStarStrategy extends PathfindingStrategy
func find_path(start: Vector2, end: Vector2) -> Array[Vector2]:
    print("Using A* calculations...")
    return [start, end] # placeholder

class_name NavMeshStrategy extends PathfindingStrategy
func find_path(start: Vector2, end: Vector2) -> Array[Vector2]:
    print("Using NavigationServer2D...")
    return [start, end] # placeholder

class_name Navigator extends Node
var _strategy: PathfindingStrategy

func set_strategy(strat: PathfindingStrategy) -> void:
    _strategy = strat

func route(start: Vector2, end: Vector2) -> Array[Vector2]:
    return _strategy.find_path(start, end)

The Strategy pattern empowers an entity with a library of tactical tomes. Instead of hardcoding complex algorithms, you dynamically inject the methodology required—be it A* pathfinding or neural-net targeting. The entity merely executes the chosen stratagem without knowing its inner workings.

Runic Tags: #godot #gdscript #strategy #algorithms #ai