CS010 Introduction to Computer Science I
Term Project
Deliverable Two

Cellular Automata:
Conway's Game of Life
(last updated 4/1/2007)


For the second project deliverable, you will implement a version of Conway's Game of Life (CGoL).  Here is one of many many links you might find on the web.  The key notion of CGoL is that each cell lives or dies according to these simple rules:
The main difference from your Project 1 is that we now have a two-dimensional universe of cells and instead of displaying a trajectory of the cells over time, we will animate them in real time.  As before, you will need to find the neighbors of a given cell to determine its life status.  However, now each cell has eight (8) neighbors.

You will want to think about how to decompose the problem into simple functional chunks.  You should define a type, grid, using Scheme vectors.  That is, the grid should be a (vectorof (vectorof cells)), where a cell is defined by you and represents a state.  You will want a function that displays a given grid.  It may be helpful to think of the grid as a vector of rows, each of which is a vector of cells.

Ultimately, you must write a function, cgol, that consumes three numbers -- the height and width of a grid, and the number of generations to simulate.  The function simulates the game of life using a randomly generated grid of the appropriate size.  Make sure that your code works according to the dimensions and initial values of the given grid.  That is, your code should work equally well as (cgol 3 5 100) as with (cgol 140 60 10).  For each generation, the life-status of each cell should be checked and updated, and then the grid should be redrawn.  The grid should wrap from edge to edge and top to bottom.  That is, the cell in the upper left corner has neighbors that include the lower right corner, the two-leftmost cells in the last row, and the right-mose cells in the top two rows.  Make sure that the new life-status of one cell does not confuse the update of an adjacent cell.  This should not be a problem if you create a new grid on each cycle -- but you might want to avoid that.  Use the draw teachpack to display your grid, drawing circles or squares to represent living cells and leaving dead cells blank.  Thus, for some radius named RADIUS and a given grid named G, your canvas would be RADIUS * (vector-length G) pixels tall, and RADIUS * (vector-length (vector-ref G 0)) pixels wide.

To grade this deliverable, I will review your code (including contracts, purpose statements, indentation, etc.), and then call your cgol function with parameters of my choosing.   Therefore, it is important that you follow the data definitions carefully.