Research Article

Artificial Intelligence in Video Games: Towards a Unified Framework

Algorithm 16

Vision update in the Graven sensory memory module.
void  CptSensoryMemory::UpdateVision()
{
 //for each bot in the world test to see if it is visible to the owner of this class
const  std::list<CptMvAgent2D> & bots = m_pOwner->GetWorld()->GetAllBots();
std::list<CptMvAgent2D>::const_iterator curBot;
for  (curBot = bots.begin(); curBot != bots.end(); ++curBot)
{
  //make sure the bot being examined is not this bot
if  (m_pOwner->GetAgent() !=  curBot)
{
   //make sure it is part of the memory map
MakeNewRecordIfNotAlreadyPresent(curBot);
   //get a reference to this bot’s data
CptMemoryRecord & info = m_MemoryMapcurBot;
   //test if there is LOS between bots
if  (m_pOwner->GetWorld()->isLOSOkay(m_pOwner->GetAgent()->Pos(), (curBot)->Pos()))
{
info.bShootable =  true;
    //test if the bot is within FOV
    if  (isSecondInFOVOfFirst(m_pOwner->GetAgent()->Pos(),
m_pOwner->GetAgent()->Facing(),
(curBot)->Pos(),  m_pOwner->GetAgent()->FieldOfView()))
{
info.fTimeLastSensed = Clock->GetCurrentTime();
info.vLastSensedPosition = (curBot)->Pos();
info.fTimeLastVisible = Clock->GetCurrentTime();
if  (info.bWithinFOV ==  false )
{
info.bWithinFOV =  true;
info.fTimeBecameVisible = info.fTimeLastSensed;
}
}
    else
{
info.bWithinFOV =  false ;
}
}
   else
{
info.bShootable =  false ;
info.bWithinFOV =  false ;
}
}
 }//next bot
}