Print this page

Conway's Game of Life

The best-known, most ubiquitous, and probably the simplest model of artificial life was invented by British mathematician John Conway in 1970. It is called, appropriately enough, LIFE. Conway's LIFE is a kind of mathematical game played with cellular automata (usually) on a two-dimensional plane divided into a grid of cells, like a checkerboard. Each cell performs some simple calculation based on itself and the other cells in its neighborhood. In the case of LIFE, a cell is born, lives, and dies depending on the number of neighbors it has [Cla94].

More information about Conway's Game of Life can be found at math.com.

This sample program was written to learn the fundamentals of VB.NET including graphics, for which the .NET framework provides a rich set of classes. Double buffering is used to prevent flickering. For performance optimization the cells are drawn from a bitmap created once at simulation start, in a sense similar to "blitting" when working directly with the GDI routines. To have the program running continuously a timer is used. Whenever the timer goes off a new generation is computed. When a pretty pattern has evolved on the screen the program can be paused to store it in a file. The ability to open and save files is implemented by using the XML serializer of .NET.

The simulation is played on an infinite plane. To let the patterns grow in all directions without restraint the edges are made to wrap around, so that a pattern going off one side will reappear on the opposite side. A new patten generation is computed according to these rules:

  • If a currently living cell has less than two or more than three neighbours it becomes dead, otherwise it remains alive.
  • If a currently dead cell has exactly three neighbours it is reborn, otherwise it stays dead.

A new simulation starts with a random scattering of cells. Individual cells can be turned on or off by clicking in the window. Alternatively an empty window can be shown allowing users to draw patterns from scratch. The window size is constrained to exactly show the cells playground, users aren't allowed to resize it.

Since computing the next generation of cells requires to know each cell's position and its neighbours of the current generation, two two-dimensional arrays are used for computations internally. Whilst one of the arrays contains the cells of the current generation the other gets filled with the next generation. After displaying the next generation the arrays swap and the one used beforehand for the next generation becomes the one with the current generation and vice versa.

For completeness the program has all the typical features of a SDI application such as menu, toolbar and a status bar. Program settings which get stored at program exit and restored at next program start can be changed in a dialog window. Defining or modifying the settings associated with a VB.NET project can be done by the programmer in a noteworthy easy-to-use form.

Download

Installation Files

These files are for installing the Life program on your computer.

LifeSetup.msi Windows installer file for Life.
LifeSetup.exe
Self-extracting Windows setup executable for Life.
Life.exe Standalone executable of Life, should run without installation on completely equipped Windows systems.

Predefined Patterns

These files contain predefined typical patterns that can be loaded into Life.

glider.life If left to itself it will glide across the plane forever.
glider_gun.life Given an infinite plane to grow on, the glider gun will run forever and grow to an infinite size.
glider_eater.life The glider eater is a stable, nongrowing pattern that consumes other patterns.
pi_heptomino.life Consisting of seven living cells arranged in an inverted U shape, reminiscent of the greek letter pi, it churns on and on.
r_pentomino.life From a starting pattern of only five live cells, the R pentomino produces an amazing amount of activity and confusion.

Source Code

Life.sln.zip Visual Studio project files including all source codes of Life.

Previous page: About VB.NET
Next page: About OpenGL