Research Article

Artificial Intelligence in Video Games: Towards a Unified Framework

Algorithm 21

Implementation of the Attack conceptual control in BW. Because the targeting AI only selects targets the unit can attack, the test to see whether the unit is flying could be discarded.
void  Attack(int  agent_id, int  target_id)
{
Unit u = Broodwar->getUnit(agent_id);
Unit v = Broodwar->getUnit(target_id);
 // Don't attack under explicit move orders
if  (u->getOrder().getID() == Orders::Move)
  return;
 // Already attacking that target
if  (u->getLastCommand().getTarget() != NULL && u->
getLastCommand().getTarget()->getID() == target_id)
  return;
if  (v->getType().isFlyer())
{
  if  (u->getType().airWeapon() != WeaponTypes::None)
u->attack(v);
  return;
}
else
{
  if  (u->getType().groundWeapon() != WeaponTypes::None &&   u->exists())
u->attack(v);
  return;
}
}