game-playing ais part 2 cis 391 fall 2007. cse 391 - intro to ai 2 games: outline of unit part ii ...
DESCRIPTION
CSE Intro to AI 3 `Don’t play hope chess’: The Minimax Rule Idea: make the move for player MAX which has the most benefit assuming that MIN makes the best move for MIN in response This is computed by a recursive process The backed-up value of each node in the tree is determined by the values of its children For a MAX node, the backed-up value is the maximum of the values of its children (i.e. the best for MAX) For a MIN node, the backed-up value is the minimum of the values of its children (i.e. the best for MIN)TRANSCRIPT
Game-playing AIsPart 2
CIS 391Fall 2007
CSE 391 - Intro to AI 2
Games: Outline of Unit
Part II The Minimax Rule Alpha-Beta Pruning Game-playing AI successes
CSE 391 - Intro to AI 3
`Don’t play hope chess’: The Minimax Rule• Idea: make the move for player MAX which has the most benefit
assuming that MIN makes the best move for MIN in response
• This is computed by a recursive process• The backed-up value of each node in the tree is determined by
the values of its children• For a MAX node, the backed-up value is the maximum of the
values of its children (i.e. the best for MAX)• For a MIN node, the backed-up value is the minimum of the
values of its children (i.e. the best for MIN)
CSE 391 - Intro to AI 4
The Minimax Procedure1. Start with the current position as a MAX node.
2. Expand the game tree a fixed number of ply (half-moves).
3. Apply the evaluation function to the leaf positions.
4. Calculate back-up up values bottom-up.
5. Pick the move which was chosen to give the MAX value at the root.
CSE 391 - Intro to AI 5
2-ply Minimax Example
2 7 1 8
MAXMIN
2 7 1 8
2 1
2 7 1 8
2 1
2This is the moveselected by minimaxEvaluation function
value
2 7 1 8
2 1
2
CSE 391 - Intro to AI 6
What if MIN does not play optimally?
Definition of optimal play for MAX assumes MIN plays optimally: • maximizes worst-case outcome for MAX.
But if MIN does not play optimally, MAX will do even better. [Theorem-not hard to prove]
CSE 391 - Intro to AI 7
Minimax Algorithmfunction MINIMAX-DECISION(state) returns an action inputs: state, current state in game vMAX-VALUE(state) return the action in SUCCESSORS(state) with value v
function MIN-VALUE(state) returns a utility value if TERMINAL-TEST(state) then return UTILITY(state) v ∞ for a,s in SUCCESSORS(state) do v MIN(v, MAX-VALUE(s) ) return v
function MAX-VALUE(state) returns a utility value if TERMINAL-TEST(state) then return UTILITY(state) v -∞ for a,s in SUCCESSORS(state) do v MAX(v, MIN-VALUE(s) ) return v
CSE 391 - Intro to AI 8
Comments on Minimax Search Depth-first search with fixed number of ply as the limit.
• O(bm) time complexity – Ooops!• O(bm) space complexity
Performance will depend on • the quality of the evaluation function (expert knowledge)• depth of search (computing power and search algorithm)
Differences from normal state space search• Looking for one move only• No cost on arcs• MAX can’t be sure how MIN will respond to his moves
Minimax rule forms the basis for other game tree search algorithms.
Alpha-Beta Pruning
Slides of example from screenshots byMikael Bodén, Halmstad University, Swedenfound at http://www.emunix.emich.edu/~evett/AI/AlphaBeta_movie/sld001.htm
CSE 391 - Intro to AI 10
Alpha-Beta Pruning A way to improve the performance of the Minimax
Procedure Basic idea: “If you have an idea which is surely
bad, don’t take the time to see how truly awful it is” ~ Pat Winston
2 7 1
=2
>=2
<=1
?
• We don’t need to compute the value at this node.
• No matter what it is it can’t effect the value of the root node.
CSE 391 - Intro to AI 11
The algorithm maintains two values, alpha and beta, which represent the minimum score that the maximizing player is assured of and the maximum score that the minimizing player is assured of respectively. Initially alpha is negative infinity and beta is positive infinity. As the recursion progresses the "window" becomes smaller. When beta becomes less than alpha, it means that the current position cannot be the result of best play by both players and hence need not be explored further.
CSE 391 - Intro to AI 12
An alpha value is an initial or temporary value associated with a MAX node. Because MAX nodes are given the maximum value among their children, an alpha value can never decrease; it can only go up. A beta value is an initial or temporary value associated with a MIN node. Because MIN nodes are given the minimum value among their children, a beta value can never increase; it can only go down.
CSE 391 - Intro to AI 13
http://www.maths.nottingham.ac.uk/personal/anw/G13GAM/alphabet.html
CSE 391 - Intro to AI 14
Alpha-Beta Pruning Traverse the search tree in depth-first order For each MAX node n, α(n)=maximum child value found so
far• Starts with –• Increases if a child returns a value greater than the current α(n)• Lower-bound on the final value
For each MIN node n, β(n)=minimum child value found so far• Starts with +• Decreases if a child returns a value less than the current β(n)• Upper-bound on the final value
MAX cutoff rule: At a MAX node n, cut off search if α(n)>=β(n)
MIN cutoff rule: At a MIN node n, cut off search if β(n)<=α(n) Carry α and β values down in search
CSE 391 - Intro to AI 15
CSE 391 - Intro to AI 16
CSE 391 - Intro to AI 17
CSE 391 - Intro to AI 18
CSE 391 - Intro to AI 19
CSE 391 - Intro to AI 20
CSE 391 - Intro to AI 21
CSE 391 - Intro to AI 22
CSE 391 - Intro to AI 23
CSE 391 - Intro to AI 24
CSE 391 - Intro to AI 25
CSE 391 - Intro to AI 26
CSE 391 - Intro to AI 27
CSE 391 - Intro to AI 28
CSE 391 - Intro to AI 29
CSE 391 - Intro to AI 30
CSE 391 - Intro to AI 31
CSE 391 - Intro to AI 32
CSE 391 - Intro to AI 33
Alpha-Beta Algorithm I
function ALPHA-BETA-SEARCH(state) returns an action inputs: state, current state in game vMAX-VALUE(state, - ∞ , +∞) return the action in SUCCESSORS(state) with value v
function MAX-VALUE(state, , ) returns a utility value if TERMINAL-TEST(state) then return UTILITY(state) v - ∞ for a,s in SUCCESSORS(state) do v MAX(v,MIN-VALUE(s, , )) if v ≥ then return v MAX( ,v) return v
CSE 391 - Intro to AI 34
Alpha-Beta Algorithm II
function MIN-VALUE(state, , ) returns a utility value if TERMINAL-TEST(state) then return UTILITY(state) v + ∞ for a,s in SUCCESSORS(state) do v MIN(v,MAX-VALUE(s, , )) if v ≤ then return v MIN( ,v) return v
CSE 391 - Intro to AI 35
Effectiveness of Alpha-Beta Pruning Guaranteed to compute same root value as
Minimax Worst case: no pruning, same as Minimax (O(bd)) Best case: when each player’s best move is the
first option examined, you examine only O(bd/2) nodes, allowing you to search twice as deep!
For Deep Blue, alpha-beta pruning reduced the average branching factor from 35-40 to 6.
CSE 391 - Intro to AI 36
Chinook and Deep Blue Chinook
• the World Man-Made Checkers Champion, developed at the University of Alberta.• Competed in human tournaments, earning the right to play for the human world
championship, and defeated the best players in the world.• Play Chinook at http://www.cs.ualberta.ca/~chinook
Deep Blue• Defeated world champion Gary Kasparov 3.5-2.5 in 1997 after losing 4-2 in 1996.• Uses a parallel array of 256 special chess-specific processors• Evaluates 200 billion moves every 3 minutes; 12-ply search depth• Expert knowledge from an international grandmaster.• 8000 factor evaluation function tuned from hundreds of thousands of grandmaster
games• Tends to play for tiny positional advantages.