Be sure you have read, or at least skimmed, the assigned readings for classes through 10/10.
Do the following programming problems. You will end up with at least one code file per problem. Submit your program source (and any other needed files) by sending mail to bmassing@cs.trinity.edu with each file as an attachment. Please use a subject line that mentions the course and the assignment (e.g., ``csci 1120 hw 8'' or ``LL hw 8''). You can develop your programs on any system that provides the needed functionality, but I will test them on one of the department's Linux machines, so you should probably make sure they work in that environment before turning them in.
The Game of Life is not so much a game in the usual sense as a set of rules for something called a cellular automaton: There are no players, and once the initial configuration is established, everything that happens is determined by the game's rules. The game is ``played'' on a board consisting of a rectangular grid of cells. Some cells are ``live'' (contain a simulated organism); others are ``dead'' (empty). At each step, a new configuration is computed from the old configuration according to the following rules:
To implement the basic algorithm in a program,
you pretty much need to use 2D arrays.
Writing a complete program is straightforward but more than
I want to ask you to do;
instead I am providing starter code that does everything but
the actual update of the grid:
game-of-life-starter.c.
The program takes two command-line arguments, the name of a file
containing an initial configuration and the number of steps to ``play'';
it prints the initial configuration and then updated configurations
for the specified number of steps.
Sample output for input files
game-of-life-in1.txt
and
game-of-life-in2.txt:
[bmassing@dias04]$ ./a.out game-of-life-in1.txt 4 Initial board: . . . . . . 1 1 1 . . . . . . . . . . . . . 1 . . . . . 1 . . . . . 1 . Board after step 1: . 1 . . . . . 1 . . . . . 1 . . . . . . . . . . . . . 1 1 1 . . . . . . Board after step 2: . . . . . . 1 1 1 . . . . . . . . . . . . . 1 . . . . . 1 . . . . . 1 . Board after step 3: . 1 . . . . . 1 . . . . . 1 . . . . . . . . . . . . . 1 1 1 . . . . . . Board after step 4: . . . . . . 1 1 1 . . . . . . . . . . . . . 1 . . . . . 1 . . . . . 1 . [bmassing@dias04]$ ./a.out game-of-life-in2.txt 4 Initial board: . . . . . . . . . 1 1 . . . . . . 1 1 . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1 . . . . . . 1 1 . . . . . . . . . Board after step 1: . . . . . . . . . 1 1 . . . . . . 1 1 . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1 . . . . . . 1 1 . . . . . . . . . Board after step 2: . . . . . . . . . 1 1 . . . . . . 1 1 . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1 . . . . . . 1 1 . . . . . . . . . Board after step 3: . . . . . . . . . 1 1 . . . . . . 1 1 . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1 . . . . . . 1 1 . . . . . . . . . Board after step 4: . . . . . . . . . 1 1 . . . . . . 1 1 . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1 . . . . . . 1 1 . . . . . . . . .For this assignment you will turn in two programs:
Here are some sample executions:
[bmassing@dias02]$ ./a.out 6 5 .5 1 print 28 live cells at start (fraction 0.777778) Initial board: 1 1 . 1 1 1 1 1 1 . 1 1 . 1 1 1 1 1 1 1 1 1 1 1 1 . . 1 1 . 1 . 1 1 . 1 8 live cells after step 1 (fraction 0.222222) Board after step 1: 1 . . 1 . 1 . . . . . . . . . . . . 1 . . . . . 1 . . . . . . 1 1 1 . . [bmassing@dias02]$ ./a.out 6 7 .5 1 print 18 live cells at start (fraction 0.500000) Initial board: 1 . . 1 1 . . 1 . 1 . 1 . . . 1 1 . . 1 1 1 1 . 1 1 1 . 1 1 1 . . . . . 11 live cells after step 1 (fraction 0.305556) Board after step 1: . . 1 1 1 . . . . . . 1 . 1 . . . 1 1 . . . . . 1 . . . 1 1 1 . . . . . (different seeds give different configurations) [bmassing@dias02]$ ./a.out 6 5 .25 1 print 9 live cells at start (fraction 0.250000) Initial board: . 1 . 1 1 1 . . . . 1 . . 1 . . . . . . . . . . 1 . . . . . . . 1 . . 1 7 live cells after step 1 (fraction 0.194444) Board after step 1: . . . 1 1 1 . . 1 1 1 1 . . . . . . . . . . . . . . . . . . . . . . . . (smaller fraction gives fewer live cells) [bmassing@dias02]$ ./a.out 100 5 .5 10 5141 live cells at start (fraction 0.514100) 2647 live cells after step 1 (fraction 0.264700) 2453 live cells after step 2 (fraction 0.245300) 2437 live cells after step 3 (fraction 0.243700) 2265 live cells after step 4 (fraction 0.226500) 2181 live cells after step 5 (fraction 0.218100) 2127 live cells after step 6 (fraction 0.212700) 2001 live cells after step 7 (fraction 0.200100) 1873 live cells after step 8 (fraction 0.187300) 1852 live cells after step 9 (fraction 0.185200) 1784 live cells after step 10 (fraction 0.178400) [bmassing@dias02]$ ./a.out 100 5 .25 10 2497 live cells at start (fraction 0.249700) 2789 live cells after step 1 (fraction 0.278900) 2338 live cells after step 2 (fraction 0.233800) 2382 live cells after step 3 (fraction 0.238200) 2243 live cells after step 4 (fraction 0.224300) 2137 live cells after step 5 (fraction 0.213700) 2158 live cells after step 6 (fraction 0.215800) 2145 live cells after step 7 (fraction 0.214500) 2028 live cells after step 8 (fraction 0.202800) 2035 live cells after step 9 (fraction 0.203500) 1899 live cells after step 10 (fraction 0.189900)
Hints:
Include the Honor Code pledge or just the word ``pledged'', plus at least one of the following about collaboration and help (as many as apply).2Text in italics is explanatory or something for you to fill in. For programming assignments, this should go in the body of the e-mail or in a plain-text file honor-code.txt (no word-processor files please).
Include a brief essay (a sentence or two is fine, though you can write as much as you like) telling me what about the assignment you found interesting, difficult, or otherwise noteworthy. For programming assignments, it should go in the body of the e-mail or in a plain-text file essay.txt (no word-processor files please).