Robson » Little Red Book » Game of life

Chapter 9 - Question 12

Imagine an immense grid like an infinite chess board. Each space on the grid is a cell and the entire grid is a cellular space. Each cell is identical and can sense its eight neighbouring cells.

Each cell can exist in one of two states: it is either alive or not alive (quiescent). The cellular space changes with time; time advances over the entire space at once, in steps. Each of these steps is called a generation.

The rules which determine the state of a given cell in the next generation are simple yet have far from simple consequences.

Each cell presently alive which has either two or three of its eight neighbouring cells alive will be living in the next generation.

Each cell presently alive which has less than two or more than three live neighbours will not be alive in the next generation.

A presently quiescent cell with exactly three live neighbours will be alive in the next generation.

These rules are applied all at once to the entire space, which should be as large as possible - what happens at the edges is undefined.

Design a program to simulate this cellular life on the VDU.

Solution 1

I found this a really fascinating program to write because it's very simple, but the possibilities seem endless.

I was originally going to write it in PHP with GD2 but decided against that because I wanted it to be "running" rather than snapshots of the current state. I don't have enough knowledge of C++ to write it in that language so I turned to VB.

The rules work exactly how they should do. A set of active cells at the start is loaded from a file and then the program starts generating the state. The user can change the refresh rate and pause/play the program.

Here's a screenshot of the program in action:

The Game of Life

I've written a few classic shapes into the starting state. There's a blinker (bottom left), toad (top left), pentadecathlon (bottom right) and the queen bee shuttle with blocks (top right). The active.txt file has a glider, which is commented out. You can add that in by removing the apostrophes. It's commented out because it moves around and runs into other shapes.

Download the 'Game of Life' VB Project. (RAR, 2.04kB)

This solution meets the requirements, but I would like to make some improvements in the future:


© 2004-17 robson | cc unless stated