20 points (Satisfies all requirements - a job well done):
17 points (Meets general requirements with a few minor problems):
14 points (Serious problems):
10 points (Extremely serious problems but demonstrates some effort and understanding):
5 points (Shows little effort and does not represent passing work):
Your program should then read in the initial configuration (i.e.
generation
0) of live and dead cells from a text file consisting of a rectangular
grid of characters. For testing purposes, you should create this
text file yourself using your favorite text editor (pico, ex, vi,
emacs..).
Before you
try to write the code for reading in this file, you should thoroughly
examine the examples on input file pointers which I showed you in
class.
This code is available on the webpage under Class Code/File
Pointers.
You should copy the code from the second example, create a text file
(called
temp, or whatever else you like) whose contents are just the characters:
12345
12345
12345
12345
12345
just as I showed you in class. Compile and run the example, and then start making modifications to both the example and the text file until you understand how it works. Consult either me or one of the lab tutors if you get stuck in this process. Ultimately the functions you write to read in the text file, and to display the grid should be modifications of this example.
After the initial configuration is read, your program will print the heading: "Generation 0", display the initial grid, print the message: "Press return to continue", and then pause. When the user hits return, the next generation is printed with an appropriate heading and message, and another pause. This process continues until the correct number of generations have been displayed, at which point execution halts.
It is required that you include at least five functions, corresponding to the five subproblems in the structure chart which I showed you. These subproblems were: (1) get the number of generations to compute from the user, with input validation; (2) read in the initial grid from a file; (3) display the current grid with a heading giving the generation number; (4) compute the next generation; and (5) compute the live neighbor counts for the present generation. Note that (5) is a subproblem of (4). The structure chart itself looked like:
LIFE
|
______________|______________
|
|
| |
|
|
| |
(1)
(2)
(3) (4)
|
|
(5)
The number of rows and columns in your world grid must be given by constant macros. Thus your program will work on any size grid and and on any initial configuration file. The name of the initial configuration file will also be defined by a constant macro, as in the second example on the webpage. The characters used to represent live and dead cells (which must also be represented by constant macros) are to be '*' and '.' respectively.
Consider the following very simple algorithm for determining whether cell in the ith row and jth column will be alive on the next generation:
When you have a working prototype test your program on the following 25 by 25 initial grid:
.........................
.........................
.........................
.........................
.........................
.........................
............*............
............*............
........*********........
........*...*...*........
.......*.*.***.*.*.......
........*...*...*........
........*********........
..........*.*.*..........
..........*.*.*..........
..........*.*.*..........
..........*****..........
............*............
............*............
.........................
.........................
.........................
.........................
.........................
.........................
Regardless of which boundary option you have chosen, generation 15 should look like:
.........................
.........................
.........................
.........................
.........................
.........................
.........................
.........................
.........................
.........................
.....*....*...*....*.....
....*..***.*.*.***..*....
....*..*.*.*.*.*.*..*....
.....*.....*.*.....*.....
......*****...*****......
.........................
.........................
.........................
.........................
.........................
.........................
.........................
.........................
.........................
.........................
Then try your program on the following 17 by 28 initial grid.
............................
............................
.......****...*******.......
.....******......*******....
........*****......*****....
............................
............................
........*..*..*.............
........*..*..*.............
........****..*.............
........*..*..*.............
........*..*..*.............
........*..*..*.............
........*******.............
............................
............................
............................
If you have chosen to use the torus option, then generation 34 should look like:
........***..***............
............................
............................
............................
............................
..........**....*...........
................*****.......
.*............*...****......
**.***.......*.......**.....
..****..........******.....*
.*.........**.*.*****.....**
**.........**............***
.............*...........***
..........*...............**
..........*..*.............*
.........**.*.*...........**
.........**..***............
If you have chosen to use the dead boundary option, generation 34 should look like:
............................
............................
............................
............................
...............***..........
...............*..*...**....
................**....**....
............................
...........*................
..........*.*...*...........
...........*...*............
................*...........
............................
...**.......................
..*..*......................
...**.......................
............................