O'Reilly logo

Programming Game AI by Example by Mat Buckland

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

AI Design Considerations
The design of the Raven bot AI is approached in the usual manner: We
consider what behavior is required of the bots to be successful within their
environment and decompose that behavior into a list of components we are
able to implement and coordinate.
I’m sure you have either played or watched someone play a Quake-like
deathmatch game, so let’s mull over that experience and see what observa
-
tions can be made about how a human player plays this sort of game. Two
obvious skills required are the ability to move around and the ability to aim
and shoot a weapon at other players. What isn’t so immediately obvious is
that if you watch experienced players you will notice that they are almost
always aiming and shooting at an enemy (provided one is in their vicinity)
whether they are attacking or defending, and regardless of the direction
they are moving. For instance, they might be strafing from side to side or
running away backward while laying down defensive fire. We’ll take a tip
from this observation and implement the weapon handling and movement
components of the AI so that they operate independently of each other.
What sort of movement related skills will the AI need? It’s clear a bot
should be able to move in any direction while avoiding walls and other
bots. We can also see it’s necessary to implement some type of search algo-
rithm to enable the AI to plan paths to specific locations or items.
What about weapon handling? What kind of weapon related decisions
does a player have to make? Well, first of all, a player has to decide which
weapon is best suited for the current situation. In Raven there are four
kinds of weapons: the blaster, the shotgun, the rocket launcher, and the
railgun. Each of these weapons has pros and cons. For example, a shotgun
is devastating when an enemy is close, but because of the way the shot
spreads outward as it travels away from the gun muzzle it becomes much
less effective with distance (see Figure 7.4). A rocket launcher is great at
medium distance but is dangerous to use up close because of the
splashback from the explosion. Any AI we implement must be able to
weigh the pros and cons of each weapon and select one accordingly.
A player also has to be able to aim his chosen weapon effectively. For
weapons that fire high-velocity projectiles, such as the railgun and shotgun,
a player must aim directly at an enemy’s position, but in the case of weap
-
ons that fire slower-moving projectiles, such as the blaster or rocket
launcher, a player must be able to predict the enemy’s movement and aim
accordingly. The bot AI must be able to do the same.
Often in games of this sort a player will be pitted against multiple oppo
-
nents. If two or more enemies are visible, the player must decide which one
to target. As a result, any AI we design must also be able to select a single
target from a group. This brings us to another issue: that of perception.
Human players select targets from the opponents perceived by their senses.
Raven: An Overview | 313
AI Design Considerations
In Raven this includes visible opponents and opponents that are noisy
enough to be heard. In addition, humans also use their short-term memory
to keep track of any bots they have encountered recently; human players do
not instantly forget about opponents that have recently moved out of their
sensory range. For example, if a player is chasing a target that then disap-
pears around a corner, he will keep chasing the target even though it cannot
be seen. To be convincing, any bot AI must also exhibit similar sensory
abilities.
Of course, all the skills mentioned thus far operate at a fairly low level.
For many games of this type, it’s simply not enough to run around a map at
random, firing at enemies only when they’re stumbled upon. A decent AI
must be able to reflect upon its own state and that of the world around it
and choose actions it thinks will help improve its state. For example, a bot
should be able to recognize when it is running low on health and formulate
a plan to locate and navigate to a health item. If a bot is fighting an enemy
but is short on ammo, it should be able to consider the possibility of break
-
ing off the fight in order to locate a few extra rockets. Therefore some type
of high-level decision-making logic must be implemented.
314 | Chapter 7
AI Design Considerations
Figure 7.4. Shotgun damage

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required