conway's game of life
see also: http://www.bitstorm.org/gameoflife/
The Game of Life is a simulation game that was invented by John Conway, a Cambridge Mathematician and frequent visitor to the U of C, and was first published in Scientific American in October 1970. It is a classic programming example/assignment/pastime.
The game runs on a square two-dimensional array that represents a flat surface. On this surface live 'creatures' - initially the distribution of creatures in the array can be random. Each cell in the array is either occupied (has a creature in it) or empty. Then the program goes into a loop that is intended to simulate the passage of time. Each pass through the loop represents an arbitrary period in time, during which creatures are born or die.
A creature will live at least one more cycle if it has two or three neighbours - it dies of isolation if there are fewer , and of over crowding if there are more.
A creature will be born into an empty cell if exactly three neighbouring cells contain creatures.
A creature will die (of overcrowding, presumably) if it has four (4) or more neighbouring creatures.
To quote from Scientific American: "It is important to understand that all births and deaths occur simultaneously."
You are to write a C++ program to play the Game of Life. The size of the array is 20 rows by 20 columns. An empty cell can be represented by the value 0, and a creature by a 1. There can only be one creature in any cell. Initialize the array using one of the random number generators to flip a 'coin' and place a 1 or 0 in each cell, or by reading in a pre-defined initial 20X20 array of creatures.
You must have a procedure that prints out the entire array after each loop and at the beginning of the game. Print a blank space for an empty cell and a '*' for a creature. For example, a 10X10 array might look like this:
Game of Life: round 3
|
*
|
|
|
|
|
|
|
|
|
|
|
|
*
|
*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
*
|
|
|
|
*
|
|
|
|
|
|
*
|
|
|
*
|
|
*
|
|
|
|
|
*
|
|
|
*
|
*
|
*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Game of Life: round 4
| * | |||||||||
| * | |||||||||
| * | |||||||||
| * | * | * | |||||||
| * | * | * | * | ||||||
| * | * | * | |||||||
| * | * | ||||||||
A heading for each time you print out the array would be nice, and you could also print out which pass through the loop (iteration) this is.
Be wary of the edge of the board.
General Remarks:
Bonus:
Other Notes:
Updated: