Вы находитесь на странице: 1из 4

Algorithms for Computer Games 2007-09-19

§4 Game Trees Game tree


 perfect information games  all possible plays of two-player, perfect
no hidden information

information games can be represented with a
 two-player, perfect information games
 Noughts and Crosses
game tree
 Chess  nodes: positions (or states)
 Go
 edges: moves
 imperfect information games
 Poker  players: MAX (has the first move) and MIN
Backgammon

 Monopoly
 ply = the length of the path between two nodes
 zero-sum property  MAX has even plies counting from the root node
 one player’s gain equals another player’s loss  MIN has odd plies counting from the root node

Division Nim with seven matches

Problem statement Minimax


Given a node v in a game tree  assumption: players are rational and try to win
 given a game tree, we know the outcome in the leaves
find a winning strategy for MAX (or MIN) from v  assign the leaves to win, draw, or loss (or a numeric value like
+1, 0, –1) according to MAX’s point of view
 at nodes one ply above the leaves, we choose the best
or (equivalently) outcome among the children (which are leaves)
 MAX: win if possible; otherwise, draw if possible; else loss
show that MAX (or MIN) can force a win from v  MIN: loss if possible; otherwise, draw if possible; else win
 recurse through the nodes until in the root

© 2003–2007 Jouni Smed 1


Algorithms for Computer Games 2007-09-19

MAX
–1
Minimax rules
MIN
1. If the node is labelled to MAX, assign it to the –1 –1 –1
maximum value of its children.
MAX
2. If the node is labelled to MIN, assign it to the +1 –1 +1 –1
minimum value of its children.
MIN
+1 –1 +1
 MIN minimizes, MAX maximizes → minimax
MAX
+1 –1

MIN
+1

Rough estimates on running


Analysis
times when d = 5
 simplifying assumptions  suppose expanding a node takes 1 ms
 internal nodes have the same branching factor b
 game tree is searched to a fixed depth d  branching factor b depends on the game
 time consumption is proportional to the number of  Draughts (b ≈ 3): t = 0.243 s
expanded nodes
 Chess (b ≈ 30): t = 6¾ h
 1 — root node (the initial ply)
 b — nodes in the first ply  Go (b ≈ 300): t = 77 a
 b2 — nodes in the second ply  alpha-beta pruning reduces b
 bd — nodes in the dth ply
 overall running time O(b d)

Controlling the search depth Evaluation function


 usually the whole game tree is too large  combination of numerical measurements
→ limit the search depth mi(s, p) of the game state
→ a partial game tree  single measurement: mi(s, p)
→ partial minimax  difference measurement: mi(s, p) − mj (s, q)
 n-move look-ahead strategy  ratio of measurements: m i (s, p) / mj(s, q)

 stop searching after n moves  aggregate the measurements maintaining the


 make the internal nodes (i.e., frontier nodes) leaves zero-sum property
 use an evaluation function to ‘guess’ the outcome

© 2003–2007 Jouni Smed 2


Algorithms for Computer Games 2007-09-19

Example: Noughts and Crosses Examples of the evaluation


 heuristic evaluation function e:
 count the winning lines open to MAX e(•) = 6 – 5 = 1
 subtract the number of winning lines open to MIN
 forced wins
 state is evaluated +∞, if it is a forced win for MAX
e(•) = 4 – 5 = –1
 state is evaluated –∞, if it is forced win for MIN

e(•) = +∞

Drawbacks of partial minimax The deeper the better...?


 horizon effect  assumptions:
 heuristically promising path can lead to an unfavourable  n-move look-ahead
situation  branching factor b, depth d,
 staged search: extend the search on promising nodes  leaves with uniform random distribution
 iterative deepening: increase n until out of memory or time  minimax convergence theorem:
 phase-related search: opening, midgame, end game  n increases → root value converges to f(b, d)
 however, horizon effect cannot be totally eliminated  last player theorem:
 bias  root values from odd and even plies not comparable
 we want to have an estimate of minimax but get a minimax of  minimax pathology theorem:
estimates  n increases → probability of selecting non-optimal move
increases (← uniformity assumption!)
 distortion in the root: odd plies → win, even plies → loss

Alpha-beta pruning Example


 reduce the branching factor of nodes  in a MAX node, α = 4
 alpha value  we know that MAX can make a move which will
 associated with MAX nodes result at least the value 4
 we can omit children whose value is less than or
 represents the worst outcome MAX can achieve
equal to 4
 can never decrease
 in a MIN node, β = 4
 beta value
 we know that MIN can make a move which will result
 associated with MIN nodes at most the value 4
 represents the worst outcome MIN can achieve
 we can omit children whose value is greater than or
 can never increase equal to 4

© 2003–2007 Jouni Smed 3


Algorithms for Computer Games 2007-09-19

Rules of pruning Best-case analysis


1. Prune below any MIN node having a beta value  omit the principal variation
less than or equal to the alpha value of any of  at depth d – 1 optimum pruning: each node
its MAX ancestors. expands one child at depth d
2. Prune below any MAX node having an alpha  at depth d – 2 no pruning: each node expands all
value greater than or equal to the beta value of children at depth d – 1
any of its MIN ancestors  at depth d – 3 optimum pruning
 at depth d – 4 no pruning, etc.
Or, simply put: If α ≥ β, then prune below!  total amount of expanded nodes: Ω(bd/2)

Principal variation search Games of chance


 alpha-beta range should be small  minimax trees assume determistic moves
 limit the range artificially → aspiration search  what about indeterministic events like tossing a coin,
 if search fails, revert to the original range casting a die or shuffling cards?
 if we find a move between α and β, assume we have  chance nodes: *-minimax tree
found a principal variation node  expectiminimax
 search the rest of nodes the assuming they will not produce a  if node v is labelled to CHANCE, multiply the
good move
probability of a child with its expectiminimax value
 if the assumption fails, re-search the node and return the sum over all v’s children
 works well if the principal variation node is likely to get  otherwise, act as in minimax
selected first

© 2003–2007 Jouni Smed 4

Вам также может понравиться