Game of Life is not as our typical computer games. It is a 'cellular
automaton'. This consists of a collection of cells which,
based on a few mathematical rules, can live, die or multiply.
The Rules:
1. Any live cell with fewer than two live neighbours dies, as if caused by
underpopulation.
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.
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 neighbours 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.
Patterns
Different types of patterns occur in the Game of Life, including still
lifes, oscillators, and spaceships, which are the patterns that translate themselves across the
board.
|
|
|
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 neighbours 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.
Play the game:
Click here to download 'Game of Life' code.
[Expecting Your Valuable Comments]
Thank You
Hi Rasheed nice job here, but the algorithm you told and the game you have uploaded are a bit different in complexity, pls try to illustrate the same with a simple 16X16 or 20X20 frame so i can understand.
ReplyDelete