Conway's Game of Life.
For details, see the Wikipedia article, https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life.
A cell is either Alive or Dead.
Conceptually, a board is an infinite grid of cells, each of which is either alive or dead.
We model this concept in our program using a function. Specifically,
a function that outputs a CellStatus when you input a Cell.
If you have a Board and Cell, you can find the status of that
Cell by plugging it into the Board.
If you need to create a board, you do so by writing a function whose
variable is a Cell and that returns a CellStatus.
The rules we need to describe in order to make a working Life game can be modeled by these three functions:
nextStatus : Int -> CellStatus -> CellStatus
Given the number of living neighbors and the current cell status, what
should the cell's next status be? Use the rules listed in the Wikipedia
article to write this function.
livingNeighbors : Board -> Cell -> Int
Given the current board and a cell, how many living neighbors does that
cell have? You'll need a tiny bit of geometry to write this function.
nextBoard : Board -> Board
Given the current board, what should the next board be? You should use
your livingNeighbors and nextStatus functions to write this function.
To complete this lab, import this library into your own Elm file,
create an appropriate LifeRules record, and use it in runLife.
module Main exposing (main)
import ElmTeachingTools.Labs.Life exposing (..)
myLifeRules : LifeRules
myLifeRules =
{ -- your code here
}
main =
runLife myLifeRules
A cell is a position in an infinite grid.