Naive implementation of the Game of Life.
Each cell is a gen_server
implementation; there is no supervision tree.
Generate and run a grid with 10 rows and 15 columns:
iex> Life.kick_start { 10, 15 }
Generate and run a grid with 10 rows and 10 columns:
iex> Life.kick_start 10
- Generate the cells, assigning them a state at random (dead or alive)
- Print the current states (red
X
means dead, greenO
means alive) - Compute and apply the new states for each cell according the rules of the game
- If a loop is detected, then stop and print where it would loop. Otherwise, go to (2)
One board to rule them all.
A cell state is represented by a tuple { coord, alive, neighbours }
, where:
coord
: the cell's coordinates, a tuple{ x, y }
alive
: if the cell's alive (:true
or:false
)neighbours
: list of coordinates representing the cell's neighbours. If Elixir/Erlang had memoization like Haskell, this would not be necessary
The board maintain a hashmap of all the cells, the key being the cell's coordinates ({ x, y }
) and the value being a tuple { pid, state }
, where:
pid
: the cell's processus idstate
: the cell's state, refreshed each time the clock ticks (stored so it can be reused for printing etc...)
- Tests
- Supervision
- Use
Tasks
instead of dirtyspawn_link
for the parallel map - Doc