Introduction to Computer Science I Term Project
Conway's Game of Life (last updated 12/1/2005)
For the second project deliverable, you will implement a version of
Conway's Game of Life. 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:
A dead cell with exactly 3 live neighbours becomes alive (or is
A live cell with 2 or 3 live neighbours stays alive; otherwise it
dies (from "loneliness" or "overcrowding").
You will want to think about how to decompose the problem into simple
You should define a grid type
using Scheme vectors. That is, the
should be a (vectorof (vectorof cells)), where a cell is represents a
life state as either 0 (dead) or 1 (live). Naturally, you will
want a function that
displays a given grid.
Ultimately, you must write a function, cgol, that consumes a grid and a
number; it simulates the game of life using the given grid for the
given number of time steps, displaying the live cells after each
The cgol function should create a canvas of the appropriate size based
on the size of the given grid and your cell-size. Make sure that your
according to the dimensions and initial values of the given grid.
That is, your code should work equally well with a grid that is 3-by-5
as with one that is 40-by-110. On each time step, the life-status
each cell should be checked and updated, and then the grid should be
redrawn. As before, the grid should wrap from edge to edge, but
also from top to bottom.
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.
Use the draw teachpack to display your grid, drawing circles or squares
living cells and leaving dead cells blank. You should define a
global variable, CELL-SIZE, that determines the
width and height of a cell's graphical representation. Your
functions should take this variable into account as it draws and clears
cells as they live and die. For example with given grid G, your
canvas should be CELL-SIZE * (vector-length G) pixels tall, and
CELL-SIZE * (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. Therefore,
it is important that you follow the data definitions carefully. I
might use the following code: