CS253: Software Development with C++

Fall 2020

HW 4

CS253 HW4: Options!

Description

For this assignment, you will improve upon your previous work in HW2, adding command-line options. This is a complete program, not a library.                 

Arguments

The first command-line arguments should be options:                 

-g golly-rule
Instead of the rule used in HW2, apply this rule, from the Golly program. It has this form: -g Bbval/Ssval.
Both bval and sval are composed of digits 08, in strictly ascending order. The default is -gB3/S23, the rule used in HW2.
bval says when a new cell is born, and sval says when an existing cell survives. E.g., -g B137/S257 means that iff an empty cell has exactly one, three, or seven neighbors, a cell is born there. Also, iff a live cell has exactly two, five, or seven neighbors, then it survives and stays alive.
Valid examples: -gB/S -gB78/S4 -g B3/S13 -gB012345678/S012345678
Invalid examples: -g S12/B34 -g B23 -gb23/s23 -g B12S78 -g B21/S34 -g B22/S34
-l live-char
Use this character to indicate that a cell is alive. This applies when reading & writing. The default is O, same as HW2. If you use a character special to bash (space, asterisk, ampersand, etc.), then quote it: -l'*'
-d dead-char
Use this character to indicate that a cell is dead. This applies when reading & writing. The default is ., same as HW2. If you use a character special to bash (space, asterisk, ampersand, etc.), then quote it: -d " "
-i
Produce an infinite number of generations on output, each separated by a blank line.

There must be, at most, one optional argument after these options. If that argument is present, read from that file, otherwise read from standard input.                 

Sample Runs

Here are sample runs, where % is my prompt.                 

% cmake .
… cmake output appears here …
% make
… make output appears here …
% cat block3
''''
'**'
'*''
''''
% ./hw4 <block3
./hw4: bad input char “'”
% ./hw4 -d"'" -l '*' <block3
''''
'**'
'**'
''''
% cat blinker
....
.O..
.O..
.O..
....
% ./hw4 blinker
....
....
OOO.
....
....
% ./hw4 -i blinker | head -17
....
....
OOO.
....
....

....
.O..
.O..
.O..
....

....
....
OOO.
....
....
% ./hw4 -g B3/S23 blinker
....
....
OOO.
....
....
% ./hw4 -gB123/S2456 blinker
OOO.
O.O.
OOO.
O.O.
OOO.
% ./hw4 -gB123/S2456 -i blinker | head -17
OOO.
O.O.
OOO.
O.O.
OOO.

O.O.
O.O.
.O..
O.O.
O.O.

O.O.
O.O.
OOO.
O.O.
O.O.

Animation

For cheap animation, try this:

    ./hw4 -i ~cs253/pub/Life/r     | sed 's/^$/sleep 0.2;clear/e'

or:

    ./hw4 -i ~cs253/pub/Life/ggg   | sed 's/^$/sleep 0.2;clear/e'

or:

    ./hw4 -i ~cs253/pub/Life/lines | sed 's/^$/sleep 0.2;clear/e'

Change the 0.2 to a larger/smaller value to slow it down or speed it up.                 

Debugging

If you encounter “STACK FRAME LINK OVERFLOW”, then try this:

    export STACK_FRAME_LINK_OVERRIDE=ffff-ad921d60486366258809553a3db49a4a

Hints

Requirements

All requirements from HW2 still apply, with these additions:

Tar file

    cmake . && make

How to submit your work:

In Canvas, check in the file hw4.tar to the assignment “HW4”.                 

How to receive negative points:

Turn in someone else’s work.