Presentation is loading. Please wait.

Presentation is loading. Please wait.

October 3, 2012Introduction to Artificial Intelligence Lecture 9: Two-Player Games 1 Iterative Deepening A* Algorithm A* has memory demands that increase.

Similar presentations


Presentation on theme: "October 3, 2012Introduction to Artificial Intelligence Lecture 9: Two-Player Games 1 Iterative Deepening A* Algorithm A* has memory demands that increase."— Presentation transcript:

1 October 3, 2012Introduction to Artificial Intelligence Lecture 9: Two-Player Games 1 Iterative Deepening A* Algorithm A* has memory demands that increase exponentially with the depth of the goal node (unless our estimations are perfect). You remember that we improved the space efficiency of the breadth-first search algorithm by applying iterative deepening. Can we do a similar thing for the Algorithm A* ? Sure!

2 October 3, 2012Introduction to Artificial Intelligence Lecture 9: Two-Player Games 2 Iterative Deepening A* In the first iteration, we determine a “cost cut-off” f’(n 0 ) = g’(n 0 ) + h’(n 0 ) = h’(n 0 ), where n 0 is the start node.In the first iteration, we determine a “cost cut-off” f’(n 0 ) = g’(n 0 ) + h’(n 0 ) = h’(n 0 ), where n 0 is the start node. We expand nodes using the depth-first algorithm and backtrack whenever f’(n) for an expanded node n exceeds the cut-off value.We expand nodes using the depth-first algorithm and backtrack whenever f’(n) for an expanded node n exceeds the cut-off value. If this search does not succeed, determine the lowest f’-value among the nodes that were visited but not expanded.If this search does not succeed, determine the lowest f’-value among the nodes that were visited but not expanded. Use this f’-value as the new cut-off value and do another depth-first search.Use this f’-value as the new cut-off value and do another depth-first search. Repeat this procedure until a goal node is found.Repeat this procedure until a goal node is found.

3 October 3, 2012Introduction to Artificial Intelligence Lecture 9: Two-Player Games 3 Let us now investigate… Two-Player Games

4 October 3, 2012Introduction to Artificial Intelligence Lecture 9: Two-Player Games 4 Two-Player Games with Complete Trees We can use search algorithms to write “intelligent” programs that play games against a human opponent. Just consider this extremely simple (and not very exciting) game: At the beginning of the game, there are seven coins on a table. At the beginning of the game, there are seven coins on a table. Player 1 makes the first move, then player 2, then player 1 again, and so on. Player 1 makes the first move, then player 2, then player 1 again, and so on. One move consists of removing 1, 2, or 3 coins. One move consists of removing 1, 2, or 3 coins. The player who removes all remaining coins wins. The player who removes all remaining coins wins.

5 October 3, 2012Introduction to Artificial Intelligence Lecture 9: Two-Player Games 5 Two-Player Games with Complete Trees Let us assume that the computer has the first move. Then, the game can be described as a series of decisions, where the first decision is made by the computer, the second one by the human, the third one by the computer, and so on, until all coins are gone. The computer wants to make decisions that guarantee its victory (in this simple game). The underlying assumption is that the human always finds the optimal move.

6 October 3, 2012Introduction to Artificial Intelligence Lecture 9: Two-Player Games 6 Two-Player Games with Complete Trees 7 6 5 4 321123 21CC142C3 352C H C H C1321123 21HHH3 1 14 32112321 HHH 3 4 32112321 CCC 3 H

7 October 3, 2012Introduction to Artificial Intelligence Lecture 9: Two-Player Games 7 Two-Player Games with Complete Trees So the computer will start the game by taking three coins and is guaranteed to win the game. The most practical way of implementing such an algorithm is the Minimax procedure: Call the two players MIN and MAX. Call the two players MIN and MAX. Mark each leaf of the search tree with 0, if it shows a victory of MIN, and with 1, if it shows a victory of MAX. Mark each leaf of the search tree with 0, if it shows a victory of MIN, and with 1, if it shows a victory of MAX. Propagate these values up the tree using the rules: Propagate these values up the tree using the rules: –If the parent state is a MAX node, give it the maximum value among its children. –If the parent state is a MIN node, give it the minimum value among its children.

8 October 3, 2012Introduction to Artificial Intelligence Lecture 9: Two-Player Games 8 Two-Player Games with Complete Trees 7 6 5 4 321 CC 4 C 5 C H C H C 321 HHH 4 321 HHH 4 321 CCC (min) (min) (min) (max) (max) H (max) 000 00 0 111111 000 0111111 011000 110 0

9 October 3, 2012Introduction to Artificial Intelligence Lecture 9: Two-Player Games 9 Two-Player Games with Complete Trees The previous example shows how we can use the Minimax procedure to determine the computer’s best move. It also shows how we can apply depth-first search and a variant of backtracking to prune the search tree. Before we formalize the idea for pruning, let us move on to more interesting games. For such games, it is impossible to check every possible sequence of moves. The computer player then only looks ahead a certain number of moves and estimates the chance of winning after each possible sequence.

10 October 3, 2012Introduction to Artificial Intelligence Lecture 9: Two-Player Games 10 Two-Player Games Therefore, we need to define a static evaluation function e(p) that tells the computer how favorable the current game position p is from its perspective. In other words, e(p) will assume large values if a position is likely to result in a win for the computer, and low values if it predicts its defeat. In any given situation, the computer will make a move that guarantees a maximum value for e(p) after a certain number of moves. For this purpose, we can use the Minimax procedure with a specific maximum search depth (ply-depth k for k moves of each player).

11 October 3, 2012Introduction to Artificial Intelligence Lecture 9: Two-Player Games 11 Two-Player Games For example, let us consider Tic-Tac-Toe (although it would still be possible to search the complete game tree for this game). What would be a suitable evaluation function for this game? We could use the number of lines that are still open for the computer (X) minus the ones that are still open for its opponent (O).

12 October 3, 2012Introduction to Artificial Intelligence Lecture 9: Two-Player Games 12 Two-Player Games e(p) = 8 – 8 = 0 XOX e(p) = 6 – 2 = 4 OOXXO X e(p) = 2 – 2 = 0 shows the weak- ness of this e(p) How about these? OOXX X e(p) =  e(p) = XXOOO X e(p) = -  e(p) = - 

13 October 3, 2012Introduction to Artificial Intelligence Lecture 9: Two-Player Games 13 Two-Player Games

14 October 3, 2012Introduction to Artificial Intelligence Lecture 9: Two-Player Games 14 The Alpha-Beta Procedure Now let us specify how to prune the Minimax tree in the case of a static evaluation function. Use two variables alpha (associated with MAX nodes) and beta (associated with MIN nodes). Use two variables alpha (associated with MAX nodes) and beta (associated with MIN nodes). These variables contain the best (highest or lowest, resp.) e(p) value at a node p that has been found so far. These variables contain the best (highest or lowest, resp.) e(p) value at a node p that has been found so far. Notice that alpha can never decrease, and beta can never increase. Notice that alpha can never decrease, and beta can never increase.

15 October 3, 2012Introduction to Artificial Intelligence Lecture 9: Two-Player Games 15 The Alpha-Beta Procedure There are two rules for terminating search: Search can be stopped below any MIN node having a beta value less than or equal to the alpha value of any of its MAX ancestors. Search can be stopped below any MIN node having a beta value less than or equal to the alpha value of any of its MAX ancestors. Search can be stopped below any MAX node having an alpha value greater than or equal to the beta value of any of its MIN ancestors. Search can be stopped below any MAX node having an alpha value greater than or equal to the beta value of any of its MIN ancestors. Alpha-beta pruning thus expresses a relation between nodes at level n and level n+2 under which entire subtrees rooted at level n+1 can be eliminated from consideration.

16 October 3, 2012Introduction to Artificial Intelligence Lecture 9: Two-Player Games 16 The Alpha-Beta Procedure Example: max min max min

17 October 3, 2012Introduction to Artificial Intelligence Lecture 9: Two-Player Games 17 The Alpha-Beta Procedure 4 Example: max min max min  = 4

18 October 3, 2012Introduction to Artificial Intelligence Lecture 9: Two-Player Games 18 The Alpha-Beta Procedure 4 5 Example: max min max min  = 4

19 October 3, 2012Introduction to Artificial Intelligence Lecture 9: Two-Player Games 19 The Alpha-Beta Procedure 4 5 3 Example: max min max min  = 3  = 3

20 October 3, 2012Introduction to Artificial Intelligence Lecture 9: Two-Player Games 20 The Alpha-Beta Procedure 4 5 31 Example: max min max min  = 3  = 3  = 1

21 October 3, 2012Introduction to Artificial Intelligence Lecture 9: Two-Player Games 21 The Alpha-Beta Procedure 4 5 31 8 Example: max min max min  = 3  = 3  = 1  = 3  = 8

22 October 3, 2012Introduction to Artificial Intelligence Lecture 9: Two-Player Games 22 The Alpha-Beta Procedure 4 5 31 8 6 Example: max min max min  = 3  = 3  = 1  = 3  = 6

23 October 3, 2012Introduction to Artificial Intelligence Lecture 9: Two-Player Games 23 The Alpha-Beta Procedure 4 5 31 8 6 7 Example: max min max min  = 3  = 3  = 1  = 3  = 6  = 6

24 October 3, 2012Introduction to Artificial Intelligence Lecture 9: Two-Player Games 24 The Alpha-Beta Procedure 4 5 31 8 6 7 Example: max min max min  = 3  = 3  = 1  = 3  = 6  = 6  = 3

25 October 3, 2012Introduction to Artificial Intelligence Lecture 9: Two-Player Games 25 The Alpha-Beta Procedure 4 5 31 8 6 7 2 Example: max min max min  = 3  = 3  = 1  = 3  = 6  = 6  = 3  = 2  = 3 Propagated from grandparent – no values below 3 can influence MAX’s decision any more.

26 October 3, 2012Introduction to Artificial Intelligence Lecture 9: Two-Player Games 26 The Alpha-Beta Procedure 4 5 31 8 6 7 2 5 Example: max min max min  = 3  = 3  = 1  = 3  = 6  = 6  = 3  = 2  = 3  = 5

27 October 3, 2012Introduction to Artificial Intelligence Lecture 9: Two-Player Games 27 The Alpha-Beta Procedure 4 5 31 8 6 7 2 5 4 Example: max min max min  = 3  = 3  = 1  = 3  = 6  = 6  = 3  = 2  = 3  = 4

28 October 3, 2012Introduction to Artificial Intelligence Lecture 9: Two-Player Games 28 The Alpha-Beta Procedure 4 5 31 8 6 7 2 5 4 4 Example: max min max min  = 3  = 3  = 1  = 3  = 6  = 6  = 3  = 2  = 4  = 4

29 October 3, 2012Introduction to Artificial Intelligence Lecture 9: Two-Player Games 29 The Alpha-Beta Procedure 4 5 31 8 6 7 2 5 4 4 6 Example: max min max min  = 3  = 3  = 1  = 3  = 6  = 6  = 3  = 2  = 4  = 4  = 6

30 October 3, 2012Introduction to Artificial Intelligence Lecture 9: Two-Player Games 30 The Alpha-Beta Procedure 4 5 31 8 6 7 2 5 4 4 6 7 Example: max min max min  = 3  = 3  = 1  = 3  = 6  = 6  = 3  = 2  = 4  = 4  = 6

31 October 3, 2012Introduction to Artificial Intelligence Lecture 9: Two-Player Games 31 The Alpha-Beta Procedure 4 5 31 8 6 7 2 5 4 4 6 7 7 Example: max min max min  = 3  = 3  = 1  = 3  = 6  = 6  = 4  = 2  = 4  = 4  = 6  = 6

32 October 3, 2012Introduction to Artificial Intelligence Lecture 9: Two-Player Games 32 The Alpha-Beta Procedure 4 5 31 8 6 7 2 5 4 4 6 7 7 Example: max min max min  = 3  = 3  = 1  = 3  = 6  = 6  = 4  = 2  = 4  = 4  = 6  = 6 Done!


Download ppt "October 3, 2012Introduction to Artificial Intelligence Lecture 9: Two-Player Games 1 Iterative Deepening A* Algorithm A* has memory demands that increase."

Similar presentations


Ads by Google