Homework 4


80 pts., due Apr. 12

Write a program which implements Conway's Game of ``Life.''

Here are the basic rules of the game (note that a cell has eight neighboring cells):

  1. If a cell with no life has exactly three live neighbors, that cell will have life in the next generation.
  2. If a cell with life has two or three live neighbors, then it will survive into the next generation.
  3. If a cell with life has fewer than two live neighbors, that cell will die due to isolation.
  4. If a cell with life has more than three live neighbors, that cell will die due to overcrowding.

Assume that the ``world'' is 20 cells by 20 cells. Use one 2-D array to represent the matrix of cells for the present generation and another 2-D array to represent the next generation. The initial live cell configuration should be read in from a disk file, using the file I/O functions (i.e., don't redirect stdin). The file will consist of records, one per line, giving the x and y coordinates of the initially live cells. The output screen should be cleared and then this initial configuration should be displayed. (The output screen should be cleared using clrscr()before displaying any cell configurations.)

Following this, repeatedly update the cell configuration and display it. This update/display loop should terminate when a ctrl-c interrupt is received. To accomplish this, you will need to install a signal handler for SIGINT. If the update/display loop is controlled by a global flag variable, the handler need only modify the flag to cause the loop to exit.

The final cell configuration should be written to a disk file, again, using the file I/O functions.

The design of your program is very important. Your program should be modular. No function should be longer than a page. Your program should be written so as to be easily modifiable. Use symbolic constants and enumerated types wherever possible. For example, the state of a cell within the cell matrix is an ideal candidate for an enumerated type.

The design of your program should be completed by the time you return from spring break. You will probably need two or three days to implement your design.

Turn-in a listing of your source code, a sample input file, the display of the initial configuration (first generation) resulting from the sample input, and the display of the second generation resulting from the sample input. Use the debugger to set breakpoints to allow you to stop the program at appropriate points to print the generation displays.

Thomas P. Kelliher
Sat Mar 23 12:00:00 EST 1996
Tom Kelliher