This lab should be done with a partner of your choosing.
The setup procedure for this lab will be similar to Labs 2, 3 and 4. Those labs probably seem like a long time ago, so let's remind ourselves about the procedure. First, both you and your partner should run setup31 to grab the starting point code for this assignment. Suppose users molly and tejas which to work together. Molly (mdanner1) can start by running
[~]$ setup31 labs/06 tdanner1Once the script finishes, Tejas (tdanner1) should run
[~]$ setup31 labs/06 mdanner1
For the next step only one partner should copy over the starting code
[~]$ cd ~/cs31/labs/06 [06]$ cp -r ~lammert/public/cs31/labs/06/* ./ [06]$ ls Makefile gol.c oscillator.txtNow push the changes to your partner
[06]$ git add * [06]$ git commit -m "lab 6 start" [06]$ git pushYour partner can now pull the changes. In this case if Tejas wishes to get files Molly pushed, he would run
[~]$ cd ~/cs31/labs/06 [06]$ git pullThe starting point code includes: an empty Makefile that you need to implement; gol.c into which you should implement your solution; and oscillator.txt, a sample input file to your program. You should create other input files to test your solution.
Your world is represented by a 2-D array of values (0 or 1). If a grid cell's value is 1, it represents a live object, if it is 0, a dead object. At each discrete time step, every cell in the 2-D grid gets a new value based on the current value of its eight neighbors:
Your 2-D world should be a TORUS; every cell in the grid has exactly eight neighbors. In the torus world, cells on the edge of the grid have neighbors that wrap around to the opposite edge. For example, the grid locations marked with an 'x' are the eight neighbors of the grid cell whose value is shown as 1.
x 1 x 0 0 0 0 x x x 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 x x x 0 0 0 0Conway's Game of Life description from Wikipedia, shows some example patterns you can use to test the correctness of your solution (like Blinker, Toad or Beacon).
Here are some example command lines:
# run with config values read from file1.txt and do not print the board: ./gol file1.txt 0 # run with config file file2.txt and print the board after each step: ./gol file2.txt 1Your program should handle badly formed command lines (e.g. print out an error message and exit).
num rows num cols num iterations num of following coordinate pairs (set each (i, j) value to 1 i j i j ...You can create your own input files in vim or emacs by following the file input format.
For example, a file with the following contents generates an interesting pattern that starts in the lower left and walk up to upper right of grid:
30 30 100 5 29 1 28 2 27 0 27 1 27 2
In addition, you will add timing code to your program to time just the Game of Life computation (the timing should not including the board initialization phase of your code).
-g -WallYour Makefile should have rules for make and make clean commands. Use Makefiles that I have given you as a guide. Here is some basics on writing makefiles
Note: the only calls to usleep and system should be in the print function(s); running with 0 as the second command line option option should include no output of the gameboard nor any calls to sleep functions during the run.
int *init_board( ...Functions that return pointer values, generally return NULL on an error. The caller then will check the return value and decide how to handle a NULL return value.
usleep(200000); // sleep for 200,000 micro seconds (.2 seconds)
struct timeval start_time; ... ret = gettimeofday(&start_time, NULL);See the man page (man gettimeofday for more information.
# a run with output: $ ./gol oscillator.txt 1 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @ - - - - - - - - - - - - - - - - - - @ - - - - - - - - - - - - - - - - - - @ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - total time for 19 iterations of 19x19 is 2.019754 secs # a run with 0 as the second parameter should print no ouput # the total time then measures just the gol computation part because # the printfs and usleeps should not be executed when passed 0 % gol ~/classes/cs31/f13/library/labs/06/oscillator.txt 0 total time for 19 iterations of 19x19 is 0.000381 secsThe starting configuration of the oscillator file board is:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @ @ @ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -As you debug, use config files with small numbers of iterations, and comment out the call to system("clear") so you can examine the results of every iteration.
To submit your code, simply commit your changes locally using git add and git commit. Then run git push while in the labs/06 directory. Only one partner needs to run the final push, but make sure both partners have pulled and merged each others changes. See the section on using a shared repo on the git help page.