This, and all, lab assignments should be done with a partner. See the Wed lab page for information about how you can set up a git repository for your joint lab 1 project.
Lab 1 Partners | ||
Katherine Bertaut and Ames Bielenberg | Nick Felt and Chloe Stevens | |
Steven Hwang and Jordan Singleton | Phil Koonce and Sam White | |
Luis Ramirez and Kyle Erf | Niels Verosky and Elliot Weiser |
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).
Your program will take a number of command line options for initializing the game playing variables (dimensions of the grid, number of iterations, how to initialize the grid), and other options to print out the grid as the computation proceeds or write result to an output file.
In addition, you will add timing code to your program to time the GOL computation (not including the initialization or output phases).
If you'd like, you could use the C code from Wednesday's lab as the starting point for your lab1 solution (you should rename files, wipe out most of their contents, and change the Makefile of course):
cp ~newhall/public/cs87/lab1/* .
./gol {-n n -m m -n k [-s] | -f infile} [-x] [-o outfile] -n n: number of rows in the game board -m m: number of columns in the game board -k k: number of iterations -s: initialize to oscillator board (default is random) -f infile: read in all board config info from a file -x: don't print board out after every iteration -o outfile: print result board to output file -h: print out this help messageYou may additionally add other command line options to initialize the game board to other pre-set patterns ([-s | -b | ... ]).
The command line options specify how to initialize the game and how to run the simulation.
There are two ways to initialize the game:
./gol -f startfile1 # initialize to values read in from a file
./gol -n 20 -m 30 -k 100 -s # initialize 20x30 board to an oscillator pattern ./gol -n 20 -m 30 -k 100 # initialize 20x30 board to a random pattern # setting about 25% of randomly selected # cells to 1 works well, but you can decide
The -x and -o outfile options are optional and work with either initialization mode. The -x option is useful for running timing tests of different sized problems of the sequential version of GOL (we may use this later in the semester). Here are some example command lines:
# initialize 20x30 board to an oscillator pattern, output final # board to a file named "outfile" in the same format as the infile format ./gol -n 20 -m 30 -k 100 -s -o outfile # initialize program from data read in from "infile" and output the final # board to a file named "outfile" in the same format as the infile format ./gol -f infile -o outfile # init from a file and do not print any output to stdout for this run ./gol -f infile -xYour program should handle badly formed command lines (e.g. print out an error message and exit instead of using incompatible or incomplete command line options).
num rows num cols num iterations num of following coordinate pairs (set each (i, j) value to 1 i j i j ...For example, this is an interesting pattern that will start in lower left and walk up to upper right of grid:
30 30 100 5 29 1 28 2 27 0 27 1 27 2A good way to check if your output file is correct is to try to use it as an input file to a subsequent run.
# a run with output: $ gol -n 11 -m 11 -k 21 -s start board: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @ @ @ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - end board: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @ - - - - - - - - - - @ - - - - - - - - - - @ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - total time for 21 iterations of 11x11 is 5.493663 secs # a run with no output (-x) measures just the gol computation (not the printfs): $ gol -n 11 -m 11 -k 21 -s -x total time for 21 iterations of 11x11 is 1.001186 secs