Game of life

We use this kata to develop the concepts of object callisthenics

Overview

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.

More information can be found on Wikipedia: https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life

Objectives

Basis

  • 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 examples section for some known seeds.

  • The rules continue to be applied repeatedly to create further generations ad infinitum.

Game rules

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.

Examples

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.

Any seed with no triominos (three adjacent cells), regardless of the total number of live cells, cannot live past the first tick as no new cells can be born.

Basic multi-generation seeds

Triominos

Made up of three adjacent cells

Credit: http://pi.math.cornell.edu/~lipa/mec/lesson6.html

Tetrominos

Made up of four adjacent cells

Credit: http://pi.math.cornell.edu/~lipa/mec/lesson6.html

The Gosper glider gun

This advanced pattern will live through infinite generations.

Credit: https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life

The Gosper glider gun in action:

Credit: Kieff - Own work, CC BY-SA 3.0, https://commons.wikimedia.org/w/index.php?curid=101736

Last updated