Game of life
We use this kata to develop the concepts of object callisthenics
Last updated
We use this kata to develop the concepts of object callisthenics
Last updated
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, a cell will die, populate or remain unchanged according to a set of rules about its neighbouring cells.
The 'grid' is infinite and is as big or as small as the live cells it contains.
There are two states for a cell:
alive
dead
There are three types of transition for a cell:
a dead cell is born (becomes a live cell)
a live cell dies (becomes a dead cell)
a live cell continues to the next generation (remains a live cell)
The initial pattern constitutes the seed of the system, see the for some known seeds.
The rules continue to be applied repeatedly to create further generations ad infinitum.
The first generation is created by applying the rules below simultaneously to every cell in the seed—births and deaths occur simultaneously - and the discrete moment at which this happens is called a tick (in other words, each generation is a pure function of the preceding one).
At each tick, 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 should live 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 simplest possible seed is one with no live cells. It will stable from the very first tick as no new cells can be born.
The second simplest seeds is one live cell. The cell will die from underpopulation on the first tick and will then be stable from the second tick as no new cells can be born.
Made up of three adjacent cells
Made up of four adjacent cells
This advanced pattern will live through infinite generations.
The Gosper glider gun in action: