Introduction to Computer Science II by James Tam | Return to the course web page |
This page is best viewed with Internet Explorer version 5+ and a computer with a sound card and a darn good set of speakers.
Births: Occur in empty squares if there are 2 or 3 neighboring Critters.
Case 1: 2 Neighbors
* | ||
* |
Case 2: 3 Neighbors
* | ||
* | ||
* |
Case 1: Critter dies of loneliness if it has no neighbors
* | * | * |
* | * | * |
If you are planning to implement the code for the "TerminatorCritter" (see Extra feature No. 1 below) then you will have to add another attribute to the Prosperous Biosphere:
Some behaviors associated with instances of the Prosperous Biosphere class include:
The starting positions for the Critters is different for this assignment and have been updated in the new biosphere class in the Assignment 4 directory. You are free to copy or modify this code but make sure that reference where you got the code from. If you choose to write your own code to initialize the starting positions make sure that you get the starting positions exactly the same! Although you are free to use the biospheres for Assignment 3 for testing purposes your program must be able to handle the cases shown below in order to receive a grade of C+ or higher.
First set of required starting positions:
Second set of required starting positions:
* | ||
* | T | |
* |
With the addition of the Terminator critter there will now be two scan phases: 1) The normal births and deaths scan phase 2) This phase immediately is followed by a "specials" phase. The extra array in the prosperous biosphere class called "specials" is needed to store the changes that occur because of the Terminator critter. During the births and deaths scan phase the terminator lies dormant and does not do anything so the births and deaths are governed by the new rules of the Prosperous Biosphere:
During the "specials" phase the Terminator will first try to: a) Terminate all neighboring critters b) If the Terminator has no neighbors then it randomly move to anther square in the biosphere.
- Terminating other critters (+1 letter step) : During the specials phase any critters are in the squares that are adjacent to the Terminator will be "terminated" (star becomes a space).
- Random movement (+1 letter step): If during the specials phase there are no critters in the squares adjacent to the terminator then the terminator critter will randomly move to one of the unoccupied squares. New randomly generated row and column coordinates will be generated if there is already a critter at the first set of coordinates. Also your program must ensure that the Terminator actually does move (i.e., the new row and column coordinates aren't the same as the original values - if this is the case then another set of values must be generated).
Some behaviors of the Terminator class:
- Terminate other critters. This method will check if the adjacent squares contain a Critter. To actually change the stars to spaces in the Prosperous biosphere, there will have to be a call in this method to the kill critter method of the Prosperous Biosphere class. (Hint: One necessary step to do this is to make the Prosperous Biosphere an attribute of the Terminator class).
- Move to an empty square with the row and column coordinates being randomly determined. Since the actual movement of the Terminator affects the data of the Prosperous biosphere there will have to be a call to the "move terminator critter" method of that class.
Finally you must set the starting position of the Terminator critter to row 3 and column 2 (see the documentation of the Prosperous biosphere class in the Assignment 4 directory for some guidance as to when you should do this in your program).
The user can invoke this mode when the program asks if the user wishes to continue on for another generation. Note that edit mode is not a listed option, it is implemented as a hidden "cheat" function. The purpose is to provide an extra debugging tool for the programmer. After the edit mode is invoked the program will display a message indicating it is now in edit mode and it will display the current state of the Prosperous biosphere (see the diagram below):
As the name implies edit mode allows the user to edit any square of the biosphere and either: 1) Empty the square of the existing critter 2) Or to add a critter to an empty square. All three arrays will be effected by edit. The Terminator critter cannot be added via edit mode because only one Terminator can exist at a time but the Terminator can be deleted. After editing a square the user can either edit another square or exit edit mode and continue the simulation.
- Exception handling (+2 letter steps):
Your program implements a new exception "CritterAlreadyInSquareException" that is thrown whenever the program tries to birth a critter in a square that already contains a critter. The method(s) that actually adds a critter to the biosphere (changes a space to a star) must throw this new exception. The only exception is the initialization methods that determine the starting positions of the critters. So this exception should be thrown whether the critter is added via the birth-and-death rules of the Prosperous biosphere or (more likely) when the user tries to manually add a Critter with during the edit mode. Any methods that invoke the methods that throw this exception must be able to handle the exception through a try-catch block. This new exception extends the existing java class "Exception".
The student has invested considerable work in the assignment and the code compiles but it doesn't fulfill any of the above requirements.
The student has invested considerable work in the assignment but it doesn't compile.
3. Breaking down the assignment:
Classes that you need from Assignment 3:As was the case with Assignment 3, you have to employ some sort of debugging mechanism. It is up to you if you choose to implement your debugging mechanism through the Debug class.
4. Handling the edge cases: All of the grade levels shown above assume that you handle the edge cases (top and bottom rows, far left and right columns as well as the four corners) by using a 10x10 array and checking these conditions differently from the inner 8x8 squares. If your program does handle these edge cases in this fashion but you otherwise implement the required functions, your submission will lose two letter steps.