CSCE 2004 - Homework 6
Due Date - 10/30/2012 at 11:59 PM

  1. Problem Statement
  2. The objective of this programming assignment is to become familiar with two-dimensional arrays. You will be completing a program to simulate Conway's Game of Life. You will be starting with a sample program hw6.cpp, that has functions for initializing the game board and drawing the game board on the screen. You task will be to complete several functions to place specific patterns on the game board and implement the rules of this game. These requirements are described in more detail below.


    The update function should implement the rules of Game of Life. Here are the rules. The Game of Life is a zero player game played on a two-dimensional grid of square cells, each of which is in one of two possible states, alive or dead. Every cell interacts with its eight neighbors, which are the cells that are horizontally, vertically, or diagonally adjacent. At each step in time, the following transitions occur:

    1. Any live cell with fewer than two live neighbors dies, as if caused by under-population.
    2. Any live cell with two or three live neighbors lives on to the next generation.
    3. Any live cell with more than three live neighbors dies, as if by overcrowding.
    4. Any dead cell with exactly three live neighbors becomes a live cell, as if by reproduction.

    The board (grid) is initialized to an initial pattern. The first generation is created by applying the above rules to every cell of the initial board. The rules continue to be applied repeatedly to create further generations for each step. The game ends after a fixed number of iterations.


    The hw6.cpp program contains a function to randomly initialize the board. To make the game more interesting, we can also add predefined patterns on the board before starting the simulation. This can be done using functions to store patterns of 0's and 1's into the two-dimensional array representing the board. The three patterns that you must create are shown below.

    1. The 6x5 Beehive Pattern:
    2. The 5x5 Blinker Pattern:
    3. The 5x5 Glider Pattern:
      glider glider


    The program hw6.cpp contains the following functions:

    1. init_board - initializes the board with some randomly placed live cells (DO NOT EDIT)
    2. redraw_board - redraws the board to the console (DO NOT EDIT)
    3. main - needs to update the board and redraw the board (YOU SHOULD EDIT THIS ONE)

    You must add the following four functions to hw6.cpp:

    1. update_board - updates the board according to the Game of Life
    2. add_beehive - places a beehive on the board with upper left corner at a given row, column position
    3. add_blinker - places a blinker on the board with upper left corner at a given row, column position
    4. add_glider - places a glider on the board with upper left corner at a given row, column position

    Once you have implemented four the functions above, modify the main program of hw6.cpp to include ONE call to each of the add_beehive, add_blinker, and add_glider functions after the call to init_board. Then call the update_board function inside the simulation loop to complete the main program. To run a sample of the final game, ssh to turing and run the following command: /home/jhendric/public_html/2004/hw6

  3. Design
  4. When finishing the main function, create a loop to update and redraw the board for each step of the game. You can use the init_board to generate a random board for testing your code. Since we seeded the random number generator in the main program, you should get a different board every time.

    When creating the update_board function, it may be useful to create one or more helper functions to use in that function. For example, you may want to create an is_on_board function that checks if a given position is on the board. If the board is 20 by 20, is_on_board(21, 4) should return false and is_on_board(5, 4) should return true. Create whatever helper function you think will make your code easier to follow and understand. Creating these helper functions is optional, but can make your code much easier to write, debug, and understand.

  5. Implementation
  6. Work incrementally, implement one function at a time. For example, you can finish the main function except for updating the board. If this runs as expected, create an update_board function. This can be called in main. You can test it using a random board generated by init_board. Once you have the update_board function working, you can create functions for adding gliders, blinkers and beehives. Create and test each of these one function at a time. To make sure that you have these patterns working, compile and run the game with STEPS = 1 (STEPS is a global constant). This will just show the initial state of the board and you should see your pattern in the (row,column) position you specified. Setting STEPS = 1 is also a good way to generate test output for turning in.

  7. Testing
  8. Test your program to check that it operates correctly for all of the requirements listed above. Also check for the error handling capabilities of the code. There are no inputs for this project so just save your test output for submission on the program due date.

  9. Documentation
  10. When you have completed your C++ program, write a short report (less than one page long) describing what the objectives were, what you did, and the status of the program. Does it work properly for all test cases? Are there any known problems? Save this report in a separate text file to be submitted electronically.

  11. Project Submission
  12. In this class, we will be using electronic project submission to make sure that all students hand their programming projects and labs on time, and to perform automatic analysis of all programs that are submitted. When you have completed the tasks above go to the class web site to "upload" your documentation and testing document (pdf, doc, or txt file), and your C++ program (cpp or txt file).

    The dates on your electronic submission will be used to verify that you met the due date above. All late projects will receive reduced credit:

    You will receive partial credit for all programs that compile even if they do not meet all program requirements, so handing projects in on time is highly recommended.