friedbrice / elm-teaching-tools / ElmTeachingTools.Labs.Life

Conway's Game of Life.

For details, see the Wikipedia article, https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life.

Basics


type alias Cell =
( Basics.Int, Basics.Int )

A cell is a position in an infinite grid.


type CellStatus
    = Dead
    | Alive

A cell is either Alive or Dead.


type alias Board =
Cell -> CellStatus

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.

Rules


type alias LifeRules =
{ nextStatus : Basics.Int -> CellStatus -> CellStatus
, livingNeighbors : Board -> Cell -> Basics.Int
, nextBoard : Board -> Board 
}

The rules we need to describe in order to make a working Life game can be modeled by these three functions:

Running

runLife : LifeRules -> ElmTeachingTools.Lib.Game.Game State Event

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