Introduction to Computer Science II by James Tam | Return to the course web page |
[JT's hint: The final exam will include a question or questions relating to material in the 'hierarchy' section. The question(s) be drawn from the three new concepts introduced in this assignment (and likely other topics such as implementing interfaces). Consequently I strongly recommend that if you don't have time to attempt all the major features of the assignment that you at least attempt features that require the application of all of the above topics.]
Computer simulations are re-creation of a real-world scenario. Simulations are important for many reasons including (but not limited to) safety and cost. Also simulations may assist in decision making by allowing alternatives to be tested before a course of action is chosen. For this assignment you are to implement a simple wildlife simulation. There will be three types of life forms that live in this simulated world: prey, flying predators and ground-based predators. Prey procreate. They may be injured by predators but they can slowly heal their wounds over time. Prey that have been critically injured by predators will die and vanish from the simulation. Predators will attack prey that are nearby. All three life forms can move randomly about the simulation although flying predators have the greatest range. The program will maintain statistics on the number of prey that are born into the simulation, and the kills and damage inflicted by the different types of predators. The simulated world will be represented in the form of a 2D array of "SimObjects" (the parent class of all the entities in the simulation).
Pre-created classes that you must use (see the 'resources' section) | Classes that you must implement |
SimObject | Driver |
Coordinate | Simulator |
Animal | Biosphere |
Predator | Prey |
Mode | Flyer |
FileBiosphere (class file) | GroundBased |
SimObject: represents all the objects in the simulated world (living or non-living). Although this version of the simulation only includes three types of living objects later versions of the program could include physical non-living objects (e.g., trees, grass, rivers etc.). These other types of objects would be instances of class SimObject. Each instance of the class will have an appearance attribute. This class will have a class constant that determines the default appearance of the object (a space). Each child class should have its own class constant to indicate the default appearance of the instances of that class e.g., class GroundBased { public static final DEFAULT_APPEARANCE = 'G'; ... }
Coordinate: each location (array element) in the world can be described by a row/column pair. In the previous assignment you could have used two integers. For this assignment some methods will generate and return a location (e.g., class Prey's move method) it's easier to return the row and column value as a single coordinate rather than as two separate integer values. (Recall methods only return a single value).
Animal: a child class of SimObject, it represents living and moving occupants of the world. Consequently instances of this class will have three attributes: the current row/column coordinate of the animal and a boolean flag that indicates whether the object has moved yet during the turn. Additionally animals have methods that allow them to move (randomly generates a value that determines which of the adjacent squares that it will attempt to move to - the Biosphere class will determine whether that location is a valid one: is it in bounds and is it empty).
Predator: a child class of Animal that represents all the animals that consume prey. It has a class constant that indicates the amount of damage that its attacks do and a method that generates the attack damage that it inflicts on prey. (The prey would then use this value to reduce its health). Instances of class Predator only do a fixed amount of damage with each attack but it's child classes: Flyer and GroundBased inflict variable damage.
Mode: It will be defined as follows:
public class Mode
{
public static boolean debug = false;
}
Similar to the previous assignment the purpose of this class is used to control the appearance (or absence) of debugging messages.
FileBiosphere: Similar to the file class from the previous assignment this static class will allow your program to read the starting positions from an input file called "input.txt". In this case it will read the information from the file and instantiate the appropriate SimObject in the array attribute of Biosphere. To use the code in this class file however you need to make certain that you follow all design requirements (e.g., classes must implement a constructor with a precisely defined method signature).
Driver: the starting execution point and it should contain a reference to an instance of class Simulator so the simulation can be started.
public class DriverSimulator: this class acts as the 'manager' for the simulation. It controls when the simulation starts and when it ends as well as determining the order of each sub step in a turn. (Similar to the Menu class from A3 which called methods of class Manager, class Simulator will call methods of class Biosphere in order to execute the sub steps such as displaying the world...the simulator determines what sub step occurs when, and then it calls the appropriate method of class Biosphere). Since the user interaction is extremely minimal (for the debug toggle) it can also process user inputs as well.
Minimum required attributes: a reference to an instance of class Biosphere.
Minimum required behaviors: all the functionality with running the simulation itself (start, end, running each sub step) and the user interface.
Biosphere: Similar to class Forest in the previous assignment. The
Biosphere tracks information associated with this particular simulated world,
a savannah.
Minimum required attributes: an array of references to SimObjects (more specifically instances of the child classes: Prey, Flying, GroundBased). Other attributes include the statistics to be tracked in this particular simulations: prey births, damage and kills inflicted by the flying and the ground based predators. Array elements will consist of references to SimObjects (prey, flyer, ground based) or it will be null.
Minimum required behaviors: methods that change or retrieve information about the attributes e.g., displaying the world, checking array bounds, births, deaths, movement etc.
Prey: A child class of Animal. It moves, procreates, heals and (perhaps) dies.
Minimum required attributes: information about it's current health level (12 is full health, 0 is dead). Also a flag is needed that indicates whether the prey is new born. An object stays newborn during the turn in which it was born (see feature #10) after which it may participate in the birth of new prey. Default appearance of prey is 'r'.
Minimum required behaviors: the ability to heal wounds inflicted by predators. Note: dead prey are removed from the simulation and don't heal. It also must have a constructor that takes the following parameters: a character and two integers. The first parameter will be used to set the appearance attribute, the second parameter will set the row attribute and the third parameter will set the column attribute: Prey (char anAppearance, int aRow, int aColumn)
Flyer: A child class of Predator. Flying predators inflict a different amount of damage from the parent predator and have a wider range of movement.
Minimum required attributes: none.
Minimum required behaviors: three overridden methods: attack(), positionToCoordinate () and move (). Flying predators inflict 2 - 8 points of damage per attack. They are not limited to moving to adjacent squares (range 1) but have maximum range of 2 squares e.g., if a flyer were on row 3 then the maximum distance it could move 'up' would be row 1 and maximum distance that it could move down be to row 5. Similar to class Prey, this class also must have a constructor that takes as input a character and two integers.
GroundBased: A child class of Predator. Ground based predators are larger and more powerful than the typical predator. Default appearance is 'G'.
Minimum required attributes: none.
Minimum required behaviors: one overridden method: attack(). To reflect their increased size and strength ground based predators inflict 3 - 10 points of damage per attack. You need to override the attack method so it generates and returns a number within this range. Similar to class Prey this class must also have a constructor that takes as input a character and two integers.
You will need to create a UML class diagram that specifies the full information about the classes in your program (method signature and return value, method attributes) as well as the relationships between classes. Your diagram should not only include the classes that you implement yourself but also the required classes that I created.
Note: the marking key for this assignment will be set up so you can get a top grade without necessarily implementing each and every feature (there will be a margin of error built in). However in order to prepare yourself for the exam make sure you attempt (better yet complete) a set of features that apply each of the new concepts introduced in this assignment.
|
||||||||||||||||||||
|
||||||||||||||||||||
|
||||||||||||||||||||
|
||||||||||||||||||||
|
||||||||||||||||||||
|
||||||||||||||||||||
|
||||||||||||||||||||
|
||||||||||||||||||||
|
||||||||||||||||||||
|
||||||||||||||||||||
Before | After | |||||||||||||||||||
|
|
|||||||||||||||||||
|
||||||||||||||||||||
|
||||||||||||||||||||
|
||||||||||||||||||||
|
||||||||||||||||||||
|
2 To make it simple you can use the following approach for determining which animal to move. Start at the left hand corner of the simulation. If there is an animal there move it. Now based on the current state (animal moved) work along that row from left to right moving the animals. The new location of animals that have moved should be treated as being occupied to animals that move later (but it's source will be treated as empty). Then move down to the next row and again move from left to right. Repeat until the square at the bottom right has been reached. Although all movements for prey or predators are all finished before the world is displayed, the program needs some rules for determining the order of movement (i.e., you can't have two animals moving into the same square during one turn). Consequently that means that movement is checked from top to bottom, left to right in order to resolve collision conflicts.
During each turn the following things will occur in the following order:
They can be found in the UNIX directory: /home/233/assignments/assignment5. Within this directory are three sub-directories: 'data', 'java_code', 'sample_runs'. The first directory contains different versions of input files that you can use for your assignment (Useful for testing different features, feel free to make your own. Just rename each file to "input.txt" when you want the "FileBiosphere" class to use it as input. Keep in mind each file must be 10x10 in size.) The program that you submit for marking must be able to handle the base file "input.txt"). The second directory contains the dot-java and the one dot-class file that is needed by your program. The third directory contains text files that show the output of my solution program under different situations. Since there is no byte code solution to run for this program you can look through the output of these files to clarify assignment requirements.