Monday, January 28, 2008

You've Got My Attention

Everyone has had moments of deep concentration, only to be interrupted by someone's voice. Turning to see who spoke is the natural response. People naturally look at whatever thing has their attention, so a First Person Shooter bot should be no different. And because "looking" (aiming) is literally half of this AI problem, bots need a detailed mechanism for deciding what occupies their attention. Just figuring out what the bot wants to look at is complex enough.

Last post I described how bots become aware of different enemy targets and select one as the target to aim at. But just because the bot has an enemy to aim at doesn't mean there isn't something even more demanding of the bot's attention. And what happens when the bot can't find an enemy to look at? They have to look at something, presumably in the direction an enemy is most likely to appear.

The selection of where to look is handled by the aim engine (ai_aim.c). The selection algorithm uses a simple priority structure to arbitrate between conflicting things. For example, if the bot needs to jump over a pit while there is an enemy nearby, the bot will always look in the direction of the jump so it doesn't mess it up. While aiming at the enemy it might score the bot a kill, doing so makes the bot extremely likely to fall down the pit to its death. The bot can always aim at the enemy after landing the jump. Similarly if the bot hears a noise that might have been made by a player, the bot will only turn to inspect that area if the bot doesn't already have a known target. Aiming at enemies has a lower priority than getting air but a higher priority than finding additional targets.

Here is the list of typical aiming reasons, from most to least important, as taken from BotAimSelect():
  • Jumping over pits
  • Aiming at enemies
  • Shooting destructible objects like mines
  • Looking forward when swimming
  • Face a non-hostile target that has the bot's attention
  • Look at the item the bot is going to pick up
  • Look in an area enemies are likely to be
  • Look at the same thing as last time
Interestingly, this prioritization is analogous to Maslow's Need Pyramid. Maslow theorized that humans rank their needs according to priorities, with each need fitting into one of 5 categories:
  • Physiological Needs (being free from short term danger)
  • Safety (being free from long term danger)
  • Love (being accepted)
  • Esteem (being appreciated)
  • Self Actualization (just being who you are)
People don't worry about getting love (level 3) when they need a job just to survive (level 2) or need food (level 1).

The base of Maslow's pyramid is comprised of immediate pressing needs, just like the top of the aiming priorities. Bots look forward when jumping because they will die if they don't. Bots don't look at items when there's an enemy nearby who wants to kill them. In this regard, bots are like humans. We are all programmed for survival as the greatest need.

No comments: