Be sure you have read, or at least skimmed, the assigned readings for classes through 4/14.
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 my TMail address 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. To give you some practice with make and to reduce code duplication, I've split the code into multiple files and included a Makefile. (NOTE: If you really want to do this homework on a system that doesn't support make, talk to me about options.) The files:
To make it easier to download all these files, I've made a ZIP file containing all of these files, so it will probably be simplest just to download that and unzip it (command unzip on our machines).
NOTE that if you prefer to download individual files, you should use your browser's “download” or “save” function to obtain the makefile rather than copying and pasting text. This is because copy-and-paste will likely replace the tab characters in the file with spaces, with bad consequences (since tabs are semantically significant in makefiles.)
NOTE that downloading files if you're using department computers remotely in text mode is problematical. You can do this from the commmand line if you have the full URL, however, using command wget. For example, to get the ZIP file:
wget http://www.cs.trinity.edu/~bmassing/Classes/CS1120_2020spring/Homeworks/HW08/Problems/hw8.zip
NOTE also that you might want to put the files for this homework in a separate directory, so its makefile doesn't conflict with the one you use for compiling other programs.
You might want to start by just downloading everything and trying compiling the two programs. They won't do anything useful yet, but this will let you check that you know how to build them when you do start writing code.
For this assignment you will develop two programs:
[bmassing@dias04]$ ./game-of-life 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]$ ./game-of-life 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 . . . . . . . . .The starter code doesn't do the update; your mission is to fix it so it does, by filling in the update function in game-of-life-util.c (look for comment FIXME). The two examples are a very minimal check that the program works as intended; you should try some of your own tests as well!
HINT: You might want to look at the code for print_board() (in the common-code files) and read_board() (in the starter program) for examples of how to work with the 2D arrays this program uses.
Here are some sample executions:
[bmassing@dias02]$ ./game-of-life-random 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]$ ./game-of-life-random 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]$ ./game-of-life-random 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]$ ./game-of-life-random 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]$ ./game-of-life-random 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:
For programming assignments, this section should go in the body of the e-mail or in a plain-text file pledge.txt (no word-processor files please). For written assignments, please put it in the text or PDF file with your answers.
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). Text in italics is explanatory or something for you to fill in.
For programming assignments, this section should go in the body of the e-mail or in a plain-text file pledge.txt (no word-processor files please). For written assignments, please put it in the text or PDF file with your answers.
Include a brief essay (a sentence or two is fine, though you can write as much as you like) telling me what if anything you think you learned from the assignment, and what if anything you found interesting, difficult, or otherwise noteworthy.