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

Putting It All Together
Once a desirability function has been defined for each evaluator object, all
that remains is for
Goal_Think to iterate through them each think update
and select the highest to be the strategy a bot will pursue. Here’s the code
to clarify:
void Goal_Think::Arbitrate()
{
double best = 0;
Goal_Evaluator* MostDesirable = NULL;
//iterate through all the evaluators to see which produces the highest score
GoalEvaluators::iterator curDes = m_Evaluators.begin();
for (curDes; curDes != m_Evaluators.end(); ++curDes)
{
double desirabilty = (*curDes)->CalculateDesirability(m_pOwner);
if (desirabilty >= best)
{
best = desirabilty;
MostDesirable = *curDes;
}
}
MostDesirable->SetGoal(m_pOwner);
}
z
TIP Human players have the ability to anticipate what another player is about to
do and act accordingly. We can do this because we are able to briefly shift our
point of view to that of any other player and think about what their desires
might be given our understanding of their state and the state of the game
world. Here’s an example:
You observe from a distance two players, Sid and Eric, battling it out
with rocket launchers when all of a sudden, after getting hit twice in suc
-
cession, Eric breaks off and starts running down a corridor. You shift your
point of perspective to Eric and, because you know he’s low on health, you
anticipate it’s very likely he’s heading toward the health pack you know he
knows is located in a room at the end of the corridor. You also realize that
you are positioned closer to the health than Eric so you decide to “steal” it
away from him and wait out of view until he arrives, whereupon you smear
his intestines along a wall with your plasma rifle.
The ability to anticipate another’s actions like this is an innate characteristic of
human behavior — we do it all the time — but it is possible to give an agent a
similar, if somewhat much lessened, capability. Because the desires of goal arbi
-
tration agents are determined algorithmically, you can have a bot run the
relevant attributes (health, ammo, etc.) of the human player through its own (or
custom) arbiter to make a guess at what the player’s desires might be at that
time. Of course the accuracy of this guess very much depends on how closely
the bot’s desires match the player’s — and that’s up to your behavioral model
-
ing skills — but it’s usually not too difficult to make the occasional accurate
prediction that enables a bot to give the player a nasty surprise, even with a
very basic model.
404 | Chapter 9
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