Thursday 29 November 2012

Conway's Game of Life



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.


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.


           Still lifes

Block Game of life block with border.svg
Beehive Game of life beehive.svg
Loaf Game of life loaf.svg
Boat Game of life boat.svg
                Oscillators




Blinker [period2] Game of life blinker.gif



Toad [period2] Game of life toad.gif



Beacon  [period2] Game of life beacon.gif



Pulsar [period3] Game of life pulsar.gif
                Spaceships

Glider Game of life animated glider.gif
Lightweight spaceship [LWSS] Game of life animated LWSS.gif
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.



Play the game:





Click here to download 'Game of Life' code.




[Expecting Your Valuable Comments]
Thank You

1 comment:

  1. 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