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

Calculating the Desirability of Attacking the Target
The desirability of attacking an opponent is proportional to how healthy
and powerful a bot is feeling. The “powerful” feature, in the context of
Raven, is an indication of the number of guns and ammo a bot is carrying
and is evaluated by the method
Raven_Feature::TotalWeaponStrength.(I
recommend you take a peek inside this method next time you’re sitting at
your computer.) Using these two features we can calculate the desirability
of pursuing the AttackTarget goal:
Here’s how it looks written in code:
double AttackTargetGoal_Evaluator::CalculateDesirability(Raven_Bot* pBot)
{
double Desirability = 0.0;
//only do the calculation if there is a target present
if (pBot->GetTargetSys()->isTargetPresent())
{
const double Tweaker = 1.0;
Desirability = Tweaker *
Raven_Feature::Health(pBot) *
Raven_Feature::TotalWeaponStrength(pBot);
}
return Desirability;
}
z
TIP Depending on how sophisticated you need your agent to be you can add
and remove strategies from the arbiter. (Remember,
Goal_Think is the arbiter
of a Raven bot’s strategy goals.) Indeed, you can even switch in and out entire
sets of strategy goals to provide an agent with a whole new suite of behaviors to
select from. Far Cry, for instance, uses this sort of technique to good effect.
Calculating the Desirability of Exploring the Map
This one is easy. Imagine yourself playing the game. You’re only likely to
go exploring the map if there are no other things requiring your immediate
attention like attacking an opponent or looking for ammo or health. Conse
-
quently, the desirability of exploring the map is fixed as a low constant
value, thus ensuring the option to explore is only selected if all alternatives
have lower desirability scores. Here’s the code:
double ExploreGoal_Evaluator::CalculateDesirability(Raven_Bot* pBot)
{
const double Desirability = 0.05;
return Desirability;
}
Goal-Driven Agent Behavior
| 403
Goal Arbitration
attack
Desirability k TotalWeaponStrength Health ´

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