| |
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:
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.
Every empty cell with three living neighbors will come to life in the next generation (a "birth").
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").
Any cell with two or three neighbors will live into the next generation (no change).
All births and deaths occur simultaneously.
Assignment:
Write a program that solves the game of Life. The size of the grid will be a square 20 x 20.
The original grid of bacteria will be supplied to your program from a text file.
The first line will contain the number(N)of bacteria locations in the file.
What follows are N pairs of data, one pair of numbers per line.
The first value of each line indicates the row location while the second value on the line indicates the column location.
The data file values are given as: 1 <= Row <= 20 and 1 <= Col <= 20 .
After your program has initialized the grid with generation 0, your program must allow Life to proceed for 5 generations.
Display the final results on the screen and determine the following statistical information:
The number of living cells in the entire board.
The number of living cells in row 10.
The number of living cells in column 10.
Instructions:
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.
|