Game AI Introduction
Game AI Introduction
6 18 -2
8 2 -100 25 18 12
210 18
8 5 -98 22
210 18
8 5 -98 22
18
5 -98
210 18
8 5 -98 22
Extensions:
When see power-ups during wandering, collect them.
Execution Flow of an AI Engine
Sense
Finite-state machines
G Decision trees
A
Neural nets
M Think ?
Fuzzy logic
E
Rule-based systems
Planning systems
Act
Conflicting Goals for
AI in Games
Goal Reactive
Driven
Human
Knowledge
Characteristics
Intensive
Complexity of Execution
How fast does it run as more knowledge is added?
How much memory is required as more knowledge is added?
Complexity of Specification
How hard is it to write the code?
As more knowledge is added, how much more code needs
to be added?
Expressiveness of Specification
What can easily be written?
Propositional:
Statements about specific objects in the world no
variables
Jim is in room7, Jim has the rocket launcher, the rocket
launcher does splash damage.
Go to room8 if you are in room7 through door14.
Predicate Logic:
Allows general statement using variables
All rooms have doors
All splash damage weapons can be used around corners
All rocket launchers do splash damage
Go to a room connected to the current room.
Example FSM
Attack Events:
E, -D
E=Enemy Seen
E S=Sound Heard
E
-E D=Die
E D
Wander Chase
-E, -S, -D S
S, -E, -D
-S
D D
-E
S
Code
Spawn
D
Action (callback) performed when a transition occurs
Example FSM
Attack Events:
E, -D
E=Enemy Seen
E S=Sound Heard
E
-E D=Die
E D
Wander Chase
-E, -S, -D S
S, -E, -D
-S
D D
-E
S
Problem: No transition
Spawn from attack to chase
D
Example FSM - Better
S
Events:
Attack Attack-S
E, -D, -S E, -D, S E=Enemy Seen
-S
-E
S=Sound Heard
E D E
D=Die
-E
E D
Wander Chase
-E, -S, -D S
S, -E, -D
-S
D D
-E
S
Spawn
D
Example FSM with Retreat
S Attack-ES
Retreat-S
Attack-E E,-D,S,-L
L -E,-D,S,L
E,-D,-S,-L -S
L -L E Events:
-E
E E -L
-L
E=Enemy Seen
Wander-L Retreat-ES
-E,-D,-S,L E L E,-D,S,L S=Sound Heard
-S
-L D=Die
L S
Retreat-E L=Low Health
Wander -E -E E E,-D,-S,L
-E,-D,-S,-L
D D Each feature
D D Chase with N values
-E,-D,S,-L
Spawn can require N
D S
times as many
(-E,-S,-L)
states
Hierarchical FSM
Expand a state into its own FSM
Attack
Wander E/-E
Pick-up
Powerup
S/-S Chase
Start
Turn Right
Go-through
Door
Die
Spawn
Non-Deterministic Hierarchical
FSM (Markov Model)
No enemy Wander
Attack
Approach
.3
Aim &
.3
Slide Right
& Shoot .3 Start
.4 .3
Aim &
.4
Slide Left
Aim &
& Shoot
Jump &
Shoot Die
Start
Implementation
Compile into an array of state-name, event event
state-name := array[state-name, event]
state
Uses state-name to call execution logic
Add buffers to queue up events in case get
simultaneous events
Hierarchical
Create array for every FSM
Have stack of states
Classify events according to stack
Update state which is sensitive to current event
FSM Evaluation
Advantages:
Very fast one array access
Can be compiled into compact data structure
Dynamic memory: current state
Static memory: state diagram array implementation
Can create tools so non-programmer can build behavior
Non-deterministic FSM can make behavior unpredictable
Disadvantages:
Number of states can grow very fast
Exponentially with number of events: s=2e
Number of arcs can grow even faster: a=s2
Propositional representation
Difficult to put in pick up the better powerup, attack the
closest enemy
References
Web references:
www.gamasutra.com/features/19970601/build_brains_into_games.
htm
csr.uvic.ca/~mmania/machines/intro.htm
www.erlang/se/documentation/doc-
4.7.3/doc/design_principles/fsm.html
www.microconsultants.com/tips/fsm/fsmartcl.htm
Deloura, Game Programming Gems, Charles
River Media, 2000, Section 3.0 & 3.1, pp. 221-
248.