Skip to main content
ICT
Lesson AB23 - Two-Dimensional Arrays
 
Main   Previous Next
 

LAB ASSIGNMENT AB23.1 page 7 of 9

Life

Background:

The “Game of Life” is a computer simulation of the life and death events of a population of bacterial 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 considered 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 (termed 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 (termed 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 implements 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 (life100.txt).

    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 row 10.

    2. The number of living cells in column 10.

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

Instructions:

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

Number in Row 10 ---> 8

Number in Column 10 ---> 5

Number of living organisms ---> 88

 

Main   Previous Next
Contact
 © ICT 2006, All Rights Reserved.