You can run game on master node and connect other nodes into cluster. Game will distribute tasks across all connected nodes.
Please see the article about the Distributed Game of Life in Elixir.
The universe of the Game of Life is an infinite two-dimensional orthogonal grid of square cells, each of which is in one of two possible states, alive or dead. Every cell interacts with its eight neighbours, which are the cells that are horizontally, vertically, or diagonally adjacent. At each step in time, the following transitions occur:
- Any live cell with fewer than two live neighbours dies, as if caused by under-population.
- Any live cell with two or three live neighbours lives on to the next generation.
- Any live cell with more than three live neighbours dies, as if by over-population.
- Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.
The initial pattern constitutes the seed of the system. The first generation is created by applying the above rules simultaneously to every cell in the seed—births and deaths occur simultaneously, and the discrete moment at which this happens is sometimes called a tick (in other words, each generation is a pure function of the preceding one). The rules continue to be applied repeatedly to create further generations.
Run first node and print board in loop there.
$ iex --sname node1 -S mix
GameOfLife.BoardServer.start_game
GameOfLife.GamePrinter.start_printing_board
Run second node and add from there a new cells to existing board on the first node.
$ iex --sname node2 -S mix
Node.connect :node1@Artur
Node.list
Node.self
GameOfLife.Patterns.Guns.gosper_glider |> GameOfLife.BoardServer.add_cells
Add cells to board.
cells = [{0, 0}, {1, 0}, {2, 0}, {1, 1}]
GameOfLife.BoardServer.add_cells(cells)
Add pattern to the board.
GameOfLife.Patterns.StillLifes.block |> GameOfLife.BoardServer.add_cells
GameOfLife.Patterns.Guns.gosper_glider |> GameOfLife.BoardServer.add_cells
Add pattern to the board at specific position. Move left bottom corner of the pattern to specified X and Y position.
GameOfLife.Patterns.StillLifes.block |> GameOfLife.PatternConverter.transit(-2, -3) |> GameOfLife.BoardServer.add_cells
Example of RPC.
cells = [{0, 0}, {1, 0}, {2, 0}, {1, 1}]
:rpc.call(:n1@Artur, GameOfLife.BoardServer, :add_cells, [cells])
For example GameOfLife.Patterns.StillLifes.block
is defined in a way the last row
contains cells for the bottom row of the pattern. Left bottom corner of the pattern is at {0, 0}
position. The pattern is always at positive X and Y axis.
https://hex.pm/packages/game_of_life
If available in Hex, the package can be installed as:
-
Add game_of_life to your list of dependencies in
mix.exs
:def deps do [{:game_of_life, "~> 1.0.0"}] end
-
Ensure game_of_life is started before your application:
def application do [applications: [:game_of_life]] end
Documentation online: https://hexdocs.pm/game_of_life
How to generate documentation on your machine:
$ mix hex.docs
$ open doc/index.html
Game Of Life in Elixir is maintained by BeyondScheme.com
Yet another software engineers, are we? We build web applications on a daily basis.
See what we do or hire us to help you with your product.