103 Views

Download Presentation
##### Search Techniques: Minimax

**An Image/Link below is provided (as is) to download presentation**

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -

**Search Techniques: Minimax**Two-ply minimax and one of two possible MAX second moves of tic-tac-toefrom Nilsson (1971). Ch04C / 1**Search Techniques: Minimax**Two-ply minimax applied to X’s move near the end of the game of tic-tac-toefrom Nilsson (1971). Ch04C / 2**Search Techniques: Minimax**• Minimax procedure is impractical because the game tree for any interesting games is extremely large. • If there are a minimum of b options for each player on each turn and the minimum number of moves required to end in a win or a draw is d, then the procedure wil take time proportional to bd. Ch04C / 3**Search Techniques: Alpha-Beta Pruning**Alpha-Beta Pruning • Minimax procedure requires two-pass analysis of the search space: • First to descend to the ply depth and there apply the heuristic • Second to propagate values back up the tree. • Minimax pursues all branches in the space, including many that could be ignored or pruned by a more intelligent algorithm. • If we have an idea that is surely bad, do not take time to see how truly awful it is. • If we know half-way through a calculation that it will succeed or fail, then there is no point doing the rest of it. • For example 1, in programming language if (A > 10 or B < 0) or if(A > 10 and B < 0) statement 1; statement 2; • If first condition is succeed (A > 10 - true) there is no need to bother trying the second condition. • For example 2, in programming language if (A > 10 or B < 0) // no point continuing if the first condition statement 1; // is fails (A > 10 – false) Ch04C / 4**Search Techniques: Alpha-Beta Pruning**• The idea is called alpha-beta principle which uses two parameters, traditionally called alpha and beta, to keep track expectations. • In the special context of games, the alpha-beta principle dictates that, whenever we discover a fact about a given node, we should check what we know about the ancestor nodes. • It may be that no further work is sensible below the parent node. • It may be that the best that we can hope for at the parent node can be revised or determined exactly. • Alpha-beta pruning procedure will increase the efficiency of the minimax procedure. • Search based on a depth-first fashion. • Two values for alpha and beta are created. • Alpha-pruning: If (alpha > beta) then all remaining path on that beta-node can be abandoned. • Beta-pruning: If (beta < alpha) then all remaining path on that alpha-node can be abandoned. Ch04C / 5**Search Techniques: Minimax**Alpha-Beta Pruning Search Algorithm Set N to be the list consisting of the single element, m. Let n be the first node N. If n=m and n has been assigned a value, then exit returning this value. Try to prune n as follows. If n is a max node, let v be the minimum of the values of siblings of n, andube the maximum of the values of siblings of ancestors of n that are minimizing nodes. If v >= u, then you can remove n and its siblings and any successors of n and its siblings form N. If m is a minimizing node, then proceed similarly switching min from max, max for min, and <= for >= Try to prune n as follows. if n can’t be pruned, then if n is a terminal node or we decide not to expand n, assign n the value determined by the evaluation function and back up the value at n. Otherwise, remove n from N, add the successors of n to the front of N, and assign the successors initial values so that maximizing nodes are assigned - and minimizing nodes are assigned +. Return to step 2. Ch04C / 6**Search Techniques: Alpha-Beta Pruning**Example 1: Game tree illustrating Apha-Beta Pruning • Suppose the score of node B has been found. As player 1 will be maximizing his score, then we know that he can get at least a score of 10 without even examining node C. • So the score for node A is at least 10. • Suppose the score of node G has also been found. Player 2 will be minimizing player 1’s score, • So the score for node G can be at most 0. Ch04C / 7**Search Techniques: Alpha-Beta Pruning**• Suppose node H’s score was less than zero (<0). • This would change the score of node C, but node A can still get a score of 10, so is unchanged. • Suppose node H’s score was greater than (or equal to) zero (>=0). • Node C’s score would be unchanged, and hence also node A’s. • The score of node H makes no difference, so that the part of the tree below that node marked X can be completely ignored. • Alpha-Beta Pruning involves keeping track of the at most and at least values, and using these to make savings. • The score at a maximizing node is going to be at least the best score of the successor nodes examined so far ( parameter is used to record it). • The score at a minimizing node is going to be at most the worst score of the successor nodes examined so far ( parameter is used to record it). • If the value of a minimizing node < the value of its parent node then all remaining calculations on that node can be abandoned. The rest of the tree is pruned. • If the value of a maximizing node > the value of its parent node then the rest of the calculations on that node can be abandoned, or the tree pruned. Ch04C / 8**Search Techniques: Alpha-Beta Pruning**Example 2: Game tree illustrating Alpha-Beta Pruning Minimax Procedure Alpha-Beta Pruning Ch04C / 9**Search Techniques: Alpha-Beta Pruning**Example 3: Consider the partially expanded game tree below • If the maximizer choose c, it can do no better than –0.2. • The maximizer will choose b over c no matter what it learns in expanding d. • So the subtree rooted at c can be pruned from the search space since the maximizer can always do better by choosing b. Ch04C / 10**Search Techniques: Alpha-Beta Pruning**Example 4: Consider the partially expanded game tree below • At node g, the minimizer has an option with –0.3. • In this case, there is no need to expand h since the maximizer can always choose b and do better than –0.3. • It may be worthwhile expanding d and f, however, since the c option may yet prove to be better than b option. • The subtree rooted at h can be pruned from the search space since the minimizer already has a choice that is better than the best alternative of the maximizer. Ch04C / 11**- -> 2.0** -> 2.0 - -> 2.0 - -> 2.0 - - -> 2.0 Search Techniques: Alpha-Beta Pruning Example 5: Consider the partially expanded game tree below • To implemet pruning strategy: • It is necessary to keep track of the current best estimated value for a node even though the subtree rooted at that node has only partially been explored. • When we encounter a new node: • If it is a terminal node or we have decided not to expand the tree further, then apply the evaluation function and assign the resulting value to the node. • If it is not a terminal node and we intend to expand it later if it is not pruned, then • If it is a maximizing node, assign it - • If it is a minimizing node, assign it + • When we assign a value to a node using the evaluation function, we then propagate the value up the tree to the ancestors of the node. • This is referred as backing up the value at a node. Ch04C / 12**Search Techniques: Summary**• Properties of depth-first search • Completeness: No. Infinite loops can occur. • Optimality: No. Solution found first may not be the shortestpossible. • Time complexity: O(bm) exponential in the maximum depth of the search tree m • Memory (space) complexity: O(bm) linear in the maximum depth of the search tree m • Properties of breadth-first search • Completeness: Yes.The solution is reached if it exists. • Optimality: Yes, for the shortest path. • Time complexity: 1 + b + b2 + b3 + … + bd = O(bd) exponential in the depth of the solution d • Memory (space) complexity: O(bd) same as time - every node is kept in the memory Ch04C / 13**Search Techniques: Summary**• Search techniques may also be applied to game playing systems, but here you have to take into account what the opponent might do. • The minimax procedure allows you to find the best move, assuming that the opponent will do his best to prevent you winning. • Alpha-Beta pruning improve the minimax algorithm by prune or cut out large parts of the tree. • - value of best (highest value) choice for MAX • - value of best (lowest value) choice for MIN • If at a MIN node and value <= , stop looking, because MAX node will ignore • If at a MAX node and value >= , stop looking because MIN node will ignore. Ch04C / 14**Search Techniques: Alpha-Beta Pruning**Exercise: Figure below shows the game tree • Perform minimax on the game tree shown above. • Perform a left-to-right alpha-beta prune on the game tree above. Perform a right -to- left alpha-beta prune on the game tree above. Discuss why a different pruning occurs. Ch04C / 15