Research Article

Artificial Intelligence in Video Games: Towards a Unified Framework

Algorithm 15

Modified target selection in Graven. Health is compared instead of distance.
void  CptTargetingSystem::Update()
{
int  LowestHPSoFar = MaxInt;
m_pCurrentTarget = 0;
 //grab a list of all the opponents the owner can sense
std::list<CptMvAgent2D>  SensedBots;
SensedBots = m_pOwner->GetSensoryMem()->GetListOfRecentlySensedOpponents();
std::list<CptMvAgent2D>::const_iterator curBot = SensedBots.begin();
for  (curBot; curBot != SensedBots.end(); ++curBot)
{
  //make sure the bot is alive and that it is not the owner
  if  ((curBot)->isAlive() && (curBot != m_pOwner->GetAgent()))
{
   int  hp = (curBot)->Health();
   if  (hp < LowestHPSoFar)
{
LowestHPSoFar = hp;
m_pCurrentTarget =  curBot;
}
}
}
}