Advanced Placement Computer Science AB:
Assignment 7:  John Conway's Game of Life
    Sewickley Academy, 2000-2001

See Course Home Page.
 
Date Assigned: Fri Sep-29
Date Due: Tue Oct-3

(Note:  lest it go unnoticed, the point of this exercise is to become yet more facile using 2D matrices in C++.)

Back in the April 1970 issue of Scientific American (p. 120), John Conway invented a simple "game" called Life.  It is not a game, really, but demonstrates cells reproducing under competitive pressures.  The "rules" are very simple:

1.  You start with an NxN 2D matrix of cells.  Some are initially occupied, others empty.

2.  You determine the next "generation" of cells as follows:

2a. Note that each cell has up to 8 neighbors (up,down,left,right,diagonals), though some cells may have fewer because they are on the edges of the matrix.

2b. If an occupied cell has 0 or 1 neighbors, the organism in that cell dies of loneliness and the cell becomes unoccupied.

2c. If an occupied cell has 2 or 3 neighbors, the organism in that cell survives and the cell remains occupied.

2d. If an occupied cell has 4 or more neighbors, the organism in that cell dies of overcrowding and the cell becomes unoccupied.

2e. If an unoccupied cell has exactly 3 occupied neighbors, then an organism is born there, and the cell becomes occupied.

That's it.

Your task here is to write a "Life simulator", which lets the user enter a board size and an initial configuration (though you should provide a couple defaults, too), and then your program will endlessly create new generations by the rules above.  In order to verify that it is working properly, it should print out the board after every K generations (where the user enters K).

Also, you may wish to seek out help online regarding the game of Life.  There are many, many examples, including demos which will run in a browser.  This step, though, is not required (writing the code, though, is!).

Happy weekend.

DK



See Course Home Page.