From 96cccfe75090f2b695ec302f5892bf45a1386386 Mon Sep 17 00:00:00 2001 From: kiana-S Date: Mon, 20 Dec 2021 00:59:04 -0500 Subject: [PATCH] Create GOL.Rule --- GOL/Rule.hs | 26 ++++++++++++++++++++++++++ Main.hs | 3 ++- conways-game-of-life.cabal | 3 ++- 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 GOL/Rule.hs diff --git a/GOL/Rule.hs b/GOL/Rule.hs new file mode 100644 index 0000000..7730c85 --- /dev/null +++ b/GOL/Rule.hs @@ -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) + diff --git a/Main.hs b/Main.hs index 6848e70..33c67b6 100644 --- a/Main.hs +++ b/Main.hs @@ -1,4 +1,5 @@ module Main where + main :: IO () -main = putStrLn "Hello" \ No newline at end of file +main = putStrLn "Hello" diff --git a/conways-game-of-life.cabal b/conways-game-of-life.cabal index 165b553..47c6008 100644 --- a/conways-game-of-life.cabal +++ b/conways-game-of-life.cabal @@ -8,5 +8,6 @@ cabal-version: >= 1.8 executable main build-depends: base, - comonad + comonad, + Yampa main-is: Main.hs \ No newline at end of file