⚙️ ISABELLE RUNE DIFFICULTY: Adept Behavioral

The Strategy

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

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Strategy
ARCANUM SCHOOL: Divination // Tactics
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// ISABELLE PATTERN //
theory Strategy
  imports Main
begin

type_synonym combat_strategy = "nat \<Rightarrow> nat \<Rightarrow> nat"

definition aggressive_strategy :: combat_strategy where
  "aggressive_strategy power defense = power * 2"

definition defensive_strategy :: combat_strategy where
  "defensive_strategy power defense = power + defense"

record combatant =
  strategy :: combat_strategy
  power :: nat
  defense :: nat

definition execute_strategy :: "combatant \<Rightarrow> nat" where
  "execute_strategy c = strategy c (power c) (defense c)"

end
Runic Tags: #isabelle #hol #divination #design-patterns