The Game of Life is a cellular automaton devised by the British mathematician John Horton Conway in 1970.The "game" 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.
Rules
- Any live cell with fewer than two live neighbors dies, as if caused by under population.
- Any live cell with two or three live neighbors lives on to the next generation.
- Any live cell with more than three live neighbors dies, as if by overcrowding.
- Any dead cell with exactly three live neighbors becomes a live cell, as if by reproduction.
Algorithm
Life patterns are represented as two-dimensional arrays
in computer memory. Typically two arrays are used, one to hold the
current generation, and one in which to calculate its successor. Often 0
and 1 represent dead and live cells respectively. A nested for-loop
considers each element of the current array in turn, counting the live neighbors of each cell to decide whether the corresponding element of
the successor array should be 0 or 1. The successor array is displayed.
For the next iteration the arrays swap roles so that the successor array
in the last iteration becomes the current array in the next iteration.
Examples of patterns
Many different types of patterns occur in the Game of Life, including still lifes, oscillators, and patterns that translate themselves across the board.examples of these three classes are shown below, with live cells shown in black, and dead cells shown in white.Still lifes Oscillators Spaceships
block Blinker (period 2) Glider
Beehive Toad (period 2) LWSS
Loaf Beacon (period 2)
No comments:
Post a Comment