Skip to main content
Lesson 21 - Two Dimensional Arrays
ZIPPDF (letter)
Lesson MenuPreviousNext
  
L.A.21.1 - Life page 7 of 9

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, for example, bacteria from one generation to the next, assuming the starting grid of bacteria is generation zero. The rules for the creation of the next generation are as follows:

  1. A "neighbor" of a cell is defined as any cell touching that cell, for example the eight blue cells in the diagram are the neighbors of the cell in the middle.

  2. Every empty cell with three living neighbors will come to life in the next generation (a "birth").

  3. Any cell with one or zero neighbors will die of loneliness, while any cell with four or more neighbors will die from overcrowding (a "death").

  4. Any cell with two or three neighbors will live into the next generation (no change).

  5. 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.

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

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

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

    4. 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:

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

    2. The number of living cells in row 10.

    3. 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 provided data file "life100.txt".

           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

*The Game of Life was invented by John H. Conway of Princeton University. It was first described to a wide audience by Martin Gardner in his "Mathematical Games" column in Scientific American, October, 1970.


Lesson MenuPreviousNext
Contact
 ©ICT 2003, All Rights Reserved.