CSCI 1120 (Low-Level Computing), Spring 2018:
Homework 8

Credit:
20 points.

Reading

Be sure you have read, or at least skimmed, the assigned readings for classes through 3/07.

Honor Code Statement

Please include with each part of the assignment the Honor Code pledge or just the word ``pledged'', plus one or more of the following about collaboration and help (as many as apply).1Text in italics is explanatory or something for you to fill in. For written assignments, it should go right after your name and the assignment number; for programming assignments, it should go in comments at the start of your program(s).

Programming Problems

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 bmassing@cs.trinity.edu 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.

  1. (20 points) Your mission for this assignment is to first complete and then modify a starter program that plays mathematician John Conway's ``Game of Life'', described below. (You can also find more information on the Web. The Wikipedia article seems good.)

    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 visualize how this works ... I found a few Web sites that let you ``play'' online, but none I found immediately appealing. I have a version that uses text-based graphics that you should be able to use on our classroom/lab machines. Download file game, tell Linux it's an executable file with the command chmod u+x game, and run it with the command ./game. (If you're curious, the program is written in C++ using a library called ncurses to do text-based graphics.)

    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: game-of-life-starter.c. The program takes two command-line arguments, the name of a file containing an initial configuration and the number of steps to ``play''; it prints the initial configuration and then updated configurations for the specified number of steps. Sample output for input files game-of-life-in1.txt and game-of-life-in2.txt:

    [bmassing@dias04]$ ./a.out 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]$ ./a.out 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 . 
    . . . . . . . . 
    
    For this assignment you will turn in two programs:



Footnotes

... apply).1
Credit where credit is due: I based the wording of this list on a posting to a SIGCSE mailing list. SIGCSE is the ACM's Special Interest Group on CS Education.
...long)2
The long data type is a ``long integer''. In C int only has to be big enough for 16-bit values; long has to be big enough for 32-bit values. If you're curious about support for 64-bit values, long long (C99 only) does that.


Berna Massingill
2018-04-17