Fixed-depth Minimax Tree Search
Bruno Bouzy
bruno.bouzy@parisdescartes.fr Université Paris Descartes
AOA Class
Outline
●
Minimax
●
Alfa-beta
●
Transposition tables
●
Iterative deepening
●
MTD(f)
●
Conclusion
The approach
Current position
Evaluation of
non terminal positions Bounded depth tree search
50
10 à 15
Chess position evaluation
●
Assumption: we get an evaluation fonction of any position, terminal or not, that can be computed quickly.
●
Chess: piece-based evaluation
●
Eval = Σ v(pn) - Σ v(pb)
Example minimax (1/4)
-3 4 5 2 -1 0 2 0
Example minimax (2/4)
4 5 0 2
-3 4 5 2 -1 0 2 0
Example minimax (3/4)
4 5 0 2
4 0
-3 4 5 2 -1 0 2 0
Example minimax (4/4)
4
4 5 0 2
4 0
-3 4 5 2 -1 0 2 0
Minimax
int minimax (int depth) {
if (depth==0) return evaluate();
int best = (maxNode) ? -∞ : +∞;
For all move m {
make move m;
val = minimax(depth-1);
unmake move m;
if (maxNode)
if (val > best) best = val;
else
if (val < best) best = val;
Negamax
int negamax (int depth) {
if (depth==0) return evaluate();
int best = -∞;
For all move m {
make move m;
val = - negamax(depth-1);
unmake move m;
if (val > best) best = val;
}
return best;
}
Negamax + alfa beta
int negamaxAlfaBeta (int depth, int alfa, int beta) { if (depth==0) return evaluate();
For all move m {
make move m;
val = - negamaxAlfaBeta(depth-1, -beta, -alfa);
unmake move m;
if (val >= beta) return beta;
if (val > alfa) alfa = val;
}
return alfa;
Minimax + alfa beta
int minimaxAlfaBeta (int depth, int alfa, int beta) { if (depth==0) return evaluate();
For all move m {
make move m;
val = minimaxAlfaBeta(depth-1, alfa, beta);
unmake move m;
if (maxNode) { if (val >= beta) return beta;
if (val > alfa) alfa = val; } else { if (val <= alfa) return alfa;
if (val < beta) beta = val; } }
if (maxNode) return alfa;
else return beta;
Example alfa beta (1a/5)
-3 4 5 2 -1 0 2 0
-∞ +∞
Example alfa beta (1b/5)
-3 4 5 2 -1 0 2 0
-∞ +∞
-∞
-∞
+∞
+∞
Example alfa beta (2a/5)
-3 4 5 2 -1 0 2 0
-∞ +∞
-∞
-3
-∞
+∞
+∞
Example alfa beta (2b/5)
4
-3 4 5 2 -1 0 2 0
-∞ +∞
-∞
4
-∞
+∞
+∞
Example alfa beta (3a/5)
4
-3 4 5 2 -1 0 2 0
-∞ +∞
-∞
4
-∞
4
+∞
Example alfa beta (3b/5)
4
-3 4 5 2 -1 0 2 0
-∞ +∞
-∞
4
-∞
4
+∞ -∞
4
Example alfa beta (3c/5)
4 4
-3 4 5 2 -1 0 2 0
-∞ +∞
-∞
4
-∞
4
+∞ -∞ 4
Example alfa beta (3d/5)
4 4
-3 4 5 2 -1 0 2 0
-∞ +∞
4 -∞
4
-∞
4
+∞ -∞ 4
Example alfa beta (3e/5)
4 4
-3 4 5 2 -1 0 2 0
4 +∞
4 -∞
4
4
+∞ -∞ 4
Example alfa beta (4a/5)
4 4 4
-3 4 5 2 -1 0 2 0
4 +∞
4 -∞
4
4
+∞ -∞ 4
4
4 +∞
+∞
Example alfa beta (4b/5)
4 4 4
-3 4 5 2 -1 0 2 0
4 +∞
4 -∞
4
4
+∞ -∞ 4
4
4 +∞
+∞
Example alfa beta (5a/5)
4 4 4
4
-3 4 5 2 -1 0 2 0
4 +∞
4 -∞
4
4
+∞ -∞ 4
4
4 +∞
+∞
Another cut, at another level.
Example alfa beta (5b/5)
4
4 4 4
4
-3 4 5 2 -1 0 2 0
4 +∞
4 -∞
4
4
+∞ -∞ 4
4
4 +∞
+∞
Example alfa beta R->L (1a/4)
-3 4 5 2 -1 0 2 0
-∞ +∞
+∞
-∞
0 +∞
Let us go from the Right to the Left...
Example alfa beta R->L (1b/4)
2
-3 4 5 2 -1 0 2 0
-∞ +∞
+∞
-∞
2 +∞
Example alfa beta R->L (2a/4)
2
-3 4 5 2 -1 0 2 0
-∞ +∞
2 -∞
2 +∞
0 2
Example alfa beta R->L (2b/4)
0 2
0
-3 4 5 2 -1 0 2 0
0
0 -∞
2 +∞
0 2
+∞
Example alfa beta R->L (3a/4)
0 2
0
-3 4 5 2 -1 0 2 0
0
0 -∞
2 +∞
0 2
+∞
0
2 +∞
+∞
Example alfa beta R->L (3b/4)
5 0 2
0
-3 4 5 2 -1 0 2 0
0
0 -∞
2 +∞
0 2
+∞
0
5 +∞
+∞
Example alfa beta R->L (4a/4)
5 0 2
0
-3 4 5 2 -1 0 2 0
0
0 -∞
2 +∞
0 2
+∞
0
5 5
+∞
4 5
Example alfa beta R->L (4b/4)
4 5 0 2
0
-3 4 5 2 -1 0 2 0
0
0 -∞
2 +∞
0 2
+∞
0
5 5
+∞
4 5
Example alfa beta R->L (4c/4)
4
4 5 0 2
4 0
-3 4 5 2 -1 0 2 0
4
0 -∞
2 +∞
0 2
+∞
0
5 4
+∞
4 5
No cut!
The order of exploration is crucial.
Transposition table
-3 4 5 2 -1 0 2 0
A B
C D C D
A
A B
Iterative deepening
d=0;
while (hasTime) { d = d+1;
minimaxAlfaBeta(d, - , + ); ꝏ ꝏ }
Start by performing depth one search and increment the depth while time is available.
Give an anytime behaviour.
The last search is the most costful.
alfa=3 beta=4 (1a/2)
-3 4 5 2 -1 0 2 0
3 4
3 4
3 4
alfa=3 beta=4 (1b/2)
4
-3 4 5 2 -1 0 2 0
3 4
3 4
3 4
alfa=3 beta=4 (2/2)
4
4 4
4
-3 4 5 2 -1 0 2 0
3 4
3 4
3 4 3 4
alfa=4 beta=5 (1a/2)
-3 4 5 2 -1 0 2 0
4 5
4 5
4 5
alfa=4 beta=5 (1b/2)
4
4
-3 4 5 2 -1 0 2 0
4 5
4 5
4 5
alfa=4 beta=5 (2/2)
4
4 4
4 4
-3 4 5 2 -1 0 2 0
4 5
4 5
4 5
4
4
5
5
Many and large cuts again!
MTD(f)
●
A narrow window [alfa, beta] search:
–
V: result at the root
–
Mmx: minimax value to be found
–
if v == alfa then Mmx <= alfa
–
if v == beta then Mmx>=beta
–
numerous cuts
●
After the [3, 4] search, we have: v=4 (beta)
●
After the [4, 5] search, we have: v=4 (alfa)
MTD(f)
int MTDF(int depth, int f) {
int g = f, upper = + , lower=- ; ꝏ ꝏ while (lower<upper) {
beta = (g==lower) ? g+1 : g;
g = minimaxAlfaBeta(depth, beta-1, beta);
if (g==beta) lower = g;
else upper = g;
}
return g;
Conclusion
●
Fixed-depth minimax search is successful in Computer Chess
– Mininax, Alfa-beta
– Transposition tables, Iterative deepening
– MTD(f)
But is inefficient for most of other games
References
●
An analysis of alfa-beta pruning, AI journal, (Knuth &
Moore 1975)
●
A comparison of minimax tree search algorithms, AI journal, (Campbell & Marsland 1983)
●
Best-first fixed-depth game tree search in practice, IJCAI (Plaat & al 1995)
●
Depth-first iterative deepening: an optimal admissible tree search, AI Journal (Korf 1985)
●