summaryrefslogtreecommitdiff
path: root/src/World
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2023-12-05 12:50:56 -0600
committersanine <sanine.not@pm.me>2023-12-05 12:50:56 -0600
commit15a0b3d4658faced5e5e09c582f4c22365b31ad7 (patch)
treecee83ed17447d4c9d2bc2b1e415ccc4255476f2c /src/World
parent899ad0ed13d3e347e2818294f7ed9d8d4d468e94 (diff)
begin implementing applyLatticeProposals
Diffstat (limited to 'src/World')
-rw-r--r--src/World/Lattice.hs32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/World/Lattice.hs b/src/World/Lattice.hs
index 257ea50..d377792 100644
--- a/src/World/Lattice.hs
+++ b/src/World/Lattice.hs
@@ -3,9 +3,17 @@ module World.Lattice
, Lattice
, LatticeRule
, updateLattice
+ , applyLatticeProposals
) where
+import World.Types
+ (Combinable (..)
+ , LatticeProposal (..)
+ , LatticePropList (..)
+ )
+
+
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
@@ -21,3 +29,27 @@ updateLattice lattice rules =
)
(zip row [0..])
in map mapRow (zip lattice [0..])
+
+
+applyLatticeProposals :: (Combinable b) => Lattice a b -> LatticePropList a b -> Lattice a b
+applyLatticeProposals lattice (LatticePropList props) =
+ let
+ update list idx new =
+ let (front, _:back) = splitAt idx list in front ++ (new:back)
+ applyProp l (LatticeProposal (x, y) from to flags) =
+ let
+ row = l !! y
+ cell = row !! x
+ cell' = LatticeCell to (combine flags $ cellFlags cell)
+ in
+ update l y (update row x cell')
+
+ -- replace each cell's flags with the identity
+ lattice' = map
+ (\row -> map
+ (\cell -> cell { flags = identity } )
+ row
+ )
+ lattice
+ in
+ foldl applyProp lattice' props