The original Game of Life used the type of cells, known as Conway cells, that you used in Project 3. However, there can be other types of cells. That is, we can imagine cells that, at each evolutionary point, determine their liveness based on different numbers of live neighbors. Furthermore, the notion of a neighborhood may change, counting the liveness of some set of cells other than the standard, adjacent eight cells. Finally, we can conceive of cells that may change themselves into another type of cell under certain circumstances.
For this project, you will modify your Game of Life program to implement a number of different cell types, where each of the variations mentioned above occurs in at least one new cell type or other. The user will provide, at the command line, a selection of cell type, and the Game will then progress by using that type.
The specific cell types: We define a few nmew types of cells in addition to the already familiar Conway cell:
Amoeba cell: This type of cell uses the standard neighborhood. If it is currently alive, then it will remain alive if it has 1, 3, 5, or 8 live neighbors. If it is currently dead, then it will become alive if it has 3, 5, or 7 live neighbors. Otherwise, it will be dead in the next generation.
HighLife cell: This cell also uses a standard neighborhood. Like the Conway cell, 2 or 3 live neighbors will keep a live HighLife cell alive. Unlike the Conway cell, 3 or 6 live neighbors will cause a dead HighLife cell to become alive. Otherwise, of course, the cell will be dead.
Friendly cell: This cell uses a more expansive neighborhood. For a Friendly cell, its neighbors are those that it could reach in any two steps from itself in any direction. That is, the 5 x 5 subgrid centered on this cell is its neighborhood. Here, if 3, 9, or 16 neighbors are alive, then a live Friendly cell remains alive; if 2, 8, 12, or 19 neighbors are alive, then a dead Friendly cell becomes alive. Otherwise, it becomes a dead Friendly cell.
Morphing cell: Using a standard neighborhood, a dead Morphing cell with 2 live neighbors becomes a live Conway cell. A dead Morphing cell with 3 live neighbors becomes a live Amoeba cell. A live Morphing cell with 4 or 5 live neighbors remains alive. Otherwise, the cell becomes dead.
Start by coping the critical classes and test files (grid initialization files and results) into your directory:
cd ~
cp -r ~sfkaplan/public/cs12/project-4 .
In order to support multiple cell types, my code assumes a few modest changes. Specifically, within your Game class, the constructor looks a little different, now requiring a cellType parameter:
The constructor. The initialStateFilename is the name of a file that contains a initialization state file, which is one that contains the size of the grid and coordinates of initially live cells. The cellType is a request for a specific kind of cell with which the universe should be populated. It is up to your code to transform this String representation into the right kind of cell object. The interfaceType specifies the kind of user interface to create---in this case, either Text or Graphic, where only the former currently works.
It is the responsibility of this method to set up the Game object. Specifically, it must, based on the initial state file, create the grid and its cells, and then set the appropriate ones to be alive. It must also create a UserInterface object (as described above) and keep a pointer to it.
All other changes are internal to your code. The user interface code continues to assume that there is a Cell class, and that objects of that type have a getStateAsText method that returns a char that represents the liveness of that cell type.
So that we can determine the types of each cell, the characters returned by the getStateAsText method must differ from once cell type to another. Here's what you should use:
Cell type | Alive | Alive name | Dead | Dead name |
---|---|---|---|---|
Amoeba | * | asterisk | _ | underscore |
Conway | + | plus | - | dash |
Friendly | % | percent | ` | backquote |
HighLife | x | lower-case X | . | period |
Morphing | # | pound | , | comma |
From within your project-4 subdirectory, use the following command to submit you work (all of your Java code files) when you are done:
cs12-submit project-4 *.java