International Journal of Computer Games Technology / 2015 / Article / Alg 6

Research Article

Artificial Intelligence in Video Games: Towards a Unified Framework

Algorithm 6

Avoiding enemy attacks by staying out of range. This function can be used for kiting.
void  stay_safe(Unit  u, UnitList  enemies)
{
UnitList threats;
UnitList::iterator e;
 //Iterate on enemies to detect immediate threats
for  (e = enemies.begin(); e != enemies.end(); ++e)
 {
  //Ignore enemies that can't be outrun
  if  (u->maxspeed() > (e)->maxspeed() &&
   distance(u->position(), (e)->position() + (e)
    ->velocity()) <= (e)->maxrange())
   threats.add(e);
 }
 //Get the center of the threats
Vector c = center(threats);
 //If the unit is located at the center, drop one of the threats
if  (c == u->position())
  c = center(remove_weakest(threats));
 //Create a force that pulls the unit away from the center
Vector dir = u->position() − c;
 //Add a steering force of maximum magnitude
u->addforce(diru->maxforce()/dir.norm());
}

We are committed to sharing findings related to COVID-19 as quickly as possible. We will be providing unlimited waivers of publication charges for accepted research articles as well as case reports and case series related to COVID-19. Review articles are excluded from this waiver policy. Sign up here as a reviewer to help fast-track new submissions.