UMBC CMSC201, Computer Science I, Fall '97

Project 4: The Game of Life - Extra Credit

Due: Wednesday, November 26, 1997

For extra credit, you can add code that lets the user play the game of life against the computer. Since adapting the simulation to a game is not an easy problem, this extra credit is worth 25 points. This extra credit is NOT required for the honors section, or anyone else. The code that allows the "Game of Life" to be played as a game must be added to the original project, so at the beginning of the program you should ask the user if he wants to run the simulation or play the game of life against the computer. If the user chooses to play the game, the interval should be set to one, rather that letting the user choose the interval AND the play will continue until there are no more individuals of a specific organism type, rather than asking the user for the duration of the simulation.

Description of the "Game of Life" Game

You will be working with a population that consists of two types of organisms contained within a 15 X 15 square-unit area (225 squares), known as the board. Each square can be empty or it can contain an X indicating the presence of an X organism, or it can contain a O indicating the presence of an O organism.

The next generation of organisms is determined according to the same rules for birth, death and survival as in the simulation (regular project), except births in a square are to be of the same type of organism as the majority of its neighbors.

Example:
If the square is an empty square that has 3 neighbors, there will be a birth in that square. If two of the neighbors are type X and one is type O, then the birth will be of type X.

The initial population, consisting of the presence of either an X individual, an O individual, or the absence of any individuals for each square-unit location are found in the file "game.dat". Basically, the file contains 225 integer values separated by whitespace, where a 1 indicates the existance of an X organism at that location, a 2 indicates the existance of an O organism, and a 0 means there is no life there. You may assume that none of the integers found in the file will be anything other than a 0, a 1, or a 2. I guarantee that there are 225 integers in the file, so checking for EOF is not necessary. Here is the contents of the file:

   
   1 1 1 0 0 0 0 0 0 0 0 0 0 2 2
   1 1 1 0 0 0 0 1 0 0 0 2 2 0 2
   1 1 0 0 0 0 0 0 0 0 0 0 2 0 0
   0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
   0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
   0 0 0 0 0 1 0 0 0 0 0 0 0 0 2
   0 0 0 0 1 1 1 0 0 0 0 0 0 0 0
   0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
   0 0 0 0 0 0 0 0 0 0 2 2 0 0 0
   0 0 0 0 0 0 0 0 0 0 2 2 0 0 0
   0 0 1 0 0 0 0 0 0 0 0 0 2 0 0
   0 0 1 0 0 0 0 0 0 0 0 2 2 0 0
   0 0 0 0 0 0 0 0 0 0 0 0 2 0 2
   0 0 0 0 0 0 0 1 0 0 0 0 2 0 0
   1 0 0 0 0 0 0 0 0 0 0 0 0 0 2


For the input file shown above, the original array should be displayed like this:

   
XXX          OO
XXX    X   OO O
XX          O  
               
               
     X        O
    XXX        
     X         
          OO   
          OO   
  X         O  
  X        OO  
            O O
       X    O  
X             O




More details