SHORTCUTS TO KAOS: COMPLEX BEHAVIOUR FROM SIMPLE DYNAMICS

From: AAAI Technical Report SS-00-02. Compilation copyright © 2000, AAAI (www.aaai.org). All rights reserved.
SHORTCUTS TO KAOS: COMPLEXBEHAVIOUR
FROM SIMPLE DYNAMICS
Gary Ushaw&GordonBell, VIS Interactive,
~ary@vis-plc.com, gordon@vis-plc.com
Dunfermline, Scotland.
the AI modulescan tap into. A possible area
of research whichmaybe of use to the AI
programmerwith this extra CPUresource at
his fingertips is chaos theory. This paper
outlines howthe increased processing power
of a next generation console has been
utilised on a gamecurrently under
developmentat VIS Interactive which will
be referred to throughoutthis paper by its
codename, "Kaos".
Abstract
A gamecurrently under development at VIS
Interactive utilises someof the tenets of
chaos theory and non-linear dynamicsin its
AI modulesto take full advantageof the
vastly increased processing poweravailable
to the programmerof next generation
consoles such as Playstation2. This paper
concentrates on howapparently complex
behaviour of agents can be attained from
disarmingly simple dynamics, while
drawingparallels to the field of chaos
theory. Oneof the basic tenets of chaos
theory is that a mathematicallysimple set of
dynamicscan result in an endlessly complex
and non-repeating behaviour; this bears a
similarity to workin such AI fields as
flocking and A-life.
A discussion of chaos theory and its possible
relevance to AI-programmingfor games is
presented. A brief description of the game,
Kaos, is provided, followed by an
examination of howthe various elements of
the AI moduleare being implemented. The
final section of the paper discusses possible
areas of gameAI which could benefit from
this chaotic approachin the future.
Chaos Theory
Chaostheory is a relatively newbranch of
mathematics which studies the behaviour of
a class of non-linear systems. Providing a
rigorous definition of chaosis a can of
wormswhich is best left unopened, however
there a numberof features which a chaotic
systemwill tend to exhibit.
Introduction
The arrival of the next generation of home
console hardware presents the programmer
of game AI with a new and unprecedented
set of challenges. Todate, the limited
processing power available on game systems
has been utilised primarily for graphics
processing, collision routines and physics
calculations, leaving only a small percentage
of CPUtime for artificial intelligence. If
Sony’s marketing department is to be
believed, however, the "Emotion Engine" of
Playstation2 will allow the implementation
of character interaction whichcan pass the
Turing test three times before breakfast and
still leave roomfor morepolygon
manipulation than you could shake a prerenderedstick at. In reality, it is likely that
the processing powerrequired for geometry
transforms, graphical effects, animation,
collision, etc, will expandto fill the newly
available CPUtime, leaving a similar
percentage of processing resource available
for AI as is currently the case. However,
such a scenario still provides us with a vast
increase in the amountof CPUpower which
70
¯
Non-periodic but bounded. A chaotic
systemis not periodic, in that it will
never repeat a particular variable state.
However,the system is bounded(if the
initial values fall within the "basin of
attraction"), whichmeansthat the
variables of the system remainwithin
certain limits as the systemevolves.
¯
Sensitive dependenceon initial
conditions. A very small change to a
chaotic systemwill radically changethe
state of that system over time, compared
to howthe system would have evolved
without that change. This is most
popularly, and not entirely
apocryphally,illustrated by the
"butterfly effect", wherebyit is said that
a butterfly flapping its wingsin the
Brazilian rainforest can cause a
hurricane to strike HongKongharbour
[11.
¯
¯
Longterm prediction is impossible.
This is a direct result of the sensitive
dependenceon initial conditions
described above. An error, however
small, in measuringa chaotic system
meansthat the modelof that system
used for prediction has marginally
different initial conditionsto the actual
system. Hence the modeland the
systemwill diverge over time.
Expansionand contraction of phase
space.
A goodpopulist account of the history and
theory of the study of chaotic systems can be
found in [2]. Further seminal workson the
subject are foundin [3], [4], [5] and [6]. The
related field of fractals was most famously
presentedin [7].
ChaosTheoryIn GameAI
As game environments become more
complexand more extensive, the behaviour
whichthe player expects to see within that
environment will also becomemore
complex. An area of research which maybe
of use is that of chaostheory and non-linear
dynamics. A numberof aspects of a chaotic
systemwouldseemto be of interest to us in
our quest to provide a deeper and more
varied gamingexperience.
Non-linear dynamics and chaos theory have
shownthat very complex behaviour can
result from a simple set of equations. An
exampleof this is the Lorenzsystem[8],
which
consists of three
simple
first order
....
~
°
differential equauons; ReraUvelysolwng
these equations over time results in an
output whichnever repeats itself, yet never
leaves a boundedregion of possible states.
The non-repetitive yet boundednature of
such systemsis clearly of interest to a game
AI programmerseeking to portray a
constantly interesting yet consistent
character. Aninfinitesimal changeto the
seed values provided to such a systemwill
producea large changeto the output after
very fewiterations, to the extent that the
instantaneous state of the systemwill be on
a completelydifferent part of the attractor
(an attractor can be thoughtof as the set of
all possible states of the system).This is
"sensitive dependenceon initial conditions".
This also wouldseemto be of interest to
gameAI programmers,as it describes a
system capable of responding to the subtlest
of changesin the player’s interaction with
the NPC.
It is well-knownwithin the AI community
that complexand organic-looking flocking
can be achieved from simple rule-sets,
wherebyindividual agents react to their
nearest neighbours in a pre-determined way.
This approach is very similar to someof the
methodologiesutilised in the study of nonlinear dynamicsand chaos theory. In
particular, whenstudying a chaotic sequence
of data (eg in order to measureits Lyapunov
exponents) a nearest neighbour approach is
generally taken, after embeddingthe data as
an attractor on a manifoldof suitable
dimension. As processing power becomes
more freely available someof the more
numerically intensive methodsof carrying
out such studies maybecomeapplicable to
games.
Takingthis further, chaotic systems are
regularly studied in four, five, or more
dimensions. This could be of use to a game
where an emotionsuch as anger, fear or
contentmentis attributed to individual
characters on a sliding scale. Eachof these
emotionscould be treated as an extra
dimension. Nearest neighbours in the three
dimensions of the gameworld would have
an effect on one another’s contentment
level: conversely, neighboursin the
"contentment dimension" would have a
greater effect on one another’s movement.
In the study of chaotic systems, nearest
neighbours are defined as those occurring
within a n-dimensional hyper-sphere around
the point of interest. If each emotionto be
representedis on a sliding scale, then each
can be represented as an extra dimensionof
the hyper-sphere, with the centre occurring
at the current position and emotionalstate of
the agent being processed.
Project "Kaos’:" Whatis it?
Kaosis a gameinvolving as manyas three
hundred autonomousagents on screen at
once, set within an expansive urban
environment. Each agent is an animated
polygonal model of a humanbeing. The
environment is a working three-dimensional
city in whichagents go about their daily
business until the player character interacts
with them. Withinthe city there are literally
thousandsof agents, all completely
autonomous,all under control of the AI
module.This is not a strategy or resource
managementgame such as Sim City or
Populous, but a gamewherethe player is in
direct control of a specific protagonist,
viewedfrom a third person perspective, as
he navigates a gamearena filled with
characters which can be influenced on an
individual basis. At first sight, any AI
programmerof merit ought to balk at the
thought of implementingwhat has just been
described, especially given the constraints of
time, programmingresource and quality
necessitated by a commercialproduct.
However,the over-riding salient fact to be
borne in mind from the abovedescription is
contained within the first four words: "Kaos
is a game".It is not a simulation,it is not a
research project, it is not a fly-on-the-wall
documentaryor an interactive movie. If a
piece of AI behaviour is convincing within
the context of the game,then it is perfect
and needs no further refinement or
complication. As such, the underlying AI
approach must be both simple and flexible,
particularly given the large numbersof
agents to be handled.
purposes of this paper. The converseof this
statement is that a simple set of equations or
rules can result in highly complex
behaviours;the trick is to find that crucial
rule set.
¯
Grid Squares
Kaos involves a large numberof agents on
screen at once, so an efficient collision
routine wasrequired. Fortunatelyit is set in
an Americancity (and none of the characters
have the powerof flight) so a twodimensional grid-based collision system was
ideally suited to our purposes. Suchan
approach has the added advantage of
providing us with access to a wealth of
knowledge on AI implementation. The most
obvious area in whichthe grid square
approachprovides us with a clear solution is
the challenge of path-finding. The majority
of literature available on path-finding
utilises an environmentbased on grid
squares, so an adapted form of A* was
easily addedto the project. A Line Of Sight
algorithmis also ideally suited to the grid
square paradigm, so we can quickly give our
characters a sense of their surroundings.
Line of sight can be achieved using the
algorithms described by Bresenham,since
we have knowledgeof whether or not each
square is solid, and a square equates to a
pixel in Bresenham’salgorithm. This is
considerably moreefficient than resorting to
someform of ray-tracing to cheek a line of
sight. The grid squares provide further
advantagesfor camerafunctionality, testing
the locality of objects or characters, and
display clipping.
AI Implementation on Kaos
In the case of Kaos, the increased processing
poweravailable for use by the AI code is
largely taken up by the sheer numbersof
agents whichneed to be processed for this
game.Whatfollows is a description of the
various parts of the AI code which have
been implementedin order to provide this
functionality. Particular note is taken of
those aspects of the AI code whichhave
included aspects of chaos theory, or which
bear discussionin relation to it.
Clearly there is little direct cross-over
between the grid-square system and chaos
theory. However,any code which relies on
finding nearest neighbourswill benefit
greatly if the environmentis sub-divided; in
Kaos, the grid-squares provide this extra
efficiency.
Twothings have becomeapparent during
this implementation.Firstly, to provide AI
for a gameof this nature, it has been
advantageousto combinethe best of all AI
approaches, taking what is suitable from
each in order to solve a particular problem.
Secondly, we have repeatedly found that
apparently complexbehaviour can arise
from disarmingly simple mechanics. This is
a basic tenet of chaos theory, whichthe
authors have unashamedlyhijacked for the
¯
Scripting Language
It was decided at an early stage that muchof
the functionality required, by Kaos,in terms
of both game-playscenarios and
environmentalcolour, could best be supplied
through the use of a scripting language. This
tool provides the GameDesigners with a
great deal of control over the gameand the
environment while remaining extremely
flexible. It is also a simplematter to extend
72
functionality by adding newscripting
commands.Aninitial set of simple scripting
commandswere provided, such as
"SendTo", "If_Arrived_At",
"Is_Object_Damaged","StartTimer", etc.
This initial command
set allowed the game
designers to script complexbehaviour and to
experiment with this behaviour without
having to resort to Software support. Oncea
satisfactory piece of behaviour has been
settled on then, if necessary, a newscripting
commandcan be added to implement the
behaviourmoreefficiently. It’s importantto
note that the scripted behaviour must work
in conjunctionwith the AI code, so that
things like collisions, generic behaviours,
etc are not left in the handsof the scripters.
This is an exampleof a goodand wellplanned AI approach making everybody’s
job a lot easier.
Againthere is virtually no input from chaos
theory here, as a scripted piece of behaviour
generally needs to be very specific for
gameplayor scenario reasons. It would,
however,be possible to provide script
commandsfor introducing chaotic
behaviour, or changingthe nature of it, as
specific gameevents occur.
¯ Map Properties: embedded AI
Informationof use to non-player characters
is embeddedin the gameenvironment, in the
formof object properties, grid-square
properties and area properties. This reduces
the amountof information which needs to be
attached to each agent, and relieves the
amount of donkey-work which would
otherwise be involved in scripting. For
example, in order to decide whether an
object can be picked up and thrown, an
agent just needs to check.the properties of
that object; similarly, in order to find a
target to throwthe object at, the agent
searchesthe vicinity for an object with
suitable properties. Properties attached to
grid squares define howagents react on
those squares (for examplea vehicle won’t
drive on a grid markedas sidewalk, unless
specifically scripted to do so). Similarly,
wider area properties can be attached which
will affect different characters in different
ways(so a character from a well-to-do
district is unlikely to wanderinto a ghetto,
whereasa group of inhabitants of the ghetto
may cause some damage in Downtown).
Embeddinga chaotic property can have an
interesting effect here. The reaction of NPCs
to this embeddedproperty will change over
time, as the property changes, but remain
within a defined set of boundaries. For
example, a broken sewer would repel NPCs,
dependingon howsmelly it is. This
"smelliness factor" is embeddedin the map
as a chaotic property; hencethe lengths to
which NPCsgo in order to avoid the sewer
varies over time, as if the smell is billowing
out in a non-repetitive manner. This only
requires storing the current state of the
chaotic systemused (typically three floats),
and a piece of codeto iterate these values
(typically a handful of multiplications and
additions).
¯ Living City
One of the biggest challenges presented by
Kaoswas to successfully imply a fully
functionalcity. If the playerjust standsstill
and watches, a wealth of independent
behaviourought to be apparent: pedestrians
walkingdownthe street, stepping into a
shop, waiting for a bus, crossing the road,
vehicles stoppingat traffic lights, giving
wayat junctions, etc. This has been
achieved through a combinationof the three
elements described above. The grid square
approachresults in a straightforward wayof
deciding which parts of a mapare available
for pedestrians (ie sidewalks) and whichare
available for vehicles (ie roads). This
information is embeddedwithin the map, so
that any agent can easily find out about the
properties of its current grid square and of
surrounding grid squares. Similarly
properties relating to the occupancyof
buildings (howmanypeople are inside),
whethera building can be entered (eg a bar),
whereto queue for a bus or cross a busy
street are all embeddedwithin the map
objects and grids. Further complexityof
living city functionality is providedby
specifically scripted scenarios whichmay
trigger after a particular set of player
actions, or just randomlyif the player is
sufficiently close to notice.
Thepossibilities for including chaotic
dynamicsin the living city behaviourare
enormous.As has been discussed, chaos
provides a non-repeating source of raw data
whichis smoothand "organic". This is not a
bad description of the sort of behaviourthat
is required for a convincingliving city. If
complexbehaviour can arise from a simple
set of rules, if those rules are correctly
tailored, bears a striking resemblanceto the
study of non-linear dynamicsand chaos
theory.
the player chooses to follow a NPCat
randomas it traverses the city, it is highly
preferable that this character does not simply
walk round and round a repeated route.
Addingchaos to the NPC’sactions and
choices prevents this from happening.
As an aside, and on a purely speculative
level, it could be suggestedthat this crowd
behaviour exhibits chaotic dynamics. Oneof
the waysof defining a chaotic systemis that
it has both a positive and negative Lyapunov
exponents. Loosely translated, this means
that the elementsof the systemare subject to
both expanding and contracting forces. The
crowd membersdescribed above are subject
to an expandingforce (as they repel one
another to avoid collisions), as well as
contracting force (as they try to moveto
particular location or grouparounda target).
¯ Crowd Dynamics.
The movementof crowds of people forms
an importantaspect of Kaosand it is here
that the concept of achieving complex
behaviour from simple dynamics comes into
its own.The streets of the city representedin
Kaosmust contain, at times, a heaving
throng of people, interacting with one
another on an individual basis but also
behaving as a whole in a convincing
manner, replicating howlarge crowdsof
people have been observedto act.
¯
In such a situation, although each crowd
memberis an autonomousagent, it must
take cues for its behaviourfrom the agents
immediately surrounding it. This
methodologyis well knownwithin the AI
communityas a means to produce complex
and organic flocking from a simple rule set.
Eachagent supplies a small repulsive force
to its neighboursin order to prevent
collisions. Coupledwith this are larger lesslocalised forces providingattractions and
repulsions to a crowd,resulting in an ebb
and flow of the mass of the crowd. As an
agent is pushed around by the surrounding
forces, its target position is also pushed
around, preventingit fromstutteringly trying
to achieve the sameposition, or relative
position, time after time. This has resulted in
a crowdwhichappears to jostle internally as
individual membersseem to push and shove
in various directions. This is especially
effective whena newelo~nent is integrated
into the crowd, or whenthe crowdis moved
into a moreconfined space.
Police Tactics
All of the above aspects of the AI code
cometogether in the control of the police
behaviour within the gamemap. The police
characters in Kaos must function
individually and as part of a larger group or
over-all tactic. Individual police characters
use scripting commandsand embeddedAI
information in the same way as other NPCs
within the game.The grid structure further
provides a quick wayfor a police character
to assess the current situation, checkinghow
manyof his fellow officers are in the
immediatevicinity, howmuchof a threat is
being presented, and howvulnerable local
property and objects maybe. This
information is processed on an individual
level, for a particular police character’s
immediateactions, and at a higher level to
provide grouping together of police NPCs
and teamwork. This once more demonstrates
a two-tier approachto the AI functionalityand is again implementedthrough a simple
inter-linked rule set. This simpleset of rules
leads to a very diverse behaviourby the
police characters, dependingon the actions,
both recent and long-term, of the player
character and other NPCs.
Ontop of this jostling dynamicis a dynamic
with a longer term goal, such as movingthe
crowdalong a street, or through a narrow
gap. It has been foundthat increasing the
amountof dampingand lag on this higherlevel dynamicin howit affects individual
agents, can greatly changethe over-all feel
of the movement.Examplesrange from a
lightly dampedshoal of fish to a muchmore
heavily dampedcrowd of people. This
multi-layered approach to crowddynamics,
coupled with the underlying concept that
No chaos theory has been used in the police
code as such, since they are, by definition,
an element of the gamewhich is tightly
governed by rules and discipline. However,
since they are controlled by a completely
stochastic system, and are in an environment
with chaotic elements, their behaviour and
responsesare highly varied, due to the large
74
numberof situation combinationsthey can
comeinto contact with in a chaotic
environment.
field of chaotic studies mayprovide insights
and resources for the gamingAI community.
References
[ 1] E.Lorenz, The essence of chaos,
UCLPress, 1993.
The Future Of Chaos In GameAI
One element of non-linear dynamicsthat has
not been mentionedso far in this paper is
that of fractai geometry. Manydisplay
engines exist whichare based on a fractal
approach,for creating landscapes,trees, etc.
There may, however, be some mileage in
applying fractals to AI coding in games.One
area of interest maybe in populating an
extensive environment with a range of
character types and character traits. A fractal
mapcould be used to define, for example,
the "anger level" of each character as he is
inserted into the environment.Similarly,
fractal mappingcould be used for embedded
AI properties such as our "smelliness factor"
on a sewer-world.
[2] J.Gleick, Chaos: making a new
science, Cardinal, London, 1987.
[3] M.Feigenbaum,"Qualitative
universality for a class of nonlinear
transformations", Jnl of Statistical Physics,
vol 19, pp 25-52, 1978
[4] T.Y.Li and J.Yorke, "Period three
implies chaos", American Mathematical
Monthly, vol 82, pp 985-92, 1975
[5] R.May, "Simple mathematical
dynamics with very complicated dynamics",
Nature, vol 261, pp 459-67, 1976
[6] D.Ruelle, "Strange Attractors",
MathematicalIntelligencer, vol 2, pp12637, 1980
It is likely that manygamesare already in
existence or developmentwhich include AI
routines providing what could be described
as chaotic behaviour, whetheror not the
developers think of it in those terms. Game
AI coders are constantly striving for
complexbehaviour from simple rules.
[7] B.Mandelbrot, The fractal geometry
of nature, Freeman, NewYork, 1977.
[8] E.N.Lorenz, "deterministic non
periodic flow", Jnl AtmosphericScience, vol
20, pp 130-141, 1963.
Although someaspects of chaos theory have
been incorporated in the game,Kaos, it has
becomeapparent that there are many
possibilities for future developmentin this
area, both in gamesof a similar type to Kaos
and in other genres. A numberof these
possibilities have been discussed throughout
the paper, and manymore will no doubt
occur to the interested reader.
Conclusions
In planning and coding the AI functionality
for Kaos, a numberof parallels have been
drawnwith the tenets and analysis of chaos
theory. In particular, it is apparentthat there
are similarities in the waycomplex
behaviour can arise from simple equations.
It seemslikely that, as the requirementfor
ever more complexcharacter interactions
continues, coupled with the increased
processing powerpresented by successive
generations of gaminghardware, that the
75