Genetic Algorithm - Game AI
Genetic Algorithm - Game AI
Shooter Bots
Nicholas Cole, Sushi1 J. Louis, and Chris Miles
Evolutionary Computing Systems Laboratory
Department of Computer Science
University of Nevada
Reno, Nevada 89557
Email: {ncole, sushil, miles) @cs.unr.edu
Authorized licensed use limited to: Staffordshire University. Downloaded on March 27, 2009 at 07:51 from IEEE Xplore. Restrictions apply.
of search space, there are a number of acceptable parameter A. Genetic Algorirhmr
optima that will lead to good gameplay. Determining the Genetic algorithms (GAS) are stochastic, parallel search
correct set of parameters is a tedious and time-consuming algorithms based on the mechanics of natural selection and
one, since a slight change to one parameter will often have a evolution [13], [14]. GAS were designed to efficiently searsch
negative impact on other parameters, i.e. they are non-linearly large, non-linear, poorly-understood search spaces where ex-
dependent. This is our motivation for applying a genetic pert knowledge is scarce or difficult to encode and whtae
algorithm to find a good set of these rule-based parameters. traditional optimization techniques fail. Robust and flex-
We ask, "Is it possible to use a genetic algorithm to tune the ble, GAS exhibit the adaptiveness of biological systems. .As
parameters as well as a human can?' such, GAS appear well-suited for searching the large, poor'ly-
Recently, the scientific community has taken an interest understood spaces that arise in tuning problems, specifically,
in using commercial 3-D engines such as Quake, Unreal, tuning parameterized rule-based bots for Counter Strike.
and Half-Life as a testbed for advanced AI research [I], [6],
171, [8]. We also believe Counter Strike, a game which runs 11. COUNTERSTRIKE
inside the Half-Life engine, to a be a good testbed for AI Counter Strike is a popular first-person shooter game in
research. John Laird uses the Soar AI Engine, a rule-based which counter terrorists try to neutralize terrorists. The game
expert system, to design bots that play Quake 11, another has a strong emphasis on tactics, decision-making, and team-
popular first-person shooter. The Soar engine is re-useable play, and we believe it serves as a good testbed for our work.
from game to game within a specific genre, requiring only Figure 2 shows an in-game screenshot.
changes to the engine calls and not to the AI logic inside of
the Soar Engine [2]. Rogelio Adobatti et al. have developed a
framework inside the Unreal Toumament engine which allows
them to study AI behavior within the virtual environment
provided by the engine [61. Adobatti et al. have also developed
a non-violent game in order to attract more researchers, who
would otherwise be turned away by the extreme violence found
in most first-person shooters.
Realizing the fact that computer game AI is constrained by
hardware limitations, Khoo et al. proposed inexpensive yet
effective methods for improving game AI [I]. Their work
included adding an Elisa-based chat program to an existing
Counter Strike bot in order to make the human players believe Fig. 2. In-game screenshot o f Counter Sbike
they were not playing against bots but rather other humans [ 11.
Many existing works present tutorials and background in- There are a number of variant types of gameplay for Counter
formation and provide excellent fundamental information for Strike, but we focused on one subset of gameplay inside
commercial game developers [9], [IO], [ll]. Counter Strike called the defuse mission. In the defuse mission,
Work by Fogel with Blondie24 shows that coevolutionary counter terrorists are tasked with preventing the terrorists from
computation can lead to a ranked AI checker player [4]. planting a bomb at one of two locations on the map. A map
Axelrod's work with the iterated prisoner's dilemma problem can be thought of as an environment in which the game takes
has also shown that coevolution techniques can lead to the place. Figure 3 shows an overhead view of a typical Counter
discovery of successful game strategies [ 5 ] . Since Counter Strike map. The counter terrorists may win by defusing a
Strike is not a turn-based game like most board and card planted bomb. The terrorists may win by planting a bomb
games, it may not lend itself well to currently established and protecting it from defusal until its detonation. Either side
coevolution techniques. Since coevolution may not be directly may win by eliminating all members of the opposite te;m,
applicable, we are simply applying a genetic algorithm to the since either side's goal could be trivially accomplished without
tuning of parameters to ascertain how effective evolutionary interference from the other team.
computation techniques are at first-person shooter games. If To constrain things further, each round of gameplay is
the genetic algorithm can make progress, then we will continue limited to five minutes with a six-second planning phase called
with our plans to coevolve Counter Strike bots. Our eventual freeze time. During freeze rime, each side may purchase new
goal is to investigate evolutionary computing techniques for weapons and equipment. Each item has an associated cost.
knowledge acquisition, human modelling, and teamplay based Table I shows the cost of each primary weapon. A primary
on this platform. We chose Counter Strike because it is weapon, as the name suggests, is the player's weapon of
extremely popular. Last month, players spent over 1.5 billion choice. Secondary weapons, pistols, can also be purchased in
minutes playing Counter Strike online [12]. Garners connect case the primary weapon fails.
from across the globe. This popularity will make it easier to The money to purchase these items is earned by the result
collect more data for human modelling from human players of the previous round. There are penalties and rewards for
as they connect to our server. certain actions during the round as shown in Table 11. 'The
140
Authorized licensed use limited to: Staffordshire University. Downloaded on March 27, 2009 at 07:51 from IEEE Xplore. Restrictions apply.
Fig. 3. This is an overhead view of the Counter Smke map "de-dust2:' The locations where the bomb may be planted by the tenonsts are denoted by a
large X. Counter terrorist begin at the lacation marked C'T Stan. Terrorists begin each round at the location marked T Stan.
TABLE I
the bot's style of play. A less aggressive player tends to locate
PRIMARY WEAPON COSTS IN COUNTER STRIKE[3]
easily-defended positions and wait for the enemy to enter
their kill-zone, whereas an aggressive player relies on the
1 Name 1 effectiveness of a fast-attack to try and catch the enemy off-
guard. A bot should have an aggressivity parameter that is
appropriate for its weapon selection. Guarding a large open
plaza from long distance is nearly impossible with a shotgun.
Likewise, charging into a room with a sniper rifle that needs
significant time to aim properly is not a prudent tactic. By
the time the bot can aim the weapon, its opponents will have
already eliminated it from the round.
TABLE 11
PAYOFFIFINE TABLEFROM COUNTER STRlKEI3I
141
Authorized licensed use limited to: Staffordshire University. Downloaded on March 27, 2009 at 07:51 from IEEE Xplore. Restrictions apply.
requesting the number of kills a certain player has, but the detect this player just as easily as if they were standing in the
SDK does not allow one to view or modify the actual code middle of the street. Our bots, however, use sensor information
inside the engine. Half-Life, like many other commercial 3- gathered from their environment much like human players. For
D engines, is frame-driven. This means if a task takes up example, if they detect another player it is only because the
too much processing time, the frame-rate will drop, clients bot has a line of sight to the player, or it has heard the player's
will lose their connections, and the engine will become non- footsteps.
responsive. The rest ofthis section will describe the selection of param-
The Half-Life engine itself handles physics, rendering 3-D eters, encoding, the evaluation function, the GA's parameters,
geometry, drawing textures, playing sound effects, and man- and Counter Strike game settings.
aging client connections. Counter Strike has its own Dynamic A. Parameter Selection
Link Library (DLL) to manage Counter Strike specific tasks,
First, we identified the parameters to optimize. The I.wo
which includes weapon profiles (rate of fire and reload time),
sets of parameters we focused on were: ( I ) weapon selection
user interface, and gameplay code (widloss conditions). Since
parameters and (2) an aggressiviry parameter (which ultimal.ely
Counter Strike does not have any of its own AI code, it
affects path preference). The weapon selection and aggres.riv-
became necessary to employ the use of yet another DLL
ity of the bot are closely-related in playing Counter Strike.
which contained our bot code. Figure 4 shows how the DLLs
Previously, we described a bot which used a sniper rifle to
and the engine interact. All components enclosed inside of
play more defensively, waiting for the enemy to come to it -
the Half-Life Dedicated Server communicate by means of
this would be associated with a low aggressivity value. One the
function calls. As mentioned previously, we wanted to keep
other hand, a bot that uses small automatic weapons should he
the frame-rate inside of Half-Life up, so we developed a GA
highly aggressive to be effective against its enemies beca.use
Server which manages all GA-related operations outside of the
its weapons have limited range. There exists no one correct
Half-Life engine. The G A Server communicates directly with
strategy to Counter Strike, but it is generally accepted that
the Bot DLL via TCP/IP. The bots receive new parameters
following these styles of play will lead to a better score. Since
from the GA Server each round. At the end of the round,
weapon selection and aggressivity are somewhat dependent
they report their score, which becomes the fitness for that
sets o f parameters, we chose to allow the GA to optimize
individual (parameter set). The GA Server is written in Java, so
these bot parameter sets in the hope that the GA would find a
it is platform independent. Since the Half-Life engine is real-
player who fit either one of these predominant styles. It was
time dependent for its physics calculations, it is infeasible to
also quite possible that the GA would arrive at an strategy that
speed up the engine artificially, while maintaining a reliable
is not easily understood yet effective.
simulation. Realizing this, we are working towards upgrading
the GA Server so it can manage multiple Half-Life Dedicated B. Encoding
Servers, all of which are running simulations of our bots in The encoding was straightforward. Each parameter was
parallel. This will significantly reduce our simulation time. encoded into a binary string consisting of 178 bits. Figure 5
Currently, it takes over two h o m to run 50 generations with shows the chromosome's layout. The number bits to enctode
a population size of 30. weapon preferences and aggressivity was higher than neces-
Ideally, commercial 3-D engines could be more modular. sary. At the time, we believed such resolution was required and
At the moment, the physics, the graphics, and multiplayer in future work we plan to use fewer hits for each parameter
logic, run interdependently. For the purpose of tuning bots, it in order to decrease the size of the search space.
is only necessary for us to have information about the physics
...1 1 I
and geometry of the world - rendering graphics for a bot is
10bitS 15bltS 0 bl&
wasteful.
IV. METHODOLOGY
In order to have a genetic algorithm tune the parameterized
rule-based AI, we had to: (1) select parameters to tune, (2) Fig. 5. Baric layout a of chromosome. F.xh parameter was represented in
binary
allow the GA to evolve parameters values while GAABs play
only against other GAABs, and (3) pit the best GAABs against
bots which were tuned by us in order to evaluate the GA- C. Evaluation Function
selected parameters. As we have many years of Counter Strike The evaluation function was an approximation of the :;tan-
playing experience as well as a solid understanding of the dard Counter Strike PayoffFine table found in Table I1 and
elements of which a good bot is comprised, the bots we tuned provided a straightforward method for measuring fitness. For
are challenging to most veteran Counter Strike players. example, if a bot is tuned with parameters that would lead
Although many commercial bots cheat to play well, our to excessive friendly fire (such as high aggressivity and a
bots, however, do not cheat. Cheating game AI destroys the strong weapon preference for automatic shotguns), then it
game experience [15]. For example, imagine a human player would receive a low fitness per the Payoffffine table :since
is hiding behind a car. Cheating game AI would be able to team killing is severely punished.
142
Authorized licensed use limited to: Staffordshire University. Downloaded on March 27, 2009 at 07:51 from IEEE Xplore. Restrictions apply.
Q G a u n t e r Strike
I Bot D L C
I
0
7
( naif-life Engine
DCL
Fig. 4. The Half-Life engine's architecture relies an communication between DLLs to operate the game. This figure shows how the various DLLs interact
with each other inside of the Half-Life Dedicated Server (HLDS) and haw our GA Server communicates with the HLDS.
D. CA Parameters V. RESULTS
The GA used the parameters in Table I11 during the training The results of the GA can be seen in Figure 6. The GA
phase for the GAABs. Since we considered our search space made steady progress during the 50 generations.
rather large, we wanted the GA to move quickly away from
poor parameter selections. We used an elitist selection method.
In this method, candidates for mating are selected proportional
to fitness, and the offspring double the population size to 2n.
- ....c
Parameter 1 Setting 1 m
Genuatianr m
--
Individuals
Crossover Points 0 6 1 . D 1 s I O . m
probability of Mutation
Selection Method Elitist Fig. 6. The results of the CA selecting the optimal parameters for the bots
Chromosome Length 178 averaged over 15 runs of the CA
143
Authorized licensed use limited to: Staffordshire University. Downloaded on March 27, 2009 at 07:51 from IEEE Xplore. Restrictions apply.
TABLE IV
the GA evaluation function exerts on the bots, the AI could
MATCHRESULTS BETWEEN BOTS
be universally~.
shaped to favor a certain .
plav. stvle
. or tactic.
A good mix of different types of bots makes a game mare
I Team I Average Skill I Standard Deviation I Median I interesting.
GAABs I 1005 1 55.2 I 987
Bo@ tuned by us I 999 I 40.3 1 991
VI. CONCLUSIONS A N D FUTURE
WORK
144
Authorized licensed use limited to: Staffordshire University. Downloaded on March 27, 2009 at 07:51 from IEEE Xplore. Restrictions apply.
REFERENCES
[I] A. Khoa and R. Zubek. Applying inexpensive techniques to computer
games. In IEEE lnrelligenr Systems, pages 2-7, 2002.
[2] M. van Lent and J. Laird. Developing an artificial intelligence engine.
In GDC Proceedings. 1999.
I31 Counter Strike ”1.6 Monuol. htrp:llwww.counter-shih.neflmanual.hrml.
1.6 edition.
141 D. B. Fogel. Blondie24: Playing ai rhe Edge of Al. Morgan Kaufmann,
2002.
IS] R. Axelrod. The evolution of strategies in the iterated prisoner’s
dilemma. In L. Davis, editor, Generic AIprirhms and Siniuloted
Annealing, pages 32-41. Morgan Kaufman, 1987.
[61 R. Adobbati, A. Marshall, A. Scholer, S. Tejada. G. Kaminka, S. Schaf-
fer, and C . Sollino. Gameboa: A 3d virtual world test-bed for multi-
agent research. In Comntanicolions of rhr ACM, 2002.
[7] 1. E. Laird. Research in human-level ai using computer games. In
Communicnriuns of lhe ACM, pages 32-35, 2002.
[81 M. Lewis and J. Jacobson. Fame engines in scientific research. In
Communimrionr oflhe ACM. pages 27-31. 2002.
(91 M. Buckland, editor. AI Techniqurs for Game Programming. Premier
Press, 2002.
[IO] F.D.ha”.Genetic algorithms: Evolving the perfect troll. In
S. Rabin, editor, AI Programming Wisdom, pages 629-639. Charles
River Media. 2003.
1111 A.J. Champaodard. AI Game Devrlopnrnr. Pearson Education. 2003.
I121 Valve. Steam network slaNs. Web page. February 2 W .
hnp:llwww.steampowered.~~~~~t~~g~~e-~t~.h~.
[I31 J. Holland. Adaprarion In Narural andArrij+ciai Sysrems. The University
of Michigan Press. Ann Arbor, 1915.
1141 D. E. Goldberg. Generic Algorilhni in Searclr, Opriniizarion. and
Machinr Learning. Addison-Wesley. Reading. MA, 1989.
1151 J. Laird and M. van Lent. Human-level ai’s killer application: Interactive
computer games. In AAAI, 2000.
1161 Lany 1. Eshelman. The CHC adaptive search algorilhm: How to have
safe search when engaging in nontraditional genetic recombination. In
Gregory J. E. Rawlins, editor, Foundmiom of Generic Algorilhms-1.
pages 265-283. Morgan Kauffmao, 1991.
1171 Psychosma FAQ. http://www.pnychostats.collllfaqphp, 1.9. I edition.
1181 A. Elo. The “ring ofchesqioyers. p a t andpresent. Arco, 1978.
145
Authorized licensed use limited to: Staffordshire University. Downloaded on March 27, 2009 at 07:51 from IEEE Xplore. Restrictions apply.