CS253 HW2: ¡Livin’ La Vida Conway!
Changes
Updates to the assignment will be noted here. None yet!
                
Description
For this assignment, you will write a program that computes the next
generation in Conway’s Game of Life.
                
Arguments
If no arguments are given, read the initial state from standard input.
Otherwise, the first argument must be a filename—read the initial state
from that file.
                
Input format
The input is a number of lines containing only period (.
) and
capital letter O (O
) characters. For example:
                
..O..
.....
O..OO
...OO
There must be at least two lines, each at least two cells wide.
Each line must have the same length.
                
Operation
Conway’s Game of Life is a cellular automaton. It a rectangular
wraparound universe of cells. The rightmost cell in each row is
considered to be adjacent to the leftmost cell in the same row.
Similarly, the topmost cell is adjacent to the bottommost cell in a
column.
                
- Every cell is alive or dead. Never having been alive is
the same as being dead.
- Alive is represented by a capital letter O:
O
- Dead is represented by a period:
.
- A cell has eight neighbors, the cells next to it, either horizontally,
vertically, or diagonally. All cells have exactly eight neighbors,
possibly taking wraparound into account. In both of these examples,
the cell E has the neighbors ABCDFGHI:
......... F......DE
...ABC... I......GH
...DEF... .........
...GHI... .........
......... C......AB
- Each generation, a rule is applied, to decide what will be in
a cell for the next generation:
- If a cell is alive, then it stays alive for the next generation
iff it has exactly two or three neighbors.
- If a cell is dead, then it becomes alive for the next generation
iff it has exactly three neighbors.
The population for generation N +1 is computed entirely on
the state of generation N. For example, when computing the next
state for cells in row 5, make sure to use the cells for row 4 from the
previous generation, and not the new cells computed for the next
generation.
                
Sample Runs
Here are sample runs, where %
is my prompt.
% cmake .
… cmake output appears here …
% make
… make output appears here …
% cat block3
....
.OO.
.O..
....
% ./hw2 <block3
....
.OO.
.OO.
....
% cat block
....
.OO.
.OO.
....
% ./hw2 block
....
.OO.
.OO.
....
% cat blinker
....
.O..
.O..
.O..
....
% cat blinker | ./hw2
....
....
OOO.
....
....
% ./hw2 <blinker | ./hw2
....
.O..
.O..
.O..
....
% cat jack
...O..............O..
...O...OO.O...OO..O.O
...O..O..O...O....OO.
O..O..O..O...O....OO.
.OO....OO.O...OO..O.O
% ./hw2 jack
O..O.............OO..
..OOO..OOO....O..OO..
..OOO.O..OO..O...O...
OO.O..O..OO..O...O...
OOOO...OOO....O..OO.O
% ./hw2 jack | ./hw2
O...............O...O
.O...O.OOOO.....O....
......O......OO.OO...
.....OO......OO.OO..O
...OO..OOOO.....O..OO
% ./hw2 jack | ./hw2 | ./hw2
O...O.O........OOO.OO
O.....OOOO......O....
........OO...OO......
....OOO.OO...OO...OOO
....OOOOOO......O..O.
% ./hw2 jack | ./hw2 | ./hw2 | ./hw2
O...O..........O.OOO.
O....OO..O....O.OO...
..........O..OOO...OO
....O.....O..OOO..OOO
O..O.....O....O.O....
% ./hw2 jack | ./hw2 | ./hw2 | ./hw2 | ./hw2
OO..OO........O...O..
O....O.......O...O...
O....O...OO......O...
O........OO.....O.O..
O..OO........O..O....
Debugging
If you encounter “STACK FRAME LINK OVERFLOW”, then try this:
export STACK_FRAME_LINK_OVERRIDE=ffff-ad921d60486366258809553a3db49a4a
Requirements
- Error messages:
- go to standard error
- include the program name as given by
argv[0]
.
- Produce an error message and stop the program if:
- a given filename can’t be opened (mention the filename)
- the input is not at least 2×2
- the input contains a bad character
- the input has inconsistent line lengths.
- The output must end with a newline.
- Newlines do not separate lines—newlines terminate lines.
- Creativity is a wonderful thing, but your output format is not
the place for it. Your non-error output should look exactly
like the output shown above. You have more leeway in error cases.
- UPPERCASE/lowercase matters.
- Spaces matter.
- Blank lines matter.
- Extra output matters.
- You may not use any external programs via system(),
fork(), popen(), execl(), execvp(), etc.
- You may not use C-style I/O facilities,
such as printf(), scanf(), fopen(), and getchar().
- You may not use dynamic memory via new, delete,
malloc(), calloc(), realloc(), free(), strdup(), etc.
- It’s ok to implicitly use dynamic memory via containers
such as string or vector.
- You may not use the istream::eof() method.
- No global variables.
- Except for an optional single global string called
program_name
containing argv[0]
.
- For readability, don’t use ASCII int constants (
65
)
instead of char constants ('A'
) for printable characters.
- We will compile your program like this:
cmake . && make
- If that generates warnings, you will lose a point.
- If that generates errors, you will lose all points.
- There is no automated testing/pre-grading/re-grading.
- Test your code yourself. It’s your job.
- Even if you only change it a little bit.
- Even if all you do is add a comment.
If you have any questions about the requirements, ask.
In the real world, your programming tasks will almost always be
vague and incompletely specified. Same here.
                
Tar file
- For each assignment this semester, you will create a tar file,
and turn it in.
- The tar file for this assignment must be called:
hw2.tar
- It must contain:
- source files (
*.cc
)
- header files (
*.h
) (if any)
CMakeLists.txt
- This command must produce the program
hw2
(note the dot):
cmake . && make
- At least
-Wall
must be used every time g++ runs.
How to submit your work:
In Canvas, check in the
file
hw2.tar
to the assignment
“HW2”.
                
How to receive negative points:
Turn in someone else’s work.