Академический Документы
Профессиональный Документы
Культура Документы
Overview of
Minimax Algorithm
A PRESENTATION BY ASHISH SABADE
Minimax Algorithm-Components
Search tree :
Squares represent decision states (i.e- after a move)
Branches are decisions (i.e- the move)
Start at root
Nodes at end are leaf nodes
Unlike binary trees can have any number of children
Depends on the game situation
Levels usually called plies (a ply is one level)
Each ply is where "turn" switches to other player
Players called Min and Max
Current board
position
Minimax Algorithm-Description(1)
Assign points to the outcome of a game
Ex: Tic-Tac-Toe: X wins, value of 1. O wins, value -1.
Max (X) tries to maximize point value, while Min (O) tries to minimize point
value
Assume both players play to best of their ability
Always make a move to minimize or maximize points
So, in choosing, Max will choose best move to get highest points, assuming Min
will choose best move to get lowest points
Minimax Algorithm-Description(2)
A tree is generated and filled with values generated from evaluation function
An evaluation function, also known as a heuristic evaluation function or static evaluation
function, is a function used by game-playing programs to estimate the value or goodness of a
position
The evaluation function is typically designed to prioritize speed over accuracy; the function looks
only at the current position and does not explore possible moves (therefore static).
E.g for chess: f(P) = 200(K-K') + 9(Q-Q') + 5(R-R') + 3(B-B'+N-N') + (P-P') - 0.5(D-D'+S-S'+I-I')
+ 0.1(M-M')
K, Q, R, B, N, P are the number of white kings, queens, rooks, bishops, knights and pawns on the board.
D, S, I are doubled, backward and isolated white pawns.
M represents white mobility (measured, say, as the number of legal moves available to White)
15
MAX
MIN
A1
A2 15
15
A3
20
if (turn == WHITE)
return Max(depth);
else
return Min(depth);
}
Function call:value = MinMax(5); // search 5 plies
if (depth == 0)
return Evaluate();
GenerateLegalMoves();
while (MovesLeft()) {
MakeNextMove();
val = Min(depth 1); // Mins turn next
UnMakeMove();
if (val > best)
best = val;
}
return best;
}
if (depth == 0)
return Evaluate();
GenerateLegalMoves();
while (MovesLeft()) {
MakeNextMove();
val = Max(depth 1); // Maxs turn next
UnMakeMove();
if (val < best) // different than MAX
best = val;
}
return best;
}
Minimax Algorithm-Evaluation
Function
Most Important Function in minimax algorithm
Example for tic tac toe for max player (for min player just return score *(-1) )
int eval(move){
if(game over) return 0;
else{
if(move blocking opponents win) return highest_priority; // say highest priority is 5
if(open move){
if(move in central area) return 4;
if(move in corner area) return 3;
if(move in horizontal block) return 1;
}
}
}
Optimal?
Yes (against an optimal opponent).
Can it be beaten by an opponent playing sub-optimally?
No
Time complexity?
Space complexity?
O(bm) (depth-first search, generate all actions at once)
O(m) (backtracking search, generate actions one at a time)
In general, stop evaluating move when find worse than previously examined move
Does not benefit the player to play that move, it need not be evaluated any further.
Save processing time without affecting final result
Hence, Alpha-Beta pruning is used to dismiss unnecessary generation of worthless nodes
We can use alpha-beta pruning to calculate values at more depth and quickly, thus enabling
computer to make best decision using less time
Beta < Alpha current position not result of best play and can be pruned
The upper and lower limit of that window are defined as the highest and the lowest reasonable
value that a node at this level can have
If a nodes value falls outside that window, depending on the father type (max or min), we can
interrupt our search and return that same value for this node.
The window size should be different for every level of the tree
For higher levels->bigger window
For lower levels->smaller window
and then steadily increase the depth, while checking the remaining time
Just before the time limit is reached, the search for the best possible move at the increased
depth is aborted and the move from the previously completed depth search is retrieved.
By using a Transposition Table, many of the evaluation functions values of the shallower search
are stored and can be retrieved while searching deeper.
Board game of
ABALONE
was used for tests
A random minimax will randomize the choice among all possible paths of the game tree is
introduced
Rminimax Algorithm
Require:
G: The generated game tree obtained with the MINIMAX
algorithm. The root of the game is k 1.
> 0: The degree of randomization of the tree ( for a
perfect rational player; 0 for an almost completely random
player).
ckk 0: The cost of each arc of the tree.
1. Assign zbn= 1 for each n N.
2. Recursively compute zbk .
3. Compute the corresponding pkk value.
4. return pkk: the transition probabilities for the next play.
max
12
Normal Minimax
( CPU with max move)
9
min
12
18
10
12
30
CPU move
10
Random Minimax
( CPU with random move)
Wrong
move !!
10
12
Correct
move !!
18
10
12
30
Case 1: ->infinity
optimal minimax strategy
(previous example)
Case 2: ->0
random strategy
(current example)
References
1)Rminimax: An Optimally Randomized MINIMAX Algorithm
IEEE TRANSACTIONS ON CYBERNETICS, VOL. 43, NO. 1, FEBRUARY 2013
THANK YOU