Conway's Game of Life with GenServers
This Conway's Game of Life implementation through GenServers mainly serves my learing purposes of OTP usage and testing, as well as build process of an Elixir app.
The game of life is composed by a single Board server of dimension x*y that orchestrate x*y Cell. The Cells are dynamically instanciated through a CellSupervisor. The Runner is used to trigger ticks on the Board and display the state of the game to the user.
sequenceDiagram
participant Runner
participant Board
participant CellSupervisor
participant Cell
participant OtherCell
Runner->>Board: start_game
Board->>CellSupervisor: instantiate cells
CellSupervisor->>Board: cell_references
Board->>Runner: :ok
Runner->>Board: tick
Board->>Cell: compute_next_state
Cell->>OtherCell: get_neighborhood_status
Cell->>Cell: next_state
Cell->>Board: :ok
Board->>Cell: update_state
Cell->>Board: new_state
Board->>Runner: board_state
Runner->>Runner: render board
iex -S mix run --no-halt
# Then in iex, launch the game through the Runner, specifying the dimensions of the board.
Raifu.Runner.start_game(20,20)
The Runner will then display the Game's board and update it upon each tick with the following format :