Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Computer Group Engineering Department University of Science and Culture S. H. Davarpanah

Similar presentations


Presentation on theme: "1 Computer Group Engineering Department University of Science and Culture S. H. Davarpanah"— Presentation transcript:

1 1 Computer Group Engineering Department University of Science and Culture S. H. Davarpanah Davarpanah@usc.ac.ir

2 Game playing Rich tradition of creating game-playing programs in AI Many similarities to search Most of the games studied – have two players, – are zero-sum: what one player wins, the other loses – have perfect information: the entire state of the game is known to both players at all times E.g., tic-tac-toe, checkers, chess, Go, backgammon, … Will focus on these for now Recently more interest in other games – Esp. games without perfect information; e.g., poker Need probability theory, game theory for such games

3 “Sum to 2” game Player 1 moves, then player 2, finally player 1 again Move = 0 or 1 Player 1 wins if and only if all moves together sum to 2 Player 1 Player 2 Player 1 Player 1 0 0 0 0 0 0 0 1 1 1 11 1 1 1 11 Player 1’s utility is in the leaves; player 2’s utility is the negative of this

4 Modified game From leaves upward, analyze best decision for player at node, give node a value Player 1 Player 2 Player 1 Player 1 0 0 0 0 0 00 1 1 1 11 1 1 -2-34-567 -8 4 6 7 6 6

5 A recursive implementation Value(state) If state is terminal, return its value If (player(state) = player 1) – v := -infinity – For each action v := max(v, Value(successor(state, action))) – Return v Else – v := infinity – For each action v := min(v, Value(successor(state, action))) – Return v Space? Time?

6 Search in Games Consider tic-tac-toe as a search problem. States, neighbors, goal? X O X O X O

7 7 An exemplary game: Tic-tac-toe Adversarial (game) tree search

8 8 Why do we consider: - only 3 nodes on the second level (instead of 9)? - only 2 nodes on the third level (instead of 8)?

9 9 The minimax procedure

10 10 Example

11 11 Solution: Example

12 Alpha-beta pruning Pruning = cutting off parts of the search tree (because you realize you don’t need to look at them) – When we considered A* we also pruned large parts of the search tree Maintain alpha = value of the best option for player 1 along the path so far Beta = value of the best option for player 2 along the path so far

13 13 Alpha represents a lower bound for the achievement of the Max player at a given node A BC D E Max Min Max f(B) = 15 f(D) = 10 f(C)  10  = 15  Alpha-beta pruning: Alpha cutoff This branch guarantees that Max will achieve at least 15 Max will not need to investigate branches with values lower than 15 because it will not move there.  

14 14 Beta represents an upper bound for the achievement of the Max player at a given node. A B F G Max Min Max f(F) = 15 H I Min ≥ f(H) = 25 25  = 15  f(G) Beta cutoff This branch guarantees that Max will achieve at most 15 Max will not need to investigate branches with values greater than 15 because Min will not move there.  

15 15 Consider the following game tree: a) Use the mini-max procedure and show what moves should be chosen by the two players. b) Use the alpha-beta pruning procedure and show what nodes would not need to be examined. c) Consider the mirror image of the above tree and apply again the alpha-beta pruning procedure. What do you notice? Exercise

16 16 a) Use the mini-max procedure and show what moves should be chosen by the two players. Exercise: Solution

17 17 b) Use the alpha-beta pruning procedure and show what nodes would not need to be examined. Exercise: Solution      

18 18 c) Consider the mirror image of the above tree and apply again the alpha-beta pruning procedure. What do you notice? Exercise: Solution 

19 Benefits of alpha-beta pruning Without pruning, need to examine O(b m ) nodes With pruning, depends on which nodes we consider first If we choose a random successor, need to examine O(b 3m/4 ) nodes If we manage to choose the best successor first, need to examine O(b m/2 ) nodes – Practical heuristics for choosing next successor to consider get quite close to this Can effectively look twice as deep! – Difference between reasonable and expert play

20 Many-player, general-sum games of perfect information Basic backward induction still works – No longer called minimax Player 1 Player 2 Player 3 0 0 0 0 0 00 1 1 1 11 1 1 (1,2,3) (3,4,2) (1,2,3) vector of numbers gives each player’s utility What if other players do not play this way?

21 Games with random moves by “Nature” E.g., games with dice (Nature chooses dice roll) Backward induction still works… – Evaluation functions now need to be cardinally right (not just ordinally) – For two-player zero-sum games with random moves, can we generalize alpha- beta? How? Player 1 Nature Player 2 50% 0 0 40% 0 00 1 60% 50% 11 1 1 (1,3) (3,2) (1,3) (3,4)(1,2) (3,4) (2,3.5)


Download ppt "1 Computer Group Engineering Department University of Science and Culture S. H. Davarpanah"

Similar presentations


Ads by Google