O'Reilly logo

Programming Game AI by Example by Mat Buckland

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Goal Arbitration
You now understand how goals work and have seen some concrete exam
-
ples, but you’re probably still wondering how the bots select between strat
-
egy-level goals. This is accomplished by the composite goal
Goal_
Think
, which each bot owns a persistent instance of, forming the root of its
goal hierarchy.
Goal_Thinks function is to arbitrate between available strat
-
egies, choosing the most appropriate to be pursued. There are six strategy-
level goals. They are:
n
Explore: An agent picks an arbitrary point in its environment and
plans and follows a path to that point.
n
Get Health: An agent finds the least cost path to an instance of a
health item and follows the path to that item.
n
Get Weapon (Rocket Launcher): An agent finds the least cost path
to an instance of a rocket launcher and follows the path to it.
n
Get Weapon (Shotgun): An agent finds the least cost path to an
instance of a shotgun and follows the path to it.
398 | Chapter 9
Goal Arbitration
Figure 9.8. Although not explicitly shown, each Goal_Think instance instantiates
three
GetWeaponGoal_Evaluator objects, one for each weapon type the bot can
pick up.
n
Get Weapon (Railgun): An agent finds the least cost path to an
instance of a railgun and follows the path to it.
n
Attack Target: An agent determines a strategy for attacking its cur
-
rent target.
Every think update each of these strategies is evaluated and given a score
representing the desirability of pursuing it. The strategy with the highest
score is assigned to be the one the agent will attempt to satisfy. To facilitate
this process each
Goal_Think aggregates several Goal_Evaluator instances,
one for each strategy. These objects have methods for calculating the desir
-
ability of the strategy they represent, and for adding that goal to
Goal_Thinks subgoal list. Figure 9.8 illustrates the design.
Each
CalculateDesirability method is a hand-crafted algorithm that
returns a value indicating the desirability of a bot pursuing the respective
strategy. These algorithms can be tricky to create so it’s often useful to first
construct some helper functions that map feature specific information from
the game to a numerical value in the range 0 to 1. These are then utilized in
the formulation of the desirability algorithms. It’s not especially important
what range of values your feature extraction methods return—0to1,0to
100, or –10000 to 1000 are all okay — but it helps if they are standardized
across all methods. This will make it easier on your brain when you begin
to create the algorithms for desirability.
To decide what information needs extracting from the game world, con-
sider each strategy goal in turn and what game features have bearing upon
the desirability of pursuing it. For instance, the GetHealth evaluation is
going to require information regarding the status of a bot’s health and the
location of a health item. Similarly, the AttackTarget evaluator is going to
require information in respect to the weapons and ammo a bot is carrying,
in addition to its health levels (a bot low on health is much less likely to
attack an opponent than a bot that is feeling fit as a fiddle). The
ExploreGoal evaluator is a special case as you’ll see shortly, but the
GetWeapon evaluator will require additional knowledge about how far
away a specific weapon is and the current ammo a bot is carrying for that
weapon.
Raven uses four such feature extraction functions, implemented as static
methods of the
Raven_Feature class. Here is the listing of the class declara
-
tion, which contains a description of each method in the comments:
class Raven_Feature
{
public:
//returns a value between 0 and 1 based on the bot's health. The better
//the health, the higher the rating
static double Health(Raven_Bot* pBot);
//returns a value between 0 and 1 based on the bot's distance to the
Goal-Driven Agent Behavior
| 399
Goal Arbitration

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required