The Strategy Incantation
Encapsulating algorithmic combat stances to be dynamically swapped during a duel.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Strategy
ARCANUM SCHOOL: Divination // Tactics
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// MATHEMATICA PATTERN //
(* The Strategies *)
AggressiveStance[power_] := Print["Striking fiercely for ", power * 2, " damage!"];
DefensiveStance[power_] := Print["Guarding, storing ", power, " energy for retaliation."];
EvasiveStance[power_] := Print["Dodging swiftly! ", power, " agility utilized."];
(* The Context (Duelist) *)
ClearAll[CreateDuelist];
CreateDuelist[name_, basePower_] := Module[{stance = AggressiveStance},
<|
"Name" -> name,
"Act" :> stance[basePower],
"ChangeStance" -> Function[newStance,
stance = newStance;
Print[name, " shifted their combat stance."]
]
|>
];
(* Usage *)
duelist = CreateDuelist["Kael", 15];
duelist["Act"];
duelist["ChangeStance"][DefensiveStance];
duelist["Act"];
duelist["ChangeStance"][EvasiveStance];
duelist["Act"];
Runic Tags:
#strategy
#behavioral
#tactics
#pure-functions