• Aucun résultat trouvé

Fixed-depth Minimax Tree Search

N/A
N/A
Protected

Academic year: 2022

Partager "Fixed-depth Minimax Tree Search"

Copied!
47
0
0

Texte intégral

(1)

Fixed-depth Minimax Tree Search

Bruno Bouzy

bruno.bouzy@parisdescartes.fr Université Paris Descartes

AOA Class

(2)

Outline

Minimax

Alfa-beta

Transposition tables

Iterative deepening

MTD(f)

Conclusion

(3)

The approach

Current position

Evaluation of

non terminal positions Bounded depth tree search

50

10 à 15

(4)

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)

(5)

Example minimax (1/4)

-3 4 5 2 -1 0 2 0

(6)

Example minimax (2/4)

4 5 0 2

-3 4 5 2 -1 0 2 0

(7)

Example minimax (3/4)

4 5 0 2

4 0

-3 4 5 2 -1 0 2 0

(8)

Example minimax (4/4)

4

4 5 0 2

4 0

-3 4 5 2 -1 0 2 0

(9)

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;

(10)

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;

}

(11)

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;

(12)

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;

(13)

Example alfa beta (1a/5)

-3 4 5 2 -1 0 2 0

-∞ +∞

(14)

Example alfa beta (1b/5)

-3 4 5 2 -1 0 2 0

-∞ +∞

-∞

-∞

+∞

+∞

(15)

Example alfa beta (2a/5)

-3 4 5 2 -1 0 2 0

-∞ +∞

-∞

-3

-∞

+∞

+∞

(16)

Example alfa beta (2b/5)

4

-3 4 5 2 -1 0 2 0

-∞ +∞

-∞

4

-∞

+∞

+∞

(17)

Example alfa beta (3a/5)

4

-3 4 5 2 -1 0 2 0

-∞ +∞

-∞

4

-∞

4

+∞

(18)

Example alfa beta (3b/5)

4

-3 4 5 2 -1 0 2 0

-∞ +∞

-∞

4

-∞

4

+∞ -∞

4

(19)

Example alfa beta (3c/5)

4 4

-3 4 5 2 -1 0 2 0

-∞ +∞

-∞

4

-∞

4

+∞ -∞ 4

(20)

Example alfa beta (3d/5)

4 4

-3 4 5 2 -1 0 2 0

-∞ +∞

4 -∞

4

-∞

4

+∞ -∞ 4

(21)

Example alfa beta (3e/5)

4 4

-3 4 5 2 -1 0 2 0

4 +∞

4 -∞

4

4

+∞ -∞ 4

(22)

Example alfa beta (4a/5)

4 4 4

-3 4 5 2 -1 0 2 0

4 +∞

4 -∞

4

4

+∞ -∞ 4

4

4 +∞

+∞

(23)

Example alfa beta (4b/5)

4 4 4

-3 4 5 2 -1 0 2 0

4 +∞

4 -∞

4

4

+∞ -∞ 4

4

4 +∞

+∞

(24)

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.

(25)

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 +∞

+∞

(26)

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...

(27)

Example alfa beta R->L (1b/4)

2

-3 4 5 2 -1 0 2 0

-∞ +∞

+∞

-∞

2 +∞

(28)

Example alfa beta R->L (2a/4)

2

-3 4 5 2 -1 0 2 0

-∞ +∞

2 -∞

2 +∞

0 2

(29)

Example alfa beta R->L (2b/4)

0 2

0

-3 4 5 2 -1 0 2 0

0

0 -∞

2 +∞

0 2

+∞

(30)

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 +∞

+∞

(31)

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 +∞

+∞

(32)

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

(33)

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

(34)

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.

(35)

Transposition table

-3 4 5 2 -1 0 2 0

A B

C D C D

A

A B

(36)

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.

(37)

alfa=3 beta=4 (1a/2)

-3 4 5 2 -1 0 2 0

3 4

3 4

3 4

(38)

alfa=3 beta=4 (1b/2)

4

-3 4 5 2 -1 0 2 0

3 4

3 4

3 4

(39)

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

(40)

alfa=4 beta=5 (1a/2)

-3 4 5 2 -1 0 2 0

4 5

4 5

4 5

(41)

alfa=4 beta=5 (1b/2)

4

4

-3 4 5 2 -1 0 2 0

4 5

4 5

4 5

(42)

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!

(43)

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)

(44)

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;

(45)

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

(46)

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)

A new hashing method with application for game playing,

ICGA journal (Zobrist 1990)

(47)

Thank you for your attention!

Références

Documents relatifs

We define in Coq an executable and terminating depth-first search algorithm, which, given a (runtime representation of) a graph, constructs a DFS forest.. The algorithm gives rise,

Technique overview and results: The study conducted in this pa- per is based on the simple observation that defining how neigh- borhoods are alternated within a local search descent

The main contribution of the paper is the Mosaic AutoML platform, adapting and extend- ing the Monte-Carlo Tree Search setting to tackle the structured optimization problem of

We consider sets of words (sequences of symbols) and their corresponding generating functions to get precise average case analysis (here expected value and variance) of

In this paper we focus on Upper Confidence Bound (UCB) bandit algorithms [ACBF02] applied to tree search, such as UCT (Upper Confidence Bounds applied to Trees) [KS06]. A reward

Experiments on the heterogeneous vehicle routing problem prove that DFS Split procedure has a great potential since the GRASPxELS approach using this

Here we introduce the main actors of the study: first the tree structures (digital search tree and tries), their parameters of interest, together with the main generat- ing

Abstract—In this work, we show that the Chapel high- productivity language is suitable for the design and implemen- tation of all aspects involved in the conception of parallel