Presentation is loading. Please wait.

Presentation is loading. Please wait.

Minimax.

Similar presentations


Presentation on theme: "Minimax."— Presentation transcript:

1 Minimax

2 Two Player Game Playing
Use backtracking to implement computer version of 2-player games: tic-tac-toe, chess, checkers, connect four Minimax algorithm: Backtracking algorithm for choosing next move in an 2-player game Value associated with each position of the game The player wants to make the move that maximizes the minimum value of the position resulting from the opponent’s following move

3 Game Tree X X X X X X X X X

4 Game Tree X moves O moves X moves O moves X O X O X O X O X O X O X O

5 Game Tree 1 -1 1 1 -1 1 X moves O moves X moves O moves X O X O X O X
1 X O X O X O X O X moves 1 -1 X O X O X O O moves 1

6 Minimax Algorithm - Strategies
Winning Strategy If the root has value 1, then player 1 has a winning strategy Termination guarantee implies an eventual win for player 1 If the root has value -1, then player 2 has a winning strategy If the root has value 0, then the best a player can do is guarantee himself a draw Does tic-tac-toe have a winning strategy?

7 Payoff Functions The game tree can be generalize to trees with payoff values Same minimax rules apply Chess Use payoff to estimate probability of a win

8 Minimax Algorithm Backtracking algorithm on the game tree
Tells us the best move (and whether it’s a winning strategy) Start with the board at some current position Explore all possibilities from this position Assign values {-1, 0, 1} after all children have returned

9 Minimax Algorithm 1 = max(1, -1, 0) -1 = min(0, -1) 0 = min(0, 1) 1
X moves 1 = max(1, -1, 0) X O X O X O O moves -1 = min(0, -1) 0 = min(0, 1) 1 X O X O X O X O X moves 0 = max(0) 0 = max(0) 1 = max(1) -1 X O X O X O O moves 1

10 Minimax Pseudocode int Minimax(state, level) { if(state is a solution) //base case return state’s value if(level is a max) { while(state has more children) Minimax(child, level+1) if value returned is > best so far, store it } return maximum returned value } else { //level is a min level if value returned is < best so far, store it return minimum returned value

11 Alpha-Beta Pruning A B I P C F J M Q T D E G H K L N O R S U V 5 2 5 4
max A 5 min B I P 2 5 4 max C F J M Q T 2 6 8 5 4 6 D E G H K L N O R S U V 2 1 6 1 8 3 5 2 3 4 2 6

12 Alpha-Beta Pruning Rules for pruning: At a max node q:
If p is a min node with parent q and p & q have “tentative” values v1 and v2 such that v1  v2, then you can prune all the unconsidered children of p. At a min node q: If p is a max node with parent q and p & q have “tentative” values v1 and v2 such that v1  v2, then you can prune all the unconsidered children of p.

13 Minimax Algorithm Pruned Pruned = -  =  = 1  =  = 1  = 
X moves = -  =  =  =  X O X O X O O moves = 1  =  = 1  = 0 1 = 1  = 0 = 1  =  X O X O X O X O X moves Pruned Pruned = 1  =  -1 = 1  =  X O X O X O O moves 1

14 Alpha-Beta Pseudocode
int Minimax(state, level, alpha, beta) { if(state is a solution) //base case return state’s value if(level is a max) { while(state has more children and alpha < beta) Minimax(child, level+1, alpha, beta) if value returned is > alpha, store it } return alpha } else { //level is a min level if value returned is < beta, store it return beta


Download ppt "Minimax."

Similar presentations


Ads by Google