IMGD 400X (B 08)
Homework Assignment #9
Steal Health
Due by Web Turn-In: Midnight, Wednesday, December 3
(See general homework instructions for turn-in details.)
The purpose of this assignment is to familiarize you with the behavior tree code in the Raven game, so that you can implement new goals for your personal Raven bot implementation, which will eventually be submitted as Homework #12 for entry into the Raven tournament.
You should only create and modify files in your personal bot folder! And remember to mark all your changes with //* comments to make your work easier to grade.
You will implement a new composite goal, "steal health", for use by the personal Raven bot that you created in Homework #8. The idea is that your bot should collect a health pack even if it doesn't need it, when there is a nearby opponent who does need it. Following is sketch of what you need to do. You should consult the code for similar existing goals, such as Goal_GetItem, for more details.
- You will need to create two new classes, Goal_StealHeath and StealHealthGoal_Evaluator, in your personal bot folder and modify your bot's version of Goal_Think.
- Starting with Goal_StealHealth:
- You will need two private members, of type AbstRaven_Bot* and Trigger* respectively, to keep track of the target bot you are stealing from and the health pack you are stealing.
- Define the Activate method:
- set status to active
- if this goal is reactivated, then there may be some existing subgoals that must be removed
- it is possible for the target bot to die while this goal is active, so test to make sure target bot is alive
- if health pack is already claimed, give up
- if target is alive and health pack is available, add subgoal (instance of GetItem)
- Define the Process method, which is similar to other composite goals.
- Now that you have a new goal, you need to add an evaluator, StealHealthGoal_Evaluator, to detect when it is appropriate to invoke this goal:
- The key method in an evaluator is CalculateDesirability. The desirability should be a function of how much closer to the health pack your bot is than the closest opponent, and how badly the other bot needs it.
- find the closest active health pack (write utility routine, see below)
- if no active health packs, return 0
- find the closest known opponent (write utility routine, see below)
- if there are no known opponents or the closest opponent closer to health pack, return 0
- use some reasonable formula based on opponent's distance and health to calculate desirability
- ensure return value is between 0 and 1 using Clamp method
- bias return value using m_dCharacterBias
- return desirability value
- Define a SetGoal method which calls the AddGoal_StealHealth method (which you will add to Goal_Think, see below)
- Define a RenderInfo method by analogy with other evaluators.
- Define a ClosestActiveHealth utility method which, given a pointer to a bot, returns the closest active health pack trigger, if any. For efficiency, use the Euclidean distance rather than trying to find the actual path to the health pack
- Define a ClosestBotToHealth utility method which, given your bot and a health pack trigger, returns the closest opponent in GetListOfRecentlySensedOpponents and its distance (use call-by-reference for the distance).
- Now that you have an evaluator class, you need to modify your bot's version of Goal_Think to use it:
- Add a line in the constructor to retrieve a new Bot_StealHealthGoalTweaker parameter from your bot's Lua initialization file.
- Add a line in the constructor to add an instance of StealHealthGoal_Evaluator to the list of evaluators.
- Define an AddGoal_StealHealth method (see other add goal method examples in superclass).
- Since you can't add goal_steal_health to the enum in Raven_Goal_Types.h, simply define thisvariable as a toplevel const int with value 18 in your version of Goal_Think.h.
- For personal debugging, you can add a case for goal_steal_health to Raven_Goal_Types::Convert, even though it won't show up in the tournament.
- Also add a debug_con print statement to this method, so you can demonstrate that this goal was activated (see below).
Run the Raven program with your bot selected to observe. You should see the desirability value for the new goal displayed at the bottom of the window. See if the goal is invoked in the right sorts of circumstances. You may need to adjust the tweaking parameter and/or the desirability calculation to get the behavior you want.
Turn on the debugging console as per instructions on page 191 in Buckland and create a DebugLog.txt file which demonstrates that the new steal health goal was activated.
What to Turn In
- Zip file containing your new bot folder only.
- DebugLog.txt file demonstrating that the steal health goal was activated.
Grading
- 4 points - Record of successful run.
- 1 point - Software engineering quality (modularity, comments, coding style).
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.