CIS200 Assignment 8: 10 points, due Thursday, May 8, 10:00pm.

Life is a simple, yet mathematically deep, board game invented by John Conway in 1970. You may read a simple explanation of the game at http://www.math.com/students/wonders/life/life.html, and you can ``play'' some sample games at http://www.tech.org/~stuart/life/life.html.

As you will see from the above web pages, Life is played on a game board where the squares can be empty or occupied by ``cells''. At each round of the game, some cells ``die'' and some new cells are ''born.'' Each board space, x, has 8 neighbors:

+--+--+--+
| 1| 2| 3|
+--+--+--+
| 4| x| 5|
+--+--+--+
| 6| 7| 8|
+--+--+--+
The game starts with some of the spaces occupied by cells (at most one cell per space). The exact rules go as follows:
  1. For each empty space on the board, if the space has exactly 3 neighbor spaces occupied by cells, then a new cell is ``born'' on the space.
  2. For each previously existing cell in a space on the board:

The cells' deaths and births happen simultaneously, and the rules as I have written them above try to clarify this notion by distinguishing the cells that are newly created from the cells that previously existed from the earlier round. For a careful explanation, read http://ddi.cs.uni-potsdam.de/HyFISCH/Produzieren/lis_projekt/proj_gamelife/ConwayScientificAmerican.htm.

Computerized Life

Your assignment is to write a C# program that plays the game of Life. The program builds a 16-by-16 game board and places 10 cells in the middle. The board prints in the command window like this:
................
................
................
................
................
................
................
...XXXXXXXXXX...
................
................
................
................
................
................
................
................

Rounds: 0
Dead cells: 0
Oldest living cell (in rounds): 0
(This is called the ``10 Cell Row'' arrangement and produces a nontrivial repeating pattern of cells.) The dots mark empty spaces, and the Xs mark cells. The statistics at the bottom list the rounds played so far, the number of cells that have already died, and the lifespan (in rounds) of the oldest living cell still on the gameboard. After each round round of Life, the board and statistics are reprinted, like this:
................                             ................
................                             ................
................                             ................
................      and after the          ................    and so on.
................       next round:           ................ 
................                             .....XXXXXX.....
....XXXXXXXX....                             ....X......X....
....XXXXXXXX....                             ...X........X...
....XXXXXXXX....                             ....X......X....
................                             .....XXXXXX.....
................                             ................
................                             ................
................                             ................
................                             ................
................                             ................
................                             ................
 
Rounds: 1                                    Rounds: 2
Dead cells: 2                                Dead cells: 22
Oldest living cell (in rounds): 1            Oldest living cell (in rounds): 2

Assembling the program from classes

This assignment gives us practice at object-oriented design, where we construct a game-board object and construct cell objects that are inserted into the board (when they are born) and removed from the board (when they die). The program will be built from these three classes:
  1. class Cell. This class constructs the cell objects that are placed on the game board. The coding of this class is given to you. (See below.) It will be placed in the file, Board.cs.
  2. public class Board, which is placed in the file, Board.cs. This class constructs the board, remembers the placement of the cells, and keeps the statistics about the rounds, the dead cells, and the oldest living cell. You must write this class.
  3. public class Life, which is a static class that holds the Main function that controls the game. The coding of this class is given to you. Place the class in the file, Life.cs.
The prewritten skeletons of these files can be found at http://www.cis.ksu.edu/~schmidt/200s08Assign/Assign8. Your job is to write the missing functions in Board.cs --- write and test the functions one at a time, in the order they are used in the coding of Life.cs. It is certainly ok to write additional, private functions within class Board.

You can check whether your program is correctly calculating births and deaths of cells by comparing its behavior to the pictures above. You can also use the game board at http://www.tech.org/~stuart/life/life.html to compare, too. (Start with his empty game board, size it at 16-by-16, and place 10 cells in the center row. Then, single-step the game to see what happens.)

Testing and submitting your program

You compile Board.cs like this:
csc /debug+ /t:library Board.cs
This generates a ``library file,'' Board.dll. You next compile Life.cs like this:
csc /debug+ /R:Board.dll Life.cs
and you start the simulation by typing Life.

Each time you change Board.cs you must recompile it.

Do all your work in a folder named Assign8. The folder will hold all the .cs, .dll, .pdb, and .exe files. Zip this folder and submit Assign8.zip at http://www.cis.ksu.edu/~schmidt/200s08/Assign.