CMSC 201 The Game of Life
Out: Tuesday 10/1/02
Sun Oct 13 23:59:59 EDT 2002 is on time, but one second later the
date command will
The design document for this project, design2.txt ,
|
You will be working with a population that is 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 organism. Each square, except for the border squares, has eight neighbors; North, South, East, West, NorthEast, SouthEast, SouthWest, and NorthWest.
Generation 1
. | . | . |
X | . | X |
. | X | . |
. | X | . |
X | . | X |
The next generation of organisms is determined according to the following criteria:
Generation 2
. | . | . |
. | X | . |
X | X | X |
X | X | X |
. | X | . |
Generation 3
. | . | . |
X | X | X |
. | . | . |
. | . | . |
X | X | X |
The initial population, consisting of the presence or absence of an individual for each square-unit location are found in the file pop1.dat The first line of the file will contain 2 integers, the first of which is the number of time units in one time interval. The second integer is total number of time units to be used for the entire simulation. The remainder of the file contains 225 integer values separated by whitespace, where a 1 indicates the existance of an organism at that location and a 0 means there is no life there. You may assume that none of the integers found in this part of the file will be anything other than a 0 or a 1. I guarantee that there are 225 integers in this part of the file, so checking for EOF is not necessary.
Here is the contents of the file, pop1.dat:
You will be reading the values found in the file into a two-dimensional array and then displaying the array, labelling it Time: 0. Then, you will need to calculate the next generation, store it in a new array and copy the new array into the original array. This process could go on indefinitely and so "the game of life" is commonly used as a screen saver. For this project, you should only display the array at the appropriate time interval and quit when you reach the last interval. So, for a simulation with a time interval of 3 and a total time of 10, you would display the array at Time: 0, 3, 6, 9 and 10. Note that you always display Time: 0, as well as Time: X, where X is the total amount of time for the entire simulation, which you read in from the data file.
For the input file shown above, the original array should be displayed like this:
There are several data files available for this project. The one shown is
pop1.dat. There is also a pop2.dat, pop3.dat and a pop4.dat, all of which may
be found in my pub directory, /afs/umbc.edu/users/s/b/sbogar1/pub
You should copy these files into your own directory. The executable and these
data files need to be in the same directory. Here's how:
Change directory until you are in the directory where you will write your
code and have the executable, then type the following command at the unix
prompt.
You must use separate compilation for this project and should have a file, called proj2.c, that contains only the function main(). You should also have life.c and life.h, that contain functions related to the game of life and the prototypes for those functions, respectively. You may, of course, have other .c and .h files, as you see fit.
Submit as follows:
submit cs201 Proj2 proj2.c life.c life.h
The order in which the files are listed doesn't matter. However, you must make sure that all files necessary to compile your project are listed.