@bramas/simulant-lean 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import Simulant
|
|
2
|
+
|
|
3
|
+
/-! Generated from the IR of component `Lights` by packages/lean-gen. Do not edit. -/
|
|
4
|
+
|
|
5
|
+
set_option linter.unusedVariables false
|
|
6
|
+
|
|
7
|
+
namespace Simulant.Library.Lights
|
|
8
|
+
open Simulant
|
|
9
|
+
|
|
10
|
+
structure World (N : Nat) where
|
|
11
|
+
colorCount : Nat
|
|
12
|
+
lights : List (Nat)
|
|
13
|
+
deriving DecidableEq, Repr
|
|
14
|
+
|
|
15
|
+
structure Fields (N : Nat) where
|
|
16
|
+
slot : Nat
|
|
17
|
+
deriving DecidableEq, Repr
|
|
18
|
+
|
|
19
|
+
/-- The flags declared by `Lights`, with the laws of a composition's flags. -/
|
|
20
|
+
class Flags (F : Type) [FlagSet F] where
|
|
21
|
+
|
|
22
|
+
class Actions (A : Type) where
|
|
23
|
+
light : A → Option (Nat)
|
|
24
|
+
|
|
25
|
+
/-- What the composition gives the component: lenses on the state it owns. -/
|
|
26
|
+
structure Ctx (σ : Sig) where
|
|
27
|
+
world : Lens σ.W (World σ.N)
|
|
28
|
+
fields : Lens σ.X (Fields σ.N)
|
|
29
|
+
|
|
30
|
+
def initWorld {N : Nat} [NeZero N] (colors : Nat) : ND (World N) := do
|
|
31
|
+
let colorCount ← (pure colors)
|
|
32
|
+
let lights ← (pure ([] : List (Nat)))
|
|
33
|
+
pure { colorCount := colorCount, lights := lights }
|
|
34
|
+
|
|
35
|
+
def init_slot {N : Nat} [NeZero N] (colors : Nat) (i : Nat) : ND (Nat) :=
|
|
36
|
+
(pure i)
|
|
37
|
+
|
|
38
|
+
section
|
|
39
|
+
variable {σ : Sig} [FlagSet σ.F] [Flags σ.F] [Actions σ.A]
|
|
40
|
+
|
|
41
|
+
/-- The hooks, on the part of the world the component owns. -/
|
|
42
|
+
def hooks (colors : Nat) (L : Ctx σ) : Hooks σ (World σ.N) where
|
|
43
|
+
beforeLook := fun ts C => pure ⟨id, fun _ => FlagSet.none⟩
|
|
44
|
+
beforeMove := fun ts C ds => (pure (let lights := (B.ofFn ((List.finRange σ.k).length) (fun (i : Nat) => (let previous := (if (decide (i < (((L.world.get C.world).lights).length))) then (((L.world.get C.world).lights)[i]!) else 0); (let updates := ((List.finRange σ.k).filter (fun (a : Fin σ.k) => ((((L.fields.get C.agents[a].fields).slot) == i) && ((ds a).decided) && ((Actions.light (ds a).act).isSome) && (decide (((Actions.light (ds a).act).getD 0) < ((L.world.get C.world).colorCount)))))); (if updates.isEmpty then previous else (updates.map (fun (a : Fin σ.k) => ((Actions.light (ds a).act).getD 0))).sum))))); ({ world := fun x => { x with lights := lights }, raise := fun a => FlagSet.none } : OwnEffect σ (World σ.N))))
|
|
45
|
+
afterMove := fun ts C => pure ⟨id, fun _ => FlagSet.none⟩
|
|
46
|
+
|
|
47
|
+
def component (colors : Nat) (L : Ctx σ) : Component σ :=
|
|
48
|
+
(hooks colors L).toComponent L.world
|
|
49
|
+
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
end Simulant.Library.Lights
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import Simulant
|
|
2
|
+
|
|
3
|
+
/-! Generated from the IR of component `Radius` by packages/lean-gen. Do not edit. -/
|
|
4
|
+
|
|
5
|
+
set_option linter.unusedVariables false
|
|
6
|
+
|
|
7
|
+
namespace Simulant.Library.Radius
|
|
8
|
+
open Simulant
|
|
9
|
+
|
|
10
|
+
structure World (N : Nat) where
|
|
11
|
+
phi : Nat
|
|
12
|
+
deriving DecidableEq, Repr
|
|
13
|
+
|
|
14
|
+
/-- The flags declared by `Radius`, with the laws of a composition's flags. -/
|
|
15
|
+
class Flags (F : Type) [FlagSet F] where
|
|
16
|
+
|
|
17
|
+
class Actions (A : Type) where
|
|
18
|
+
|
|
19
|
+
/-- What the composition gives the component: lenses on the state it owns. -/
|
|
20
|
+
structure Ctx (σ : Sig) where
|
|
21
|
+
world : Lens σ.W (World σ.N)
|
|
22
|
+
|
|
23
|
+
def initWorld {N : Nat} [NeZero N] (phi : Nat) : ND (World N) := do
|
|
24
|
+
let phi ← (pure phi)
|
|
25
|
+
pure { phi := phi }
|
|
26
|
+
|
|
27
|
+
section
|
|
28
|
+
variable {σ : Sig} [FlagSet σ.F] [Flags σ.F] [Actions σ.A]
|
|
29
|
+
|
|
30
|
+
/-- The hooks, on the part of the world the component owns. -/
|
|
31
|
+
def hooks (L : Ctx σ) : Hooks σ (World σ.N) where
|
|
32
|
+
beforeLook := fun ts C => pure ⟨id, fun _ => FlagSet.none⟩
|
|
33
|
+
beforeMove := fun ts C ds => pure ⟨id, fun _ => FlagSet.none⟩
|
|
34
|
+
afterMove := fun ts C => pure ⟨id, fun _ => FlagSet.none⟩
|
|
35
|
+
|
|
36
|
+
def component (L : Ctx σ) : Component σ :=
|
|
37
|
+
(hooks L).toComponent L.world
|
|
38
|
+
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
end Simulant.Library.Radius
|
package/Simulant/Library.lean
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import Simulant.Library.BlackHole
|
|
2
2
|
import Simulant.Library.CrashStop
|
|
3
3
|
import Simulant.Library.CrashAtNode
|
|
4
|
+
import Simulant.Library.Radius
|
|
5
|
+
import Simulant.Library.Lights
|
|
4
6
|
import Simulant.Library.Pebbles
|
|
5
7
|
import Simulant.Library.PersistentReflection
|
|
6
8
|
import Simulant.Library.Visited
|