Strategy (Forth)
Hot-swap your combat algorithms on the execution stack.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Strategy
ARCANUM SCHOOL: Divination // Battle-Calculation
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// FORTH PATTERN //
\ Battle-Calculation: The Strategy
\ Passing the algorithm (XT) as a parameter.
: SLASH ( -- ) ." Slashing with void-blade!" CR ;
: PIERCE ( -- ) ." Piercing with aether-lance!" CR ;
: EXECUTE-ATTACK ( xt -- )
." Preparing strike... " EXECUTE ;
\ Usage:
\ ' SLASH EXECUTE-ATTACK
\ ' PIERCE EXECUTE-ATTACK
Why hardcode the algorithm when the battlefield is ever-shifting? The Strategy pattern allows you to define multiple distinct algorithms and pass their Execution Tokens (XTs) on the stack. The host execution logic simply consumes the XT, remaining wholly ignorant of the specific spell cast.
Runic Tags:
#behavioral
#strategy
#forth
#tactics