IMGD 400X (B 09)
Homework Assignment #3
Tank States
Due by Web Turn-In: Midnight, Wednesday, November 4
(See general homework instructions for turn-in details.)
The purpose of this assignment is to gain experience formalizing a modestly complicated AI behavior as a finite state machine. Imagine that you are an AI developer in a game company and one of the designers has given you the textual tank behavior specification below. Your job is to formalize the behavior as a state machine clearly enough so that your documentation could be handed off to a low-level programmer to implement (who may be you!).
Here are the basic steps and work products you should go through:
- Create a table that describes each state, the game properties it references, and the actions that occur in that state.
- an example property might be the vector from the tank to the player
- an example action might be to run an explosion animation or to turn on steering toward a particular target
- assume that animations are run on a separate thread (asynchronously), i.e., if a game state starts an animation, it may need a condition to test when the animation has finished
- feel free to use a hierarchical state machine, if you like
- Create a table of conditions (boolean functions) that will be used to control transition between states.
- describe each condition in words or pseudo-code
- define short (but understandable) abbreviations for each condition
to use when labeling transitions in diagram (e.g., "low_health")
- Draw a "bubble and arrow" diagram for the finite state machine.
- the drawing tools in PowerPoint are probably sufficient for the job (use "connectors" to make it easier)
- or you may also wish to use a more sophisticated tool, like Visio.
Remember, this is a detailed design document, not an implementation. At this level of design, don't worry about variable names, which information is stored in state instances vs. game entities (singleton state implementation), etc.
Finally, don't be surprised if you discover during the formalization process that the textual behavior specification below is incomplete (that's typical and part of the goal of formalization). Make reasonable decisions on the incomplete cases and document them.
Tank Behavior Specification
Initialization
- The tank becomes active when the level is initialized.
- It will wander
about the "patrol zone" portion of the level. In this state, the
turret is always pointing the same direction as the direction of
travel.
Combat
- The tank will engage in combat with the player when
- (a) the player enters into the field of view of the turret, or
- (b) the player fires a weapon.
- When in combat, the tank's turret will track the player and fire at a fixed rate. The tank body will also turn towards the player, but the turret can turn faster.
- If the player is out of view behind a non-destructible object (like a rock), the tank will cease fire but continue to track the location where the player was last seen.
- If the player is behind a destructible object (like a Jeep), the tank will reorient its fire to destroy the obstacle, i.e., it will shoot at the object rather than the player.
- The tank's main gun cannot fire closer than 50 meters, so the tank will try to maintain at least this distance to its target.
- If the player comes within 50 meters of the tank, its machine gun (also mounted on the turret) will fire in bursts. The machine gun will not attempt to destroy obstacles.
- If the player gets closer than 10 meters, the tank will cease trying to move to main gun distance and will instead drive toward the player to crush him. All firing ceases while this is happening, but begins again if the player evades (i.e., if the player gets more than 10 meters away again).
- If the player hits the tank with a RPG or hand-thrown grenade, it will cease firing while an explosion animation is shown.
- If the tank's health is less than 25%, it will begin emitting smoke and the main gun will cease functioning, leaving only the machine gun.
Termination
- If the player's health is reduced to zero, the tank heads back towards the patrol zone.
- If the tank's health is reduced to zero, it explodes in a fireball.
What to Turn In
- State property and action table.
- Game conditions table.
- State transition diagram.
Grading
- 4 points - Correct and complete implementation of specification
- 1 point deduction for each incorrect behavior
- 1 point deduction for each missing behavior
- 1 point - Software engineering quality (clear organization, layout, naming conventions).
Please post any questions to the myWPI forum for the course.
Acknowledgement: I would like to thank Robin Burke for allowing the reuse of this assignment.