Create GOL.Rule
This commit is contained in:
parent
51c91a0b9b
commit
96cccfe750
3 changed files with 30 additions and 2 deletions
26
GOL/Rule.hs
Normal file
26
GOL/Rule.hs
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
module GOL.Rule where
|
||||
|
||||
-- | The rule of a Conway's Game of Life simulation
|
||||
-- describes how a cell changes based on its surrounding
|
||||
-- cells. The official GOL uses one standard rule, but
|
||||
-- this engine allows for an arbitrary rule to be applied.
|
||||
--
|
||||
-- A rule consists of two predicates that take a value
|
||||
-- in the range [0..8], the count of alive cells neighboring
|
||||
-- the current cell, and returns whether that cell will be
|
||||
-- alive in the next generation.
|
||||
data Rule = Rule
|
||||
{
|
||||
-- | A predicate deciding if an alive cell
|
||||
-- will be alive in the next generation.
|
||||
survive :: Int -> Bool,
|
||||
-- | A predicate deciding if a dead cell
|
||||
-- will be alive in the next generation.
|
||||
birth :: Int -> Bool
|
||||
}
|
||||
|
||||
|
||||
-- | The standard GOL rule (S23/B3).
|
||||
standardRule :: Rule
|
||||
standardRule = Rule (`elem` [2,3]) (== 3)
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue