Conway's Game of Life

Conway's Game of Life

View on Github ~~>
cellular automata
live demo

Conway’s Game of Life

Conway’s Game of Life is a cellular automaton devised by the British mathematician John Horton Conway in 1970. It is a zero-player game, meaning that its evolution is determined by its initial state, requiring no further input. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. It is Turing complete and can simulate a universal constructor or any other Turing machine.

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 by underpopulation.
  • 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 overpopulation.
  • 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 can be thought of as a ‘generation’. The rules continue to be applied repeatedly to create further generations.


The implementation is a simple Javascript implementation of the game. The grid is a 2D array of cells, each of which has a state of either alive or dead. The grid is rendered using Svelte. The game is updated by iterating over the grid and applying the rules to each cell. The rules are applied to a copy of the grid, and then the copy is swapped with the original grid. This is done to prevent the rules from being applied to the same grid that is being iterated over.

The game is paused by default, and can be started by clicking the play button. The game can be reset by clicking the reset button. Users can also draw on the grid by clicking and dragging. The grid can be cleared by clicking the clear button.

Future Improvements

  • Add a speed slider to control the speed of the game.
  • Add a slider to control the size of the grid.
  • Add a slider to control the size of the cells.

The Code

The code for this demo can be found on GitHub.


© 2024 Joshua Gracie
Thanks for stopping by! Don't forget to check out my LinkedIn 💼 and TryHackMe