summaryrefslogtreecommitdiff
path: root/src/World
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2023-12-04 20:10:18 -0600
committersanine <sanine.not@pm.me>2023-12-04 20:10:18 -0600
commit899ad0ed13d3e347e2818294f7ed9d8d4d468e94 (patch)
treeaa38d3b8c6980ca9e87f28be550573a3ba15b35e /src/World
parent749df3069669787d2c0a57fb9b9ad66a3605da19 (diff)
refactor: Lattice -> World.Lattice
Diffstat (limited to 'src/World')
-rw-r--r--src/World/Lattice.hs23
-rw-r--r--src/World/Types.hs2
2 files changed, 24 insertions, 1 deletions
diff --git a/src/World/Lattice.hs b/src/World/Lattice.hs
new file mode 100644
index 0000000..257ea50
--- /dev/null
+++ b/src/World/Lattice.hs
@@ -0,0 +1,23 @@
+module World.Lattice
+ ( LatticeCell (..)
+ , Lattice
+ , LatticeRule
+ , updateLattice
+ ) where
+
+
+data LatticeCell a b = LatticeCell { kind :: a, flags :: b } deriving (Show, Eq)
+type Lattice a b = [[LatticeCell a b]]
+type LatticeRule a b = Lattice a b -> Int -> Int -> LatticeCell a b
+
+
+updateLattice :: (Enum a) => Lattice a b -> [LatticeRule a b] -> Lattice a b
+updateLattice lattice rules =
+ let
+ mapRow = \(row, y) -> map
+ (\((LatticeCell k _), x) ->
+ let rule = rules !! (fromEnum k)
+ in rule lattice x y
+ )
+ (zip row [0..])
+ in map mapRow (zip lattice [0..])
diff --git a/src/World/Types.hs b/src/World/Types.hs
index e9be991..78bd5af 100644
--- a/src/World/Types.hs
+++ b/src/World/Types.hs
@@ -104,6 +104,6 @@ instance (Combinable a) => Combinable (AgentPropList a) where
newtype Proposal a b c = Proposal (LatticePropList a b, AgentPropList c) deriving (Show, Eq)
instance (Combinable a, Combinable b, Combinable c) => Combinable (Proposal a b c) where
- identity = Proposal ([], [])
+ identity = Proposal (LatticePropList [], AgentPropList [])
combinable (Proposal (l, a)) (Proposal (l', a')) = (combinable l l') && (combinable a a')
combine (Proposal (l, a)) (Proposal (l', a')) = Proposal (combine l l', combine a a')