CS010 Introduction to Computer Science I
Term Project
Deliverable Three


Cellular Automata:
Using Object-Oriented Programming
(last updated 4/15/2007)


Update:  You should only create cell-objects at the beginning initialization.  After, each cell-object should persist and compute its new state, switch to it, and display itself according to its current state generation after generation.



For the third deliverable, you will modify your version of Conway's Game of Life such that it models cells as cell-objects.  You should use the principles covered in class and in Sections 39-41 to create a cell class that encapsulates appropriate state variables and services relevant to a cell.  Thus, a cell will be a service manager function that consumes messages and provides services.

Your cell must provide the following services: 
'show-self: displays this cell according to its current state
'current: returns this cell's current state
'determine-new: causes this cell to compute it's new state
'switch-to-new: causes this cell to change to its computed new state

The key problem you may immediately notice is, how will a cell know its neighbors.  You should use a new-grid definition: (vectorof (vectorof cell-object)).  Then you should provide a means for a cell object to find its neighbors, and then it can ask each of its neighbors for their respective current states.  A good approach to this is to provide a cell's row and column as well as the grid itself as arguments to the constructor when you create a cell-object.  In this way, it should not be difficult for a cell-object to find its neighbors, since it has its own location and access to the grid as a whole.  However, as you create the cell objects, you may need to store them in their appropriate grid locations using vector-set!.

So, define a cell-object "interface" with a constructor called make-cell-object.  This constructor should consume four arguments, a current state (either 1 or 0), a row index, a column index, and a grid in which the cell object resides.

Finally, you'll need to make minor alterations to the rest of your program that displays the grid and updates it.  The basic approach you'll probably want to use is have all of the cell-objects "determine-new" by querying their respective neighbors, and then have all the cell-objects "switch-to-new".  Then have all the cell-objects "show-self" according to their (new) current states.  Finally, you'll want to repeat this sequence as many times as needed according to the argument to cgol.

Your main function, oo-cgol, should accept (as before) three numbers: the height and width of the new-grid, and a number for the generations to simulate.  As before, it should create a canvas of the appropriate size according to the scale you use, create a new-grid of the proper size, and do whatever initialization is necessary for the new-grid.  And of course, oo-cgol should simulate the generations of the grid according to the rules for Conway's Game of Life.

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