The magazine of the Melbourne PC User Group

The Game of Life
Ken Holmes

Download program listing here

Programming is fun - or, at least it is when you see something happen on the screen as intended. Those who have not tried it, or have tried half-heartedly, might be tempted to try Conway's LIFE which can supply some vigorous action on the screen from a fairly small program. The code provided will let you put in any desired pattern of live cells and see how they develop. It is shown in QuickBasic code to avoid all those funny line numbers but you can use GWBasic if you must, and if you can manage its clumsy and limited coding resources.

LIFE is a well-known example of Cellular Automata or arrays of cells which automatically react to their environment by living, breeding and dying. They will give your computer's neurons a good workout and, while the results may not change the course of world history, they will give some respite from your mega-wordprocessing and database monsters.

The survival rules for cellular automata may be anything you like but Mr Conway's are:

In each cycle, each cell and its 8 adjacent cells are examined and, if it is alive with 2 or 3 live neighbours, or if it is dead with 3 live neighbours, it remains/becomes alive foe the next cycle.

Different starting patterns give varied results; many die out completely, some leave small stable remnants, some leave the bistable "beacon", some go on forever with patterns waxing and waning and some regularly fire off "gliders" (small groups of cells which go through a short cycle of shapes, being steadily moved in one direction with each cycle).

Though not strictly in accordance with Conway's intentions, in this program you may switch on edge cells outside the red rectangle and they will stay alive, steadily spawning life inside. This code uses the two pages of screen 9 alternately, as this gives 25 percent faster execution than using one page, updating it and copying the Temp array into the Life array. However, edge cells need to be put in the Temp array also in Init and must be redrawn each cycle in Go.

If interested, you are welcome to the code of a larger program which includes preset patterns for several of the above phenomena, including a glider gun-phone. It includes a smaller 16 x 12 cell array which is quicker and may be operated with fixed borders, as here, or with a toroidal universe where the top wraps to the bottom and the right wraps t the left (this is done by using modular arithmetic in the Go subroutine just as in the Init subroutine here. It also has some other automata with different survival rules.

Program listing: ( download in text form from here )

Reprinted from the November 1993 issue of PC Update, the magazine of Melbourne PC User Group, Australia

 

[About Melbourne PC User Group]