lab exercise

 

life

 

 

Background:

 

The game of Life is a computer simulation of the life and death events of a population of organisms.  This program will determine the life, death, and survival of bacteria from one generation to the next, assuming the starting grid of bacteria is generation zero (0).  The rules for the creation of the next generation are as follows:

 

1.   Every empty cell with three living neighbors will come to life in the next generation.  

 

2.   Any cell with one or zero neighbors will die of loneliness, while any cell with four or more neighbors will die from overcrowding.

 

3.   Any cell with two or three neighbors will live into the next generation.

 

4.   All births and deaths occur simultaneously.

 

 

Assignment:

 

1.   Write a program that solves the game of Life.  The size of the grid will be a square 20 x 20.

 

2.   The original grid of bacteria will be supplied to your program from a text file. 

 

      a.   The first line will contain the number (N) of bacteria locations in the file. 

 

      b.   What follows are N pairs of data, one pair of numbers per line. 

 

      c.   The first value of each line indicates the row location while the second value on the line indicates the column location. 

 

      d.   The data file values are given as:  1<=Row<=20 and 1 <=Col<=20.

 

3.   After your program has initialized the grid with generation 0, your program must allow Life to proceed for 5 generations.

 

4.   Display the final results on the screen and determine the following statistical information:

a.   The number of living cells in the entire board.

b.   The number of living cells in row 10.

c.   The number of living cells in column 10.

 

 


Instructions:

 

1.   A sample run output is given below.  Note, these are the correct answers if you use the data file "life100.txt" provided in the disk subdirectory ap97.

 

 

       12345678901234567890

 

 1           **           

 2          * *           

 3           *        **  

 4                  **  * 

 5                  ** ** 

 6                 * * ** 

 7               * **     

 8               *        

 9            ***  **     

10          ** ** ** **   

11          ******        

12           ** **** **   

13            *  **  ***  

14           *  * *** **  

15            **     ** * 

16           **      **  *

17          * *    **    *

18          * *   ***    *

19          *    *  * **  

20                        

 

 

Number in Row 10 ---> 8

 

Number in Column 10 ---> 5

 

 

Number of living organisms ---> 88