Introduction to multidisciplinary Computer Science II by James Tam | Return to the course web page |
Figure 1: Race simulation
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 race simulation (see Figure 1). There will be four competitors in the race. Three will be controlled by the computer program 'X', one is controlled by the user 'P'. Each runner will start at row 1 and try to make their way to row 50. When one or more racers reach the last row the simulation will end. If the runner controlled by the user is the only one to have reached row 50 then that race is won by the user. If any of the computer controlled runners reaches the final row before the user controlled runner then the race has been lost by the user. If the user controlled runner and at least one of the computer controlled runners have reached this row then the race is tied. Finally if the user quits the simulation prematurely then the race is neither won nor lost. Because of the length of the track only a part of it will be displayed at a time.
Figure 2: End of the race, at least one runner reached the last row.
Each runner can run at one of three speeds: jog, run, sprint. The latter two speeds results in move rows being traveled but they come at a risk. There is the possibility when traveling at higher speeds that the runner becomes winded and if so the runner must jog the next turn. When sprinting there is the additional chance that the runner will burn out and be forced to jog for the remainder of the race. The user controls the running speed of one runner. The other three have a even chance at travelling at one of the three possible speeds. There is a chance that each runner will be unable to maintain a running speed faster than a jog (the runner's discipline breaks). That means even if the user selects a faster running speed or the computer randomly determines that one of the other runners should move faster, the runner becomes distracted and slows to a jog. This slowing down is different from becoming winded. Becoming winded or burnt out is (for this simulation) determined by physical characteristics, the runner's body has given out. Breaking discipline means that the runner's mind has become distracted and even though the body is able to run at a faster speed, the runner has become distracted and does not maintain the faster pace (slows to a jog).
The running styles of the runners are determined by three attributes: strength, endurance and discipline. Strength may increase the sprint distance. Higher endurances reduces the chance that a runner will become winded or burn out. Having a higher discipline reduces the chance that the runner will become distracted. At the start of the simulation the user can determine their runner's strength's and weaknesses (increasing one attribute will take away from the others).
Finally this simulation will randomly determine the current weather for that day's race. The weather will consist of two properties: the wind speed and the temperature. Higher wind speeds can reduce the amount of distance traveled by runners (or even push slower runners back!) Higher temperatures increase the chance of getting winded or burnt out. One set the weather will remain the same for the duration of the simulation.
CommandProcessor: it's similar to the Menu class from the previous assignment. This class is responsible for all the user-interface operations in this program e.g., displaying menus, getting user input, determining if the user's selection was valid/determining which option was selected. Once the user's selection has been determined then it will pass messages to (call methods of) other objects (as was the case with the Menu class).
Minimum required attributes: a reference to an instance of class Track (the race track) as well as something to store the user's selection.
Minimum required methods: will include everything associated with the user interface (e.g., Displaying menus, getting user selections, determining what selection was made etc. It should also be responsible for starting and ending the simulation).
Mode: identical to the Mode class that you used for the previous assignment. It's sole purpose is to determine if the program is operating in the debugging mode. By default the program will not be operating in debugging mode.
public class Mode
{
public static
boolean debug = false;
}
RaceSim: The 'Driver' class for this program. The starting execution point that should contain a reference to the user interface class:
public static void main (String [] args)
{Runner: the entities that travel along the race course. As mentioned one will be controlled by the user, three will be controlled by the computer program.
Minimum required attributes: strength, endurance, discipline, current running mode (jog, run, sprint), and if the runner is 'winded' or 'burnt out' (see Feature #8). Also each runner needs an 'appearance' field, a single character that determines how the runner is represented (the runner controlled by the user is a 'P' while the three controlled by the program are 'X'). Finally each runner should track it's current location (row/column) on the race track because the destination is going to be based on the current location. These are just a few of the attributes needed for class Runner you will almost certainly have more.
Minimum required methods: everything that modifies/retrieves the attributes (there will be many). It should also include methods that are somehow related to the attributes even though they don't directly access or modify the attribute for other objects. For example determining if the runner gets distracted (see Feature #5c) should be implemented as one or more methods of this class because the probability of distraction is determined by the runner's discipline.
Track: similar to the Manager class in the previous assignment it tracks the core data used by the program. The previous program's Manager class tracked information about the list, this program's Track class is responsible for storing and managing all the information used in the simulated world (the race track).
Minimum required attributes: the simulated world (a 2D array of 'Runner' objects): private Runner [][] raceCourse; references to the one runner controlled by the user and three runners controlled by the program. Each element in the race course array will either be null (signifying an empty location on the track) or refer to a runner object.
Minimum required methods: all behaviors associated with managing the data attributes (e.g., displaying the world, changing data in the world - moving runners between locations, checking if the race is finished (when one or more runners reaches the end).
Weather: This class is similar to class Mode in that there will only be one instance of this class for the whole program. Consequently it should have an entirely static implementation (alternatively you can employ the Singleton design pattern, if you don't know what I mean then just stick to making all attributes and methods static). This simulation tracks two aspects of the weather: the wind strength and the current temperature. There are three possible wind strengths: no wind, mild wind and heavy wind. There's four possible states for the temperature are: average, hot, very hot, heat wave. There's an equal probability for a particular wind strength to occur and an equal probability for a particular temperature. The weather conditions will be determined at the start of the simulation and stay the same for the remainder of the race.
Minimum required attributes: wind and temperature.
Minimum required methods: one or more methods to randomly determine the weather conditions.
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) as many features as possible.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
They can be found in the UNIX directory: /home/219/assignments/assignment5. Within this directory are three sub-directories: 'java_code', 'sample_runs'. The first directory contains the dot-java files that are needed by your program. The second 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.