Write main engine algorithm
This commit is contained in:
parent
7412b9e3a7
commit
2f74cb258e
|
@ -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
|
Loading…
Reference in a new issue