1. Computing

The Game of Life

By July 24, 2006

Follow me on:

Screen Dump from Life Simulation

No, this isn't a philosophical debate but a look at the phenomenon of Cellular Automata (CA). In the 1970s, Martin Gardner in his Scientific American magazine column devoted a lot of article space to a CA called The Game of Life (GOL) invented by an English Mathematician John Conway. It proved to be very popular with readers. I spent a considerable part of my undergraduate time writing Life simulations. It was fun!

GOL has two very simple rules. Imagine a 2d grid where each cell is either live (*) or dead (.) as in the diagram below.

* . *
. . *
. . .

The rules determine whether a live cell remains alive in the next generation or does through starvation or overcrowding and if a dead cell can become alive (birth). This is done by looking at all 8 neighbours in the 3 x 3 grid surrounding each cell.

1 2 3
4 * 5
6 7 8

Rules

  1. If there are three live cells then a dead cell becomes alive
  2. If there are less than two cells or more than three cells then a live cell dies out.

By Rule 2, the first example would create a new live cell as it is a dead cell siurrounded by 3 live cells.

So we start with a grid full of random cells and run it through a few generations. It's fascinating to watch. Now it's very easy to program this algorithm and I'm going to do this as a tutorial but meanwhile, it has been done as an Open Source in C++. This has been done using a quite complex Data Structure (an ADT). You can find it here and its been added to the Code Library. There is also a fascinating technical article about the implementation of GOLLY here.
Comments
March 17, 2008 at 1:38 pm
(1) Uzi says:

Hey mister i need help with a game of life program in my class. The rules are this:

1. Any live cell with fewer than two neighbours dies of loneliness.
2. Any live cell with more than three neighbours dies of crowding.
3. Any dead cell with exactly three neighbours comes to life.
4. Any live cell with two or three neighbours lives, unchanged, to the next generation.

and this is the website to help us understand that:

http://www.math.com/students/wonders/life/life.html

please! i need a C++ cpp program on this!

May 7, 2010 at 9:13 pm
(2) Muslim says:

the code in c++ it is too easy to do!
The beginners can do it easily!
however; thank you, we need more of those games

Leave a Comment

Line and paragraph breaks are automatic. Some HTML allowed: <a href="" title="">, <b>, <i>, <strike>

©2014 About.com. All rights reserved.