The State
Mutating a Gallina Ward's behavior in real-time by seamlessly shifting its internal state machine configurations.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: State
ARCANUM SCHOOL: Transmutation // Metamorphosis
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CODEX INCANTATION //
(* Gallina Ward: State *)
Require Import String.
Inductive WardPhase :=
| Dormant
| Active
| Overloaded.
Record WardContext := {
phase : WardPhase;
energy : nat
}.
Definition absorbEnergy (ctx : WardContext) (amount : nat) : WardContext :=
let newEnergy := ctx.(energy) + amount in
match ctx.(phase) with
| Dormant =>
if Nat.leb 10 newEnergy then {| phase := Active; energy := newEnergy |}
else {| phase := Dormant; energy := newEnergy |}
| Active =>
if Nat.leb 100 newEnergy then {| phase := Overloaded; energy := newEnergy |}
else {| phase := Active; energy := newEnergy |}
| Overloaded => {| phase := Overloaded; energy := newEnergy |} (* Locked state *)
end.
Runic Tags:
#state
#gallina
#wards