gameOfLife: Conway's Game of Life

gameOfLifeR Documentation

Conway's Game of Life

Description

An implementation of Conway's Game of Life, a classical cellular automaton, using the morph function. The gosperGliderGun function provides an interesting starting configuration.

Usage

gameOfLife(init, size, density = 0.3, steps = 200, viz = FALSE,
  tick = 0.5)

gosperGliderGun()

Arguments

init

The initial state of the automaton, a binary matrix. If missing, the initial state will be randomly generated, with a population density given by density.

size

The dimensions of the board. Defaults to the size of init, but must be given if that parameter is missing. If both are specified and size is larger than the dimensions of init, then the latter will be padded with zeroes.

density

The approximate population density of the starting state. Ignored if init is provided.

steps

The number of generations of the automaton to simulate.

viz

If TRUE, the state of the system at each generation is plotted.

tick

The amount of time, in seconds, to pause before plotting each successive generation. Ignored if viz is FALSE.

Details

Conway's Game of Life is a simple cellular automaton, based on a 2D matrix of “cells”. It shows complex behaviour based on four simple rules. These are:

  1. Any live cell with fewer than two live neighbours dies, as if caused by under-population.

  2. Any live cell with two or three live neighbours lives on to the next generation.

  3. Any live cell with more than three live neighbours dies, as if by overcrowding.

  4. Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.

Live and dead cells are represented by 1s and 0s in the matrix, respectively.

The initial state and the rules above completely determine the behaviour of the system. The Gosper glider gun is an interesting starting configuration that generates so-called “gliders”, which propagate across the board.

In principle the size of the board in a cellular automaton is infinite. Of course this is not easy to simulate, but this implementation adds a border of two extra cells around the board on all sides to approximate an infinite board slightly better. These are not visualised, nor returned in the final state.

Value

A binary matrix representing the final state of the system after steps generations.

Author(s)

Jon Clayden <code@clayden.org>

See Also

The morph function, which powers this simulation.

Examples


## Not run: gameOfLife(init=gosperGliderGun(), size=c(40,40), steps=50, viz=TRUE)

mmand documentation built on Feb. 16, 2023, 9:22 p.m.