CS335 Introduction To AI: Francisco Iacobelli June 25, 2015
CS335 Introduction To AI: Francisco Iacobelli June 25, 2015
Francisco Iacobelli
June 25, 2015
Games
Competitive and Perfect Information
S0 //initial state
player(s) // who’s the player in state s
actions(s) // possible moves from state s
result(s,a) // the state after action a is taken on state s
terminal(s) // returns true if s is a terminal state
utility(s,p) // the objective function in state s for player p
Optimal Decisions
Optimal Players
4 = MAX ; 5 = MIN
Minimax
Picking my best move against your best move
minimax(s) =
utility (s) if terminal(s)
maxa∈action(s) minimax(result(s, a)) if player (s) = MAX
mina∈action(s) minimax(result(s, a)) if player (s) = MIN
Minimax
Example
minimax(s) =
utility (s) if terminal(s)
maxa∈action(s) minimax(result(s, a)) if player (s) = MAX
mina∈action(s) minimax(result(s, a)) if player (s) = MIN
Minimax Algorithm
Recursive
function Minimax(state)
v = max-value(state)
return action in successors(state) with value v
//
function max-value(state)
if terminal(s)
return utility(s)
v = -infinity
for a,s in successors(state) do
v = max(v,min-value(s))
return v
//
function min-value(state)
if terminal(state)
return utility(s)
v = +infinity
for a,s in successors(state) do
v = min(v,max-value(s))
return v
Minimax
Discussion
Do we need z?
Alpha–Beta prunning
Two values:
I α = value of best choice so far for MAX (highest-value)
I β = value of best choice so far for MIN (lowest-value)
I Each node keeps track of its [α, β] values
Alpha Beta prunning
Example
A α = −∞ β = +∞
B C D
3
Alpha Beta prunning
Example
A α = −∞ β = +∞
B C D
3 ≤ α?.. continue
Alpha Beta prunning
Example
A α = −∞ β = 3
B C D
3 ≤ β?
Alpha Beta prunning
Example
A α = −∞ β = 3
B C D
3 12 ≤ α?
Alpha Beta prunning
Example
A α = −∞ β = 3
B C D
3 12 ≤ β?
Alpha Beta prunning
Example
A α = −∞ β = 3
B C D
3 12 8 ≤ α, β?
Alpha Beta prunning
Example
A α = −∞ β = 3
3 B C D
3 12 8
Alpha Beta prunning
Example
A α = −∞ β = 3
3 ≥ α? B C D
3 12 8
Alpha Beta prunning
Example
A α=3β=3
3 B C D
3 12 8
Alpha Beta prunning
Example
A α=3β=3
3 B C D
3 12 8 2 ≤ α?
Alpha Beta prunning
Example
A α=3β=3
3 B 2 ≥ α? C D
3 12 8 2
Alpha Beta prunning
Example
A α=3β=3
3 B 2 C D
3 12 8 2 14 ≤ α?
Alpha Beta prunning
Example
A α=3β=3
3 B 2 C D
3 12 8 2 14 ≤ β?
Alpha Beta prunning
Example
A α=3β=3
3 B 2 C D
3 12 8 2 14 5 ≤ α?
Alpha Beta prunning
Example
A α=3β=3
3 B 2 C D
3 12 8 2 14 5 ≤ β?
Alpha Beta prunning
Example
A α=3β=3
3 B 2 C 2 D
3 12 8 2 14 5 2 ≤ α?
Alpha Beta prunning
Example
3 A α=3β=3
3 B 2 C 2 D
3 12 8 2 14 5 2
Alpha-Beta Prunning
Algorithm
function alpha-beta(state)
v = max-value(state,−∞,+∞)
return action in successors(state) with value v
//
function max-value(state,α,β)
if terminal(s)
return utility(s)
v = -infinity
for a in action(state) do
v = max(v,min-value(result(s,a),α,β))
if v >= β return v
α = max(α,v)
return v
//
function min-value(state,α,β)
if terminal(state)
return utility(s)
v = +infinity
for a in action(state) do
v = min(v,max-value(result(s,a),α,β))
if v<= α return v
β = min(β,v)
return v
Alpha-Beta Prunning
Properties
h − minimax(s, d) =
eval(s) if cutoff (s)
maxa∈action(s) h − minimax(result(s, a), d + 1) if player (s) = MAX
mina∈action(s) h − minimax(result(s, a), d + 1) if player (s) = MIN
Heuristics
Good Evaluation Functions
1
w=win,d=draw,l=lose
Heuristics
Combination of Features
n
X
eval(s) = w1 f1 (s) + w2 f2 (s) + . . . + wn fn (s) = wi fi (s)
i=1
What are good features and weights, say for chess? for
checkers?
Heuristics
linearity and the independence assumption
I fixed d
I iterative deepening on d
I if s is terminal, cutoff (s) returns true
I add quiescence search or vanilla states
I try and prevent horizon effect or inevitable consequences
Stochastic Games
Chance plays a part
expectiminimax(s) =
utility (s) if terminal(s)
maxa∈action(s) expectiminimax(result(s, a)) if player (s) = Max
min
P a∈action(s) expectiminimax(result(s, a)) if player (s) = Min
r P(r )expectiminimax(result(s, r )) if player (s) = Chance
Playing Games
Complexity
2
Togelius,Shaker,Karakovskiy and Yannakakis (2013)
Playing Games
Current Status