observe δ is typically implemented using look-up tables, e.g.. HR. Hr hr. aD. oD guard charge error error die guard charge charge attack retreat die guard attack.
Game AI Prof. Christian Bauckhage
outline lecture 16 recap reactive behavior programing reduction of DFAs composition of DFAs non-deterministic FAs probabilistic FAs summary
recap hierarchy of behaviors strategic long term goals
tactical mid term goals
resources
contextual / world knowledge
information
reasoning / planning
reactive short term goals
computation time
deterministic finite state machine / automaton
⇔ a tuple A = S, Σ, δ, s0 , F
where S ≡ finite set of states Σ ≡ alphabet of input symbols δ : S × Σ → S ≡ state transition function s0 ∈ S ≡ initial state F ⊆ S ≡ set of final states
example: behavior of a guardian
S = guard, charge, attack, retreat, flee, die, celebrate F = die s0 = guard die
guard
charge
attack
celebrate
retreat
flee
example: behavior of a guardian
Σ = HR, Hr, hr, aD, oD where H : agent’s health > 20% h : agent’s health < 20% R : opponent in view r : opponent in range aD : agent is dead oD : opponent is dead
note
symbols in Σ reflect current game entity attributes i.e. aspects of the current overall game state ⇔ we assume that there is a function that generates symbols from game states
example: behavior of a guardian
δ:S×Σ→S
aD aD oD
HR oD
charge
aD
HR
attack Hr
HR
HR
hr
Hr R H
guard
die
Hr
oD
hr
Hr
celebrate aD
oD
oD
retreat
flee
hr
hr
aD
observe
δ is typically implemented using look-up tables, e.g.
guard charge attack .. .
HR charge charge charge .. .
Hr error attack attack .. .
hr error retreat flee .. .
aD die die die .. .
oD guard guard celebrate .. .
note
in the context of game AI, state machines actually produce output for each state there are scripts that update NPC attributes, render animations, etc. ⇒ we should better talk about finite state transducers
reactive behavior programing
observe
DFAs for real games may become very large and complex ⇒ we might want to minimize DFAs
observe
DFAs for real games may become very large and complex ⇒ we might want to minimize DFAs
in fact, for every DFA, there exists a unique minimal DFA
observe
DFAs for real games may become very large and complex ⇒ we might want to minimize DFAs
in fact, for every DFA, there exists a unique minimal DFA two classes of states can always be removed / merged unreachable states indistinguishable / equivalent states
notation
Σ∗ ≡ set of all words over Σ ∈ Σ ≡ empty character w = x : xs ∈ Σ∗ ≡ word where x ∈ Σ, xs ∈ Σ∗ δ∗ : S × Σ∗ → S ≡ transition function such that δ(s, x), if xs = ∗ δ (s, x : xs) = ∗ δ δ(s, x), xs , otherwise
unreachable state ⇔ state si is unreachable, if there is no word w ∈ Σ∗ such that si = δ∗ (s0 , w) a
s1 a
s0
b b
s2 a
s3
c
s4
equivalent states ⇔ two states si and sj are equivalent si ∼ sj , if ∀ w ∈ Σ∗ : δ∗ (si , w) ∈ F ⇔ δ∗ (sj , w) ∈ F
equivalent states ⇔ two states si and sj are equivalent si ∼ sj , if ∀ w ∈ Σ∗ : δ∗ (si , w) ∈ F ⇔ δ∗ (sj , w) ∈ F
⇔ the machine does the same when started in either state
example
aD
aD
aD
aD oD
HR
guard
oD
charge
die
Hr aD
HR
guard
attack Hr
HR
oD
HR oD
charge
attack
hr
Hr
celebrate aD
oD
hr
⇔ oD
retreat
flee
hr
hr
Hr
Hr R H
HR
celebrate
retreat aD hr
oD
oD hr
HR hr
aD
Hr
HR
oD
die
Hr HR
aD
note
there are efficient algorithms O n log n , n = |S| to identify equivalent states (Hopcroft, 1971) ⇒ DFA / FSM minimization is solved and allows for optimization of behavior programs
observe
more comprehensive behaviors may be realized by combining simple DFAs into more complex ones typical compositions include . . .
cascaded composition
A1
A2
parallel composition
A1
A2
feedback composition
A
observe
there are numerous ideas of how to generalize the idea of DFAs / DFSMs an important one is the following . . .
non-deterministic automaton / state machine (NFA / NFSM) ⇔ a FSM where δ is replaced by ∆ : S × Σ → 2S ⇔ when observing a symbol x in state s, the machine may transit to one out of several states charge a
guard a
retreat
note
“one can show” that NFAs are equivalent to DFAs
probabilistic automaton / state machine ⇔ a generalization of NFSMs
note
instead of a function ∆ : S × Σ → 2S
we may think of a relation ∆⊆S×Σ×S
example function ∆(s1 , a) = {s2 , s3 }
relation ∆ = (s1 , a, s2 ), (s1 , a, s3 ),
∆(s1 , b) = {s1 , s2 , s3 }
(s1 , b, s1 ), (s1 , b, s2 ), (s1 , b, s3 ),
∆(s2 , a) = {s2 , s3 , s4 } .. .
(s2 , a, s2 ), (ss , a, s3 ), (s3 , a, s4 ), . . .
note
instead of a relation ∆⊆S×Σ×S we may think of an indicator function τ : S × Σ × S → 0, 1 where τ s, x, s
0
=
1, if s, x, s 0 ∈ ∆ 0, otherwise
note
for every x ∈ Σ, we may define a (transition) matrix Mx s 0 s = τ s, x, s 0 ∈ 0, 1
note
for every x ∈ Σ, we may define a (transition) matrix Mx s 0 s = τ s, x, s 0 ∈ 0, 1
we may replace Mx by a column stochastic matrix Px where X Px s 0 s ∈ 0, 1 and Px s 0 s = 1 s0
observe
states of a probabilistic automaton are stochastic vectors v where X vs ∈ 0, 1 and vs = 1 s
observe
states of a probabilistic automaton are stochastic vectors v where X vs ∈ 0, 1 and vs = 1 s
for instance, when starting in state v and seeing symbols a, b, c, the automaton will be in state v 0 = Pc Pb Pa v
note
PFAs ⇔ inhomogeneous discrete time Markov chains
summary
we now know about
reduction and composition of DFAs non-deterministic FAs probabilistic FAs