From 2f74cb258e53416960a60df9a2bdb456baf59d83 Mon Sep 17 00:00:00 2001 From: kiana-S Date: Mon, 20 Dec 2021 15:26:18 -0500 Subject: [PATCH] Write main engine algorithm --- GOL/Engine.hs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/GOL/Engine.hs b/GOL/Engine.hs index c07b024..46fdbb2 100644 --- a/GOL/Engine.hs +++ b/GOL/Engine.hs @@ -11,3 +11,20 @@ import GOL.Space type GOL f = EnvT Rule (Store f) +getNeighbors :: forall s f a. Space s f => GOL f a -> [a] +getNeighbors = experiment $ neighbors @s @f + +nextState :: Space s f => GOL f Bool -> Bool +nextState = do + selfState <- extract + neighborStates <- getNeighbors + let count = sum . fmap (bool 0 1) $ neighborStates + + Rule survive birth <- ask + return $ if selfState + then survive count + else birth count + + +tick :: Space s f => GOL f Bool -> GOL f Bool +tick = extend nextState \ No newline at end of file