Games Chapter 6 Dr. Mustafa Jarrar University of Birzeit [email_address] www.jarrar.info   Lecture Notes,  Advanced Artificial Intelligence (SCOM7341)  University of Birzeit 2 nd  Semester, 2011 Advanced Artificial Intelligence  (SCOM7341)
Can you plan ahead with these games
Game Tree (2-player, deterministic, turns) Calculated by utility function, depends on the game. Last state, game is over
Two-Person Perfect Information Deterministic Game Your Moves My Moves My Moves Your Moves Your Moves My Moves My Moves My Moves Two players take turns making moves Board state fully known, deterministic evaluation of moves One player wins by defeating the other (or else there is a tie) Want a strategy to win, assuming the other person plays as well as possible
Computer Games Playing games can be seen as a  Search Problem Multiplayer games as  multi-agent environments . Agents' goals are in conflict. Mostly  deterministic  and  fully observable  environments. Some games are  not trivial search problems , thus needs AI techniques, e.g. Chess has an average branching factor of 35, and games often go to 50 moves by each player, so the search tree has about  35 100 or 10 154   nodes. Finding  optimal move : choosing a good move with time limits. Heuristic evaluation functions allow us to approximate the true  utility of a state  without doing a complete search.
Minimax Create a utility function Evaluation of board/game state to determine how strong the position of player 1 is. Player 1 wants to maximize the utility function Player 2 wants to minimize the utility function Minimax Tree Generate a new level for each move Levels alternate between “max” (player 1 moves) and “min” (player 2 moves)
Minimax Tree Max Min Max Min
Minimax Tree Evaluation Assign utility values to leaves Sometimes called “board evaluation function” If leaf is a “final” state, assign the maximum or minimum possible utility value (depending on who would win). If leaf is not a “final” state, must use some other heuristic, specific to the game, to evaluate how good/bad the state is at that point
Minimax Tree Max Min Max Min 100 -24 -8 -14 -73 -100 -5 -70 -12 -3 70 4 12 -3 21 28 23 Terminal nodes: values calculated from the utility function,  evaluates how good/bad the state is at this point
Minimax Tree Evaluation For the MAX player Generate the game as  deep as time permits Apply the evaluation function to the leaf states Back-up values At MIN ply assign minimum payoff move At MAX ply assign maximum payoff move At root, MAX chooses the operator that led to the highest payoff
Minimax Tree -24 -8 -14 -73 -100 -5 -70 -12 -3 70 4 12 -3 21 28 23 Max Min Max Min Terminal nodes: values calculated from the utility function
Minimax Tree 100 -24 -8 -14 -73 -100 -5 -70 -12 -3 70 4 12 -3 21 28 23 28 -3 12 70 -3 -73 -14 -8 Max Min Max Min Other nodes: values calculated via minimax algorithm
Minimax Tree 100 -24 -8 -14 -73 -100 -5 -70 -12 -4 70 4 12 -3 21 28 23 21 -3 12 70 -4 -73 -14 -8 -3 -4 -73 Max Min Max Min
Minimax Tree 100 -24 -8 -14 -73 -100 -5 -70 -12 -4 70 4 12 -3 21 28 23 21 -3 12 70 -4 -73 -14 -8 -3 -4 -73 -3 Max Min Max Min
Minimax Tree 100 -24 -8 -14 -73 -100 -5 -70 -12 -4 70 4 12 -3 21 28 23 21 -3 12 70 -4 -73 -14 -8 -3 -4 -73 -3 Max Min Max Min The best next  move for Max
MiniMax Example-2 Terminal nodes: values calculated from the utility function 4 7 9 6 9 8 8 5 6 7 5 2 3 2 5 4 9 3 Max Max Min Min
MiniMax Example-2 Other nodes: values calculated via minimax algorithm 4 7 9 6 9 8 8 5 6 7 5 2 3 2 5 4 9 3 4 7 6 2 6 3 4 5 1 2 5 4 1 2 6 3 4 3 Max Max Min Min
MiniMax Example-2 4 7 9 6 9 8 8 5 6 7 5 2 3 2 5 4 9 3 4 7 6 2 6 3 4 5 1 2 5 4 1 2 6 3 4 3 7 6 5 5 6 4 Max Max Min Min
MiniMax Example-2 4 7 9 6 9 8 8 5 6 7 5 2 3 2 5 4 9 3 4 7 6 2 6 3 4 5 1 2 5 4 1 2 6 3 4 3 7 6 5 5 6 4 5 3 4 Max Max Min Min
MiniMax Example-2 4 7 9 6 9 8 8 5 6 7 5 2 3 2 5 4 9 3 4 7 6 2 6 3 4 5 1 2 5 4 1 2 6 3 4 3 7 6 5 5 6 4 5 3 4 5 Max Max Min Min
MiniMax Example-2 moves by  Max  and countermoves by  Min  Max Max Min Min 4 7 9 6 9 8 8 5 6 7 5 2 3 2 5 4 9 3 4 7 6 2 6 3 4 5 1 2 5 4 1 2 6 3 4 3 7 6 5 5 6 4 5 3 4 5
Properties of minimax Complete?  Yes (if tree is finite) Space complexity?  A complete evaluation takes space  bm (depth-first exploration) For chess, b  ≈  35, m  ≈ 100 for "reasonable" games   exact solution completely infeasible, since it’s too big Instead, we limit the depth based on various factors, including time available. Optimal? Yes (against an optimal opponent) Time complexity? A complete evaluation takes time bm
Pruning the Minimax Tree Since we have limited time available, we want to avoid unnecessary computation in the minimax tree. Pruning: ways of determining that certain branches will not be useful.    Cuts If the current max value is greater than the successor’s min value, don’t explore that min subtree any more.
   Cut Example 100 21 -3 12 70 -4 -73 -14 -3 -4 -3 -73 Max Max Min
   Cut Example Depth first search along path 1 100 21 -3 12 -70 -4 -73 -14 Max Max Min
   Cut Example 21 is minimum so far (second level) Can’t evaluate yet at top level 100 21 -3 12 -70 -4 -73 -14 21 Max Max Min
   Cut Example -3 is minimum so far (second level) -3 is maximum so far (top level) 100 21 -3 12 -70 -4 -73 -14 -3 -3 Max Max Min
   Cut Example 12 is minimum so far (second level) -3 is still maximum (can’t use second node yet) 100 21 -3 12 -70 -4 -73 -14 -3 -3 12 Max Max Min
   Cut Example -70 is now minimum so far (second level) -3 is still maximum (can’t use second node yet) 100 21 -3 12 -70 -4 -73 -14 -3 -3 -70 Max Max Min
   Cut Example Since second level node will never be > -70, it will never be chosen by the previous level We can stop exploring that node 100 21 -3 12 -70 -4 -73 -14 -3 -3 -70 Max Max Min
   Cut Example Evaluation at second level is again -73 100 21 -3 12 -70 -4 -73 -14 -3 -3 -70 -73 Max Max Min
   Cut Example Again, can apply    cut since the second level node will never be > -73, and thus will never be chosen by the previous level 100 21 -3 12 -70 -4 -73 -14 -3 -3 -70 -73 Max Max Min
   Cut Example As a result, we evaluated the Max node without evaluating several of the possible paths 100 21 -3 12 -70 -4 -73 -14 -3 -3 -70 -73 Max Max Min
   Cuts Similar idea to    cuts, but the other way around If the current minimum is less than the successor’s max value, don’t look down that max tree any more
   Cut Example Some subtrees at second level already have values > min from previous, so we can stop evaluating them. 100 21 -3 12 70 -4 73 -14 Min Min Max 21 21 70 73
Alpha-Beta Example 2 we assume a depth-first, left-to-right search as basic strategy the range of the possible values for each node are indicated initially [-∞, +∞] from  Max ’s or  Min ’s perspective these  local  values reflect the values of the sub-trees in that node;  the  global  values    and    are the best overall choices so far for  Max  or  Min [-∞, +∞] [-∞, +∞]  best choice for  Max ?    best choice for  Min ? Max Min
Alpha-Beta Example 2 Max Min [-∞, 7] [-∞, +∞]  best choice for  Max ?    best choice for  Min 7 7
Alpha-Beta Example 2 Max Min [-∞, 6] [-∞, +∞]  best choice for  Max ?    best choice for  Min 6 7 6
Alpha-Beta Example 2 Max Min 5 [5, +∞]  best choice for  Max 5    best choice for  Min 5 7 6 5 Min  obtains the third value from a successor node this is the last value from this sub-tree, and the exact value is known Max  now has a value for its first successor node, but hopes that something better might still come
Alpha-Beta Example 2 Max Min [-∞, 5] [5, +∞]  best choice for  Max 5    best choice for  Min 3 7 6 5 Min continues with the next sub-tree, and gets a better value  Max has a better choice from its perspective, however, and will not consider a move in the sub-tree currently explored by  Min initially [-∞, +∞] [-∞,3] 3
Alpha-Beta Example 2 Max Min [-∞, 5] [5, +∞]  best choice for  Max 5    best choice for  Min 3 7 6 5 Min knows that Max won’t consider a move to this sub-tree, and abandons it this is a case of pruning, indicated by  [-∞,3] 3
Alpha-Beta Example 2 Max Min [-∞, 5] [5, +∞]  best choice for  Max 5    best choice for  Min 3 7 6 5 Min explores the next sub-tree, and finds a value that is worse than the other nodes at this level if Min is not able to find something lower, then Max will choose this branch, so Min must explore more successor nodes [-∞,3] 3 [-∞,6] 6
Alpha-Beta Example 2 Max Min [-∞, 5] [5, +∞]  best choice for  Max 5    best choice for  Min 3 7 6 5 Min is lucky, and finds a value that is the same as the current worst value at this level Max can choose this branch, or the other branch with the same value [-∞,3] 3 [-∞,5] 6 5
Alpha-Beta Example 2 Max Min [-∞, 5] 5  best choice for  Max 5    best choice for  Min 3 7 6 5 Min could continue searching this sub-tree to see if there is a value that is less than the current worst alternative in order to give Max as few choices as possible this depends on the specific implementation Max knows the best value for its sub-tree  [-∞,3] 3 [-∞,5] 6 5
Exercise  max min max min
Exercise (Solution)  max min max min 10 9 14 2 4 10 14 4 10 4 10
 -   Pruning Pruning by these cuts does not affect final result May allow you to go much deeper in tree “ Good” ordering of moves can make this pruning much more efficient Evaluating “best” branch first yields better likelihood of pruning later branches Perfect ordering reduces time to  b m /2  instead of  O(b d ) i.e. doubles the depth you can search to!
 -   Pruning Can store information along an entire  path , not just at most recent levels! Keep along the path:  : best MAX value found on this path  (initialize to most negative utility value)  : best MIN value found on this path  (initialize to most positive utility value)
Pruning at MAX node    is possibly updated by the MAX of successors evaluated so far If the value that would be returned is ever >   , then stop work on this branch If all children are evaluated without pruning, return the MAX of their values
Pruning at MIN node    is possibly updated by the MIN of successors evaluated so far If the value that would be returned is ever <   , then stop work on this branch If all children are evaluated without pruning, return the MIN of their values
Idea of   -   Pruning We know    on this path is 21 So, when we get max=70, we know this will never be used, so we can stop here 100 21 -3 12 70 -4 21 21 70
Why is it called α-β? α is the value of the best (i.e., highest-value) choice found so far at any choice point along the path for  max If  v  is worse than α,  max  will avoid it    prune that branch Define β similarly for  min
Imperfect Decisions Complete search is impractical for most games Alternative: search the tree only to a certain depth Requires a cutoff-test to determine where to stop Replaces the terminal test The nodes at that level effectively become terminal leave nodes Uses a heuristics-based evaluation function to estimate the expected utility of the game from those leave nodes.
Utility Evaluation Function Very game-specific Take into account knowledge about game “ Stupid” utility 1 if player 1 wins -1 if player 0 wins 0 if tie (or unknown) Only works if we can evaluate complete tree But, should form a basis for other evaluations
Utility Evaluation Need to assign a numerical value to the state Could assign a more complex utility value, but then the min/max determination becomes trickier. Typically assign numerical values to lots of individual factors: a = # player 1’s pieces - # player 2’s pieces b = 1 if player 1 has queen and player 2 does not, -1 if the opposite, or 0 if the same c = 2 if player 1 has 2-rook advantage, 1 if a 1-rook advantage, etc.
Utility Evaluation The individual factors are combined by some function Usually a linear weighted combination is used: u =   a +   b +   c Different ways to combine are also possible Notice: quality of utility function is based on: What features are evaluated How those features are scored How the scores are weighted/combined Absolute utility value doesn’t matter – relative value does.
Evaluation Functions If you had a perfect utility evaluation function, what would it mean about the minimax tree? You would never have to evaluate more than one level deep! Typically, you can’t create such perfect utility evaluations, though.
Evaluation Functions for Ordering As mentioned earlier, order of branch evaluation can make a big difference in how well you can prune A good evaluation function might help you order your available moves: Perform one move only Evaluate board at that level Recursively evaluate branches in order from best first move to worst first move (or vice-versa if at a MIN node)
The following are extra Examples (Self Study)
Example: Tic-Tac-Toe  (evaluation function) Simple evaluation function E(s) = (rx + cx + dx) - (ro + co + do) where r,c,d are the numbers of row, column and diagonal lines still available;  x and o are the pieces of the two players. 1-ply lookahead start at the top of the tree evaluate all 9 choices for player 1 pick the maximum E-value 2-ply lookahead also looks at the opponents possible move assuming that the opponents picks the minimum E-value
Tic-Tac-Toe 1-Ply E(s12) 8 - 6 = 2 E(s13) 8 - 5 = 3 E(s14) 8 - 6 = 2 E(s15) 8 - 4 = 4 E(s16) 8 - 6 = 2 E(s17) 8 - 5 = 3 E(s18) 8 - 6 = 2 E(s19) 8 - 5 = 3 X X X X X X X X X E(s11) 8 - 5 = 3 E(s0) = Max{E(s11), E(s1n)} = Max{2,3,4} = 4
Tic-Tac-Toe 2-Ply E(s2:16) 5 - 6 = -1 E(s2:15) 5 -6 = -1 E(s28) 5 - 5 = 0 E(s27) 6 - 5 = 1 E(s2:48) 5 - 4 = 1 E(s2:47) 6 - 4 = 2 E(s2:13) 5 - 6 = -1 E(s2:9) 5 - 6 = -1 E(s2:10) 5 -6 = -1 E(s2:11) 5 - 6 = -1 E(s2:12) 5 - 6 = -1 E(s2:14) 5 - 6 = -1 E(s25) 6 - 5 = 1 E(s21) 6 - 5 = 1 E(s22) 5 - 5 = 0 E(s23) 6 - 5 = 1 E(s24) 4 - 5 = -1 E(s26) 5 - 5 = 0 E(s1:6) 8 - 6 = 2 E(s1:7) 8 - 5 = 3 E(s1:8) 8 - 6 = 2 E(s1:9) 8 - 5 = 3 E(s1:5) 8 - 4 = 4 E(s1:3) 8 - 5 = 3 E(s1:2) 8 - 6 = 2 E(s1:1) 8 - 5 = 3 E(s2:45) 6 - 4 = 2 X X X X X X X X X E(s1:4) 8 - 6 = 2 X O X O X O E(s2:41) 5 - 4 = 1 E(s2:42) 6 - 4 = 2 E(s2:43) 5 - 4 = 1 E(s2:44) 6 - 4 = 2 E(s2:46) 5 - 4 = 1 O X O X O X O X X O X O X O X O X X O X O O X X O X O X O X O X O X O X O X O X O O E(s0) = Max{E(s11), E(s1n)} = Max{2,3,4} = 4
Checkers Case Study 31 Initial board configuration Black   single on 20 single on 21 king on 31 Red single on 23 king on 22 Evaluation function E(s) = (5 x 1  + x 2 ) - (5r 1  + r 2 ) where  x 1  = black king advantage,  x 2  = black single advantage,   r 1  = red king advantage,  r 2  = red single advantage 1 2 3 4 8 6 5 9 10 11 12 16 14 13 17 18 19 20 24 22 21 25 26 27 28 32 30 29 7 15 23
Checkers MiniMax Example 20 -> 16 21 -> 17 31 -> 26 31 -> 27 22 -> 17 22 -> 18 22 -> 25 22 -> 26 23 -> 26 23 -> 27 21 -> 14 16 -> 11 31 -> 27 16 -> 11 31 -> 27 31 -> 27 16 -> 11 31 -> 27 31 -> 24 22 -> 13 22 -> 31 23 -> 30 23 -> 32 20 -> 16 31 -> 27 31 -> 26 21 -> 17 20 -> 16 21 -> 17 20 -> 16 20 -> 16 21 -> 17 MAX MAX MIN 1 1 1 1 1 2 2 6 6 1 1 1 1 1 1 1 1 1 1 1 1 6 6 0 0 0 0 -4 -4 -4 -8 -8 -8 -8 -8 -8 1 0 -8 -8 1 31 1 2 3 4 8 6 5 9 10 11 12 16 14 13 17 18 19 20 24 22 21 25 26 27 28 32 30 29 7 15 23
Checkers Alpha-Beta Example 20 -> 16 21 -> 17 31 -> 26 31 -> 27 22 -> 17 22 -> 18 22 -> 25 22 -> 26 23 -> 26 23 -> 27 21 -> 14 16 -> 11 31 -> 27 16 -> 11 31 -> 27 31 -> 27 16 -> 11 31 -> 27 31 -> 24 22 -> 18 22 -> 31 23 -> 30 23 -> 32 20 -> 16 31 -> 27 31 -> 26 21 -> 17 20 -> 16 21 -> 17 20 -> 16 20 -> 16 21 -> 17 31 1 2 3 4 8 6 5 9 10 11 12 16 14 13 17 18 19 20 24 22 21 25 26 27 28 32 30 29 7 15 23    1     6 MAX MAX MIN 1 1 1 1 1 2 2 6 6 1 1 1 1 1 1 1 1 1 1 1 1 6 6 0 0 0 0 -4 -4 -4 -8 -8 -8 -8 -8 -8 1 0 -4 -8 1
Checkers Alpha-Beta Example 20 -> 16 21 -> 17 31 -> 26 31 -> 27 22 -> 17 22 -> 18 22 -> 25 22 -> 26 23 -> 26 23 -> 27 21 -> 14 16 -> 11 31 -> 27 16 -> 11 31 -> 27 31 -> 27 16 -> 11 31 -> 27 31 -> 24 22 -> 18 22 -> 31 23 -> 30 23 -> 32 20 -> 16 31 -> 27 31 -> 26 21 -> 17 20 -> 16 21 -> 17 20 -> 16 20 -> 16 21 -> 17 31 1 2 3 4 8 6 5 9 10 11 12 16 14 13 17 18 19 20 24 22 21 25 26 27 28 32 30 29 7 15 23    1     1 MAX MAX MIN 1 1 1 1 1 2 2 6 6 1 1 1 1 1 1 1 1 1 1 1 1 6 6 0 0 0 0 -4 -4 -4 -8 -8 -8 -8 -8 -8 1 0 -4 -8 1
Checkers Alpha-Beta Example 20 -> 16 21 -> 17 31 -> 26 31 -> 27 22 -> 17 22 -> 18 22 -> 25 22 -> 26 23 -> 26 23 -> 27 21 -> 14 16 -> 11 31 -> 27 16 -> 11 31 -> 27 31 -> 22 16 -> 11 31 -> 27 31 -> 24 22 -> 18 22 -> 31 23 -> 30 23 -> 32 20 -> 16 31 -> 27 31 -> 26 21 -> 17 20 -> 16 21 -> 17 20 -> 16 20 -> 16 21 -> 17 31 1 2 3 4 8 6 5 9 10 11 12 16 14 13 17 18 19 20 24 22 21 25 26 27 28 32 30 29 7 15 23    1     1  cutoff : no need to examine further branches MAX MAX MIN 1 1 1 1 1 2 2 6 6 1 1 1 1 1 1 1 1 1 1 1 1 6 6 0 0 0 0 -4 -4 -4 -8 -8 -8 -8 -8 -8 1 0 -4 -8 1
Checkers Alpha-Beta Example 1 0 -4 -8 20 -> 16 21 -> 17 31 -> 26 31 -> 27 22 -> 17 22 -> 18 22 -> 25 22 -> 26 23 -> 26 23 -> 27 21 -> 14 16 -> 11 31 -> 27 16 -> 11 31 -> 27 31 -> 22 16 -> 11 31 -> 27 31 -> 24 22 -> 18 22 -> 31 23 -> 30 23 -> 32 20 -> 16 31 -> 27 31 -> 26 21 -> 17 20 -> 16 21 -> 17 20 -> 16 20 -> 16 21 -> 17 31 1 2 3 4 8 6 5 9 10 11 12 16 14 13 17 18 19 20 24 22 21 25 26 27 28 32 30 29 7 15 23    1     1 MAX MAX MIN 1 1 1 1 1 2 2 6 6 1 1 1 1 1 1 1 1 1 1 1 1 6 6 0 0 0 0 -4 -4 -4 -8 -8 -8 -8 -8 -8 1
Checkers Alpha-Beta Example 1 0 -4 -8 20 -> 16 21 -> 17 31 -> 26 31 -> 27 22 -> 17 22 -> 18 22 -> 25 22 -> 26 23 -> 26 23 -> 27 21 -> 14 16 -> 11 31 -> 27 16 -> 11 31 -> 27 31 -> 22 16 -> 11 31 -> 27 31 -> 24 22 -> 18 22 -> 31 23 -> 30 23 -> 32 20 -> 16 31 -> 27 31 -> 26 21 -> 17 20 -> 16 21 -> 17 20 -> 16 20 -> 16 21 -> 17 31 1 2 3 4 8 6 5 9 10 11 12 16 14 13 17 18 19 20 24 22 21 25 26 27 28 32 30 29 7 15 23    1     1  cutoff : no need to examine further branches MAX MAX MIN 1 1 1 1 1 2 2 6 6 1 1 1 1 1 1 1 1 1 1 1 1 6 6 0 0 0 0 -4 -4 -4 -8 -8 -8 -8 -8 -8 1
Checkers Alpha-Beta Example 1 0 -4 -8 20 -> 16 21 -> 17 31 -> 26 31 -> 27 22 -> 17 22 -> 18 22 -> 25 22 -> 26 23 -> 26 23 -> 27 21 -> 14 16 -> 11 31 -> 27 16 -> 11 31 -> 27 31 -> 22 16 -> 11 31 -> 27 31 -> 24 22 -> 18 22 -> 31 23 -> 30 23 -> 32 20 -> 16 31 -> 27 31 -> 26 21 -> 17 20 -> 16 21 -> 17 20 -> 16 20 -> 16 21 -> 17 31 1 2 3 4 8 6 5 9 10 11 12 16 14 13 17 18 19 20 24 22 21 25 26 27 28 32 30 29 7 15 23    1     1 MAX MAX MIN 1 1 1 1 1 2 2 6 6 1 1 1 1 1 1 1 1 1 1 1 1 6 6 0 0 0 0 -4 -4 -4 -8 -8 -8 -8 -8 -8 1
Checkers Alpha-Beta Example 1 0 -4 -8 20 -> 16 21 -> 17 31 -> 26 31 -> 27 22 -> 17 22 -> 18 22 -> 25 22 -> 26 23 -> 26 23 -> 27 21 -> 14 16 -> 11 31 -> 27 16 -> 11 31 -> 27 31 -> 22 16 -> 11 31 -> 27 31 -> 24 22 -> 13 22 -> 31 23 -> 30 23 -> 32 20 -> 16 31 -> 27 31 -> 26 21 -> 17 20 -> 16 21 -> 17 20 -> 16 20 -> 16 21 -> 17 31 1 2 3 4 8 6 5 9 10 11 12 16 14 13 17 18 19 20 24 22 21 25 26 27 28 32 30 29 7 15 23    1     0 MAX MAX MIN 1 1 1 1 1 2 2 6 6 1 1 1 1 1 1 1 1 1 1 1 1 6 6 0 0 0 0 -4 -4 -4 -8 -8 -8 -8 -8 -8 1
Checkers Alpha-Beta Example 1 0 -4 -8 20 -> 16 21 -> 17 31 -> 26 31 -> 27 22 -> 17 22 -> 18 22 -> 25 22 -> 26 23 -> 26 23 -> 27 21 -> 14 16 -> 11 31 -> 27 16 -> 11 31 -> 27 31 -> 22 16 -> 11 31 -> 27 31 -> 24 22 -> 18 22 -> 31 23 -> 30 23 -> 32 20 -> 16 31 -> 27 31 -> 26 21 -> 17 20 -> 16 21 -> 17 20 -> 16 20 -> 16 21 -> 17 31 1 2 3 4 8 6 5 9 10 11 12 16 14 13 17 18 19 20 24 22 21 25 26 27 28 32 30 29 7 15 23    1     -4  cutoff : no need to examine further branches MAX MAX MIN 1 1 1 1 1 2 2 6 6 1 1 1 1 1 1 1 1 1 1 1 1 6 6 0 0 0 0 -4 -4 -4 -8 -8 -8 -8 -8 -8 1
Checkers Alpha-Beta Example 22 -> 31 1 0 -4 -8 20 -> 16 21 -> 17 31 -> 26 31 -> 27 22 -> 17 22 -> 18 22 -> 25 22 -> 26 23 -> 26 23 -> 27 21 -> 14 16 -> 11 31 -> 27 16 -> 11 31 -> 27 31 -> 22 16 -> 11 31 -> 27 31 -> 24 22 -> 18 23 -> 30 23 -> 32 20 -> 16 31 -> 27 31 -> 26 21 -> 17 20 -> 16 21 -> 17 20 -> 16 20 -> 16 21 -> 17 31 1 2 3 4 8 6 5 9 10 11 12 16 14 13 17 18 19 20 24 22 21 25 26 27 28 32 30 29 7 15 23    1     -8 MAX MAX MIN 1 1 1 1 1 2 2 6 6 1 1 1 1 1 1 1 1 1 1 1 1 6 6 0 0 0 0 -4 -4 -4 -8 -8 -8 -8 -8 -8 1

Jarrar.lecture notes.aai.2011s.ch6.games

  • 1.
    Games Chapter 6Dr. Mustafa Jarrar University of Birzeit [email_address] www.jarrar.info Lecture Notes, Advanced Artificial Intelligence (SCOM7341) University of Birzeit 2 nd Semester, 2011 Advanced Artificial Intelligence (SCOM7341)
  • 2.
    Can you planahead with these games
  • 3.
    Game Tree (2-player,deterministic, turns) Calculated by utility function, depends on the game. Last state, game is over
  • 4.
    Two-Person Perfect InformationDeterministic Game Your Moves My Moves My Moves Your Moves Your Moves My Moves My Moves My Moves Two players take turns making moves Board state fully known, deterministic evaluation of moves One player wins by defeating the other (or else there is a tie) Want a strategy to win, assuming the other person plays as well as possible
  • 5.
    Computer Games Playinggames can be seen as a Search Problem Multiplayer games as multi-agent environments . Agents' goals are in conflict. Mostly deterministic and fully observable environments. Some games are not trivial search problems , thus needs AI techniques, e.g. Chess has an average branching factor of 35, and games often go to 50 moves by each player, so the search tree has about 35 100 or 10 154 nodes. Finding optimal move : choosing a good move with time limits. Heuristic evaluation functions allow us to approximate the true utility of a state without doing a complete search.
  • 6.
    Minimax Create autility function Evaluation of board/game state to determine how strong the position of player 1 is. Player 1 wants to maximize the utility function Player 2 wants to minimize the utility function Minimax Tree Generate a new level for each move Levels alternate between “max” (player 1 moves) and “min” (player 2 moves)
  • 7.
    Minimax Tree MaxMin Max Min
  • 8.
    Minimax Tree EvaluationAssign utility values to leaves Sometimes called “board evaluation function” If leaf is a “final” state, assign the maximum or minimum possible utility value (depending on who would win). If leaf is not a “final” state, must use some other heuristic, specific to the game, to evaluate how good/bad the state is at that point
  • 9.
    Minimax Tree MaxMin Max Min 100 -24 -8 -14 -73 -100 -5 -70 -12 -3 70 4 12 -3 21 28 23 Terminal nodes: values calculated from the utility function, evaluates how good/bad the state is at this point
  • 10.
    Minimax Tree EvaluationFor the MAX player Generate the game as deep as time permits Apply the evaluation function to the leaf states Back-up values At MIN ply assign minimum payoff move At MAX ply assign maximum payoff move At root, MAX chooses the operator that led to the highest payoff
  • 11.
    Minimax Tree -24-8 -14 -73 -100 -5 -70 -12 -3 70 4 12 -3 21 28 23 Max Min Max Min Terminal nodes: values calculated from the utility function
  • 12.
    Minimax Tree 100-24 -8 -14 -73 -100 -5 -70 -12 -3 70 4 12 -3 21 28 23 28 -3 12 70 -3 -73 -14 -8 Max Min Max Min Other nodes: values calculated via minimax algorithm
  • 13.
    Minimax Tree 100-24 -8 -14 -73 -100 -5 -70 -12 -4 70 4 12 -3 21 28 23 21 -3 12 70 -4 -73 -14 -8 -3 -4 -73 Max Min Max Min
  • 14.
    Minimax Tree 100-24 -8 -14 -73 -100 -5 -70 -12 -4 70 4 12 -3 21 28 23 21 -3 12 70 -4 -73 -14 -8 -3 -4 -73 -3 Max Min Max Min
  • 15.
    Minimax Tree 100-24 -8 -14 -73 -100 -5 -70 -12 -4 70 4 12 -3 21 28 23 21 -3 12 70 -4 -73 -14 -8 -3 -4 -73 -3 Max Min Max Min The best next move for Max
  • 16.
    MiniMax Example-2 Terminalnodes: values calculated from the utility function 4 7 9 6 9 8 8 5 6 7 5 2 3 2 5 4 9 3 Max Max Min Min
  • 17.
    MiniMax Example-2 Othernodes: values calculated via minimax algorithm 4 7 9 6 9 8 8 5 6 7 5 2 3 2 5 4 9 3 4 7 6 2 6 3 4 5 1 2 5 4 1 2 6 3 4 3 Max Max Min Min
  • 18.
    MiniMax Example-2 47 9 6 9 8 8 5 6 7 5 2 3 2 5 4 9 3 4 7 6 2 6 3 4 5 1 2 5 4 1 2 6 3 4 3 7 6 5 5 6 4 Max Max Min Min
  • 19.
    MiniMax Example-2 47 9 6 9 8 8 5 6 7 5 2 3 2 5 4 9 3 4 7 6 2 6 3 4 5 1 2 5 4 1 2 6 3 4 3 7 6 5 5 6 4 5 3 4 Max Max Min Min
  • 20.
    MiniMax Example-2 47 9 6 9 8 8 5 6 7 5 2 3 2 5 4 9 3 4 7 6 2 6 3 4 5 1 2 5 4 1 2 6 3 4 3 7 6 5 5 6 4 5 3 4 5 Max Max Min Min
  • 21.
    MiniMax Example-2 movesby Max and countermoves by Min Max Max Min Min 4 7 9 6 9 8 8 5 6 7 5 2 3 2 5 4 9 3 4 7 6 2 6 3 4 5 1 2 5 4 1 2 6 3 4 3 7 6 5 5 6 4 5 3 4 5
  • 22.
    Properties of minimaxComplete? Yes (if tree is finite) Space complexity? A complete evaluation takes space bm (depth-first exploration) For chess, b ≈ 35, m ≈ 100 for &quot;reasonable&quot; games  exact solution completely infeasible, since it’s too big Instead, we limit the depth based on various factors, including time available. Optimal? Yes (against an optimal opponent) Time complexity? A complete evaluation takes time bm
  • 23.
    Pruning the MinimaxTree Since we have limited time available, we want to avoid unnecessary computation in the minimax tree. Pruning: ways of determining that certain branches will not be useful.  Cuts If the current max value is greater than the successor’s min value, don’t explore that min subtree any more.
  • 24.
    Cut Example 100 21 -3 12 70 -4 -73 -14 -3 -4 -3 -73 Max Max Min
  • 25.
    Cut Example Depth first search along path 1 100 21 -3 12 -70 -4 -73 -14 Max Max Min
  • 26.
    Cut Example 21 is minimum so far (second level) Can’t evaluate yet at top level 100 21 -3 12 -70 -4 -73 -14 21 Max Max Min
  • 27.
    Cut Example -3 is minimum so far (second level) -3 is maximum so far (top level) 100 21 -3 12 -70 -4 -73 -14 -3 -3 Max Max Min
  • 28.
    Cut Example 12 is minimum so far (second level) -3 is still maximum (can’t use second node yet) 100 21 -3 12 -70 -4 -73 -14 -3 -3 12 Max Max Min
  • 29.
    Cut Example -70 is now minimum so far (second level) -3 is still maximum (can’t use second node yet) 100 21 -3 12 -70 -4 -73 -14 -3 -3 -70 Max Max Min
  • 30.
    Cut Example Since second level node will never be > -70, it will never be chosen by the previous level We can stop exploring that node 100 21 -3 12 -70 -4 -73 -14 -3 -3 -70 Max Max Min
  • 31.
    Cut Example Evaluation at second level is again -73 100 21 -3 12 -70 -4 -73 -14 -3 -3 -70 -73 Max Max Min
  • 32.
    Cut Example Again, can apply  cut since the second level node will never be > -73, and thus will never be chosen by the previous level 100 21 -3 12 -70 -4 -73 -14 -3 -3 -70 -73 Max Max Min
  • 33.
    Cut Example As a result, we evaluated the Max node without evaluating several of the possible paths 100 21 -3 12 -70 -4 -73 -14 -3 -3 -70 -73 Max Max Min
  • 34.
    Cuts Similar idea to  cuts, but the other way around If the current minimum is less than the successor’s max value, don’t look down that max tree any more
  • 35.
    Cut Example Some subtrees at second level already have values > min from previous, so we can stop evaluating them. 100 21 -3 12 70 -4 73 -14 Min Min Max 21 21 70 73
  • 36.
    Alpha-Beta Example 2we assume a depth-first, left-to-right search as basic strategy the range of the possible values for each node are indicated initially [-∞, +∞] from Max ’s or Min ’s perspective these local values reflect the values of the sub-trees in that node; the global values  and  are the best overall choices so far for Max or Min [-∞, +∞] [-∞, +∞]  best choice for Max ?  best choice for Min ? Max Min
  • 37.
    Alpha-Beta Example 2Max Min [-∞, 7] [-∞, +∞]  best choice for Max ?  best choice for Min 7 7
  • 38.
    Alpha-Beta Example 2Max Min [-∞, 6] [-∞, +∞]  best choice for Max ?  best choice for Min 6 7 6
  • 39.
    Alpha-Beta Example 2Max Min 5 [5, +∞]  best choice for Max 5  best choice for Min 5 7 6 5 Min obtains the third value from a successor node this is the last value from this sub-tree, and the exact value is known Max now has a value for its first successor node, but hopes that something better might still come
  • 40.
    Alpha-Beta Example 2Max Min [-∞, 5] [5, +∞]  best choice for Max 5  best choice for Min 3 7 6 5 Min continues with the next sub-tree, and gets a better value Max has a better choice from its perspective, however, and will not consider a move in the sub-tree currently explored by Min initially [-∞, +∞] [-∞,3] 3
  • 41.
    Alpha-Beta Example 2Max Min [-∞, 5] [5, +∞]  best choice for Max 5  best choice for Min 3 7 6 5 Min knows that Max won’t consider a move to this sub-tree, and abandons it this is a case of pruning, indicated by [-∞,3] 3
  • 42.
    Alpha-Beta Example 2Max Min [-∞, 5] [5, +∞]  best choice for Max 5  best choice for Min 3 7 6 5 Min explores the next sub-tree, and finds a value that is worse than the other nodes at this level if Min is not able to find something lower, then Max will choose this branch, so Min must explore more successor nodes [-∞,3] 3 [-∞,6] 6
  • 43.
    Alpha-Beta Example 2Max Min [-∞, 5] [5, +∞]  best choice for Max 5  best choice for Min 3 7 6 5 Min is lucky, and finds a value that is the same as the current worst value at this level Max can choose this branch, or the other branch with the same value [-∞,3] 3 [-∞,5] 6 5
  • 44.
    Alpha-Beta Example 2Max Min [-∞, 5] 5  best choice for Max 5  best choice for Min 3 7 6 5 Min could continue searching this sub-tree to see if there is a value that is less than the current worst alternative in order to give Max as few choices as possible this depends on the specific implementation Max knows the best value for its sub-tree [-∞,3] 3 [-∞,5] 6 5
  • 45.
    Exercise maxmin max min
  • 46.
    Exercise (Solution) max min max min 10 9 14 2 4 10 14 4 10 4 10
  • 47.
     -  Pruning Pruning by these cuts does not affect final result May allow you to go much deeper in tree “ Good” ordering of moves can make this pruning much more efficient Evaluating “best” branch first yields better likelihood of pruning later branches Perfect ordering reduces time to b m /2 instead of O(b d ) i.e. doubles the depth you can search to!
  • 48.
     -  Pruning Can store information along an entire path , not just at most recent levels! Keep along the path:  : best MAX value found on this path (initialize to most negative utility value)  : best MIN value found on this path (initialize to most positive utility value)
  • 49.
    Pruning at MAXnode  is possibly updated by the MAX of successors evaluated so far If the value that would be returned is ever >  , then stop work on this branch If all children are evaluated without pruning, return the MAX of their values
  • 50.
    Pruning at MINnode  is possibly updated by the MIN of successors evaluated so far If the value that would be returned is ever <  , then stop work on this branch If all children are evaluated without pruning, return the MIN of their values
  • 51.
    Idea of  -  Pruning We know  on this path is 21 So, when we get max=70, we know this will never be used, so we can stop here 100 21 -3 12 70 -4 21 21 70
  • 52.
    Why is itcalled α-β? α is the value of the best (i.e., highest-value) choice found so far at any choice point along the path for max If v is worse than α, max will avoid it  prune that branch Define β similarly for min
  • 53.
    Imperfect Decisions Completesearch is impractical for most games Alternative: search the tree only to a certain depth Requires a cutoff-test to determine where to stop Replaces the terminal test The nodes at that level effectively become terminal leave nodes Uses a heuristics-based evaluation function to estimate the expected utility of the game from those leave nodes.
  • 54.
    Utility Evaluation FunctionVery game-specific Take into account knowledge about game “ Stupid” utility 1 if player 1 wins -1 if player 0 wins 0 if tie (or unknown) Only works if we can evaluate complete tree But, should form a basis for other evaluations
  • 55.
    Utility Evaluation Needto assign a numerical value to the state Could assign a more complex utility value, but then the min/max determination becomes trickier. Typically assign numerical values to lots of individual factors: a = # player 1’s pieces - # player 2’s pieces b = 1 if player 1 has queen and player 2 does not, -1 if the opposite, or 0 if the same c = 2 if player 1 has 2-rook advantage, 1 if a 1-rook advantage, etc.
  • 56.
    Utility Evaluation Theindividual factors are combined by some function Usually a linear weighted combination is used: u =  a +  b +  c Different ways to combine are also possible Notice: quality of utility function is based on: What features are evaluated How those features are scored How the scores are weighted/combined Absolute utility value doesn’t matter – relative value does.
  • 57.
    Evaluation Functions Ifyou had a perfect utility evaluation function, what would it mean about the minimax tree? You would never have to evaluate more than one level deep! Typically, you can’t create such perfect utility evaluations, though.
  • 58.
    Evaluation Functions forOrdering As mentioned earlier, order of branch evaluation can make a big difference in how well you can prune A good evaluation function might help you order your available moves: Perform one move only Evaluate board at that level Recursively evaluate branches in order from best first move to worst first move (or vice-versa if at a MIN node)
  • 59.
    The following areextra Examples (Self Study)
  • 60.
    Example: Tic-Tac-Toe (evaluation function) Simple evaluation function E(s) = (rx + cx + dx) - (ro + co + do) where r,c,d are the numbers of row, column and diagonal lines still available; x and o are the pieces of the two players. 1-ply lookahead start at the top of the tree evaluate all 9 choices for player 1 pick the maximum E-value 2-ply lookahead also looks at the opponents possible move assuming that the opponents picks the minimum E-value
  • 61.
    Tic-Tac-Toe 1-Ply E(s12)8 - 6 = 2 E(s13) 8 - 5 = 3 E(s14) 8 - 6 = 2 E(s15) 8 - 4 = 4 E(s16) 8 - 6 = 2 E(s17) 8 - 5 = 3 E(s18) 8 - 6 = 2 E(s19) 8 - 5 = 3 X X X X X X X X X E(s11) 8 - 5 = 3 E(s0) = Max{E(s11), E(s1n)} = Max{2,3,4} = 4
  • 62.
    Tic-Tac-Toe 2-Ply E(s2:16)5 - 6 = -1 E(s2:15) 5 -6 = -1 E(s28) 5 - 5 = 0 E(s27) 6 - 5 = 1 E(s2:48) 5 - 4 = 1 E(s2:47) 6 - 4 = 2 E(s2:13) 5 - 6 = -1 E(s2:9) 5 - 6 = -1 E(s2:10) 5 -6 = -1 E(s2:11) 5 - 6 = -1 E(s2:12) 5 - 6 = -1 E(s2:14) 5 - 6 = -1 E(s25) 6 - 5 = 1 E(s21) 6 - 5 = 1 E(s22) 5 - 5 = 0 E(s23) 6 - 5 = 1 E(s24) 4 - 5 = -1 E(s26) 5 - 5 = 0 E(s1:6) 8 - 6 = 2 E(s1:7) 8 - 5 = 3 E(s1:8) 8 - 6 = 2 E(s1:9) 8 - 5 = 3 E(s1:5) 8 - 4 = 4 E(s1:3) 8 - 5 = 3 E(s1:2) 8 - 6 = 2 E(s1:1) 8 - 5 = 3 E(s2:45) 6 - 4 = 2 X X X X X X X X X E(s1:4) 8 - 6 = 2 X O X O X O E(s2:41) 5 - 4 = 1 E(s2:42) 6 - 4 = 2 E(s2:43) 5 - 4 = 1 E(s2:44) 6 - 4 = 2 E(s2:46) 5 - 4 = 1 O X O X O X O X X O X O X O X O X X O X O O X X O X O X O X O X O X O X O X O X O O E(s0) = Max{E(s11), E(s1n)} = Max{2,3,4} = 4
  • 63.
    Checkers Case Study31 Initial board configuration Black single on 20 single on 21 king on 31 Red single on 23 king on 22 Evaluation function E(s) = (5 x 1 + x 2 ) - (5r 1 + r 2 ) where x 1 = black king advantage, x 2 = black single advantage, r 1 = red king advantage, r 2 = red single advantage 1 2 3 4 8 6 5 9 10 11 12 16 14 13 17 18 19 20 24 22 21 25 26 27 28 32 30 29 7 15 23
  • 64.
    Checkers MiniMax Example20 -> 16 21 -> 17 31 -> 26 31 -> 27 22 -> 17 22 -> 18 22 -> 25 22 -> 26 23 -> 26 23 -> 27 21 -> 14 16 -> 11 31 -> 27 16 -> 11 31 -> 27 31 -> 27 16 -> 11 31 -> 27 31 -> 24 22 -> 13 22 -> 31 23 -> 30 23 -> 32 20 -> 16 31 -> 27 31 -> 26 21 -> 17 20 -> 16 21 -> 17 20 -> 16 20 -> 16 21 -> 17 MAX MAX MIN 1 1 1 1 1 2 2 6 6 1 1 1 1 1 1 1 1 1 1 1 1 6 6 0 0 0 0 -4 -4 -4 -8 -8 -8 -8 -8 -8 1 0 -8 -8 1 31 1 2 3 4 8 6 5 9 10 11 12 16 14 13 17 18 19 20 24 22 21 25 26 27 28 32 30 29 7 15 23
  • 65.
    Checkers Alpha-Beta Example20 -> 16 21 -> 17 31 -> 26 31 -> 27 22 -> 17 22 -> 18 22 -> 25 22 -> 26 23 -> 26 23 -> 27 21 -> 14 16 -> 11 31 -> 27 16 -> 11 31 -> 27 31 -> 27 16 -> 11 31 -> 27 31 -> 24 22 -> 18 22 -> 31 23 -> 30 23 -> 32 20 -> 16 31 -> 27 31 -> 26 21 -> 17 20 -> 16 21 -> 17 20 -> 16 20 -> 16 21 -> 17 31 1 2 3 4 8 6 5 9 10 11 12 16 14 13 17 18 19 20 24 22 21 25 26 27 28 32 30 29 7 15 23  1  6 MAX MAX MIN 1 1 1 1 1 2 2 6 6 1 1 1 1 1 1 1 1 1 1 1 1 6 6 0 0 0 0 -4 -4 -4 -8 -8 -8 -8 -8 -8 1 0 -4 -8 1
  • 66.
    Checkers Alpha-Beta Example20 -> 16 21 -> 17 31 -> 26 31 -> 27 22 -> 17 22 -> 18 22 -> 25 22 -> 26 23 -> 26 23 -> 27 21 -> 14 16 -> 11 31 -> 27 16 -> 11 31 -> 27 31 -> 27 16 -> 11 31 -> 27 31 -> 24 22 -> 18 22 -> 31 23 -> 30 23 -> 32 20 -> 16 31 -> 27 31 -> 26 21 -> 17 20 -> 16 21 -> 17 20 -> 16 20 -> 16 21 -> 17 31 1 2 3 4 8 6 5 9 10 11 12 16 14 13 17 18 19 20 24 22 21 25 26 27 28 32 30 29 7 15 23  1  1 MAX MAX MIN 1 1 1 1 1 2 2 6 6 1 1 1 1 1 1 1 1 1 1 1 1 6 6 0 0 0 0 -4 -4 -4 -8 -8 -8 -8 -8 -8 1 0 -4 -8 1
  • 67.
    Checkers Alpha-Beta Example20 -> 16 21 -> 17 31 -> 26 31 -> 27 22 -> 17 22 -> 18 22 -> 25 22 -> 26 23 -> 26 23 -> 27 21 -> 14 16 -> 11 31 -> 27 16 -> 11 31 -> 27 31 -> 22 16 -> 11 31 -> 27 31 -> 24 22 -> 18 22 -> 31 23 -> 30 23 -> 32 20 -> 16 31 -> 27 31 -> 26 21 -> 17 20 -> 16 21 -> 17 20 -> 16 20 -> 16 21 -> 17 31 1 2 3 4 8 6 5 9 10 11 12 16 14 13 17 18 19 20 24 22 21 25 26 27 28 32 30 29 7 15 23  1  1  cutoff : no need to examine further branches MAX MAX MIN 1 1 1 1 1 2 2 6 6 1 1 1 1 1 1 1 1 1 1 1 1 6 6 0 0 0 0 -4 -4 -4 -8 -8 -8 -8 -8 -8 1 0 -4 -8 1
  • 68.
    Checkers Alpha-Beta Example1 0 -4 -8 20 -> 16 21 -> 17 31 -> 26 31 -> 27 22 -> 17 22 -> 18 22 -> 25 22 -> 26 23 -> 26 23 -> 27 21 -> 14 16 -> 11 31 -> 27 16 -> 11 31 -> 27 31 -> 22 16 -> 11 31 -> 27 31 -> 24 22 -> 18 22 -> 31 23 -> 30 23 -> 32 20 -> 16 31 -> 27 31 -> 26 21 -> 17 20 -> 16 21 -> 17 20 -> 16 20 -> 16 21 -> 17 31 1 2 3 4 8 6 5 9 10 11 12 16 14 13 17 18 19 20 24 22 21 25 26 27 28 32 30 29 7 15 23  1  1 MAX MAX MIN 1 1 1 1 1 2 2 6 6 1 1 1 1 1 1 1 1 1 1 1 1 6 6 0 0 0 0 -4 -4 -4 -8 -8 -8 -8 -8 -8 1
  • 69.
    Checkers Alpha-Beta Example1 0 -4 -8 20 -> 16 21 -> 17 31 -> 26 31 -> 27 22 -> 17 22 -> 18 22 -> 25 22 -> 26 23 -> 26 23 -> 27 21 -> 14 16 -> 11 31 -> 27 16 -> 11 31 -> 27 31 -> 22 16 -> 11 31 -> 27 31 -> 24 22 -> 18 22 -> 31 23 -> 30 23 -> 32 20 -> 16 31 -> 27 31 -> 26 21 -> 17 20 -> 16 21 -> 17 20 -> 16 20 -> 16 21 -> 17 31 1 2 3 4 8 6 5 9 10 11 12 16 14 13 17 18 19 20 24 22 21 25 26 27 28 32 30 29 7 15 23  1  1  cutoff : no need to examine further branches MAX MAX MIN 1 1 1 1 1 2 2 6 6 1 1 1 1 1 1 1 1 1 1 1 1 6 6 0 0 0 0 -4 -4 -4 -8 -8 -8 -8 -8 -8 1
  • 70.
    Checkers Alpha-Beta Example1 0 -4 -8 20 -> 16 21 -> 17 31 -> 26 31 -> 27 22 -> 17 22 -> 18 22 -> 25 22 -> 26 23 -> 26 23 -> 27 21 -> 14 16 -> 11 31 -> 27 16 -> 11 31 -> 27 31 -> 22 16 -> 11 31 -> 27 31 -> 24 22 -> 18 22 -> 31 23 -> 30 23 -> 32 20 -> 16 31 -> 27 31 -> 26 21 -> 17 20 -> 16 21 -> 17 20 -> 16 20 -> 16 21 -> 17 31 1 2 3 4 8 6 5 9 10 11 12 16 14 13 17 18 19 20 24 22 21 25 26 27 28 32 30 29 7 15 23  1  1 MAX MAX MIN 1 1 1 1 1 2 2 6 6 1 1 1 1 1 1 1 1 1 1 1 1 6 6 0 0 0 0 -4 -4 -4 -8 -8 -8 -8 -8 -8 1
  • 71.
    Checkers Alpha-Beta Example1 0 -4 -8 20 -> 16 21 -> 17 31 -> 26 31 -> 27 22 -> 17 22 -> 18 22 -> 25 22 -> 26 23 -> 26 23 -> 27 21 -> 14 16 -> 11 31 -> 27 16 -> 11 31 -> 27 31 -> 22 16 -> 11 31 -> 27 31 -> 24 22 -> 13 22 -> 31 23 -> 30 23 -> 32 20 -> 16 31 -> 27 31 -> 26 21 -> 17 20 -> 16 21 -> 17 20 -> 16 20 -> 16 21 -> 17 31 1 2 3 4 8 6 5 9 10 11 12 16 14 13 17 18 19 20 24 22 21 25 26 27 28 32 30 29 7 15 23  1  0 MAX MAX MIN 1 1 1 1 1 2 2 6 6 1 1 1 1 1 1 1 1 1 1 1 1 6 6 0 0 0 0 -4 -4 -4 -8 -8 -8 -8 -8 -8 1
  • 72.
    Checkers Alpha-Beta Example1 0 -4 -8 20 -> 16 21 -> 17 31 -> 26 31 -> 27 22 -> 17 22 -> 18 22 -> 25 22 -> 26 23 -> 26 23 -> 27 21 -> 14 16 -> 11 31 -> 27 16 -> 11 31 -> 27 31 -> 22 16 -> 11 31 -> 27 31 -> 24 22 -> 18 22 -> 31 23 -> 30 23 -> 32 20 -> 16 31 -> 27 31 -> 26 21 -> 17 20 -> 16 21 -> 17 20 -> 16 20 -> 16 21 -> 17 31 1 2 3 4 8 6 5 9 10 11 12 16 14 13 17 18 19 20 24 22 21 25 26 27 28 32 30 29 7 15 23  1  -4  cutoff : no need to examine further branches MAX MAX MIN 1 1 1 1 1 2 2 6 6 1 1 1 1 1 1 1 1 1 1 1 1 6 6 0 0 0 0 -4 -4 -4 -8 -8 -8 -8 -8 -8 1
  • 73.
    Checkers Alpha-Beta Example22 -> 31 1 0 -4 -8 20 -> 16 21 -> 17 31 -> 26 31 -> 27 22 -> 17 22 -> 18 22 -> 25 22 -> 26 23 -> 26 23 -> 27 21 -> 14 16 -> 11 31 -> 27 16 -> 11 31 -> 27 31 -> 22 16 -> 11 31 -> 27 31 -> 24 22 -> 18 23 -> 30 23 -> 32 20 -> 16 31 -> 27 31 -> 26 21 -> 17 20 -> 16 21 -> 17 20 -> 16 20 -> 16 21 -> 17 31 1 2 3 4 8 6 5 9 10 11 12 16 14 13 17 18 19 20 24 22 21 25 26 27 28 32 30 29 7 15 23  1  -8 MAX MAX MIN 1 1 1 1 1 2 2 6 6 1 1 1 1 1 1 1 1 1 1 1 1 6 6 0 0 0 0 -4 -4 -4 -8 -8 -8 -8 -8 -8 1