State spaces represent game trees, but here each alternate level is played by an adversary who will pessimise the search.
MiniMax(State,Direction,Depth) {
if (Depth == Limit) {
return(h(State));
}
if (Direction == maximising) {
Report the maximum of MINIMAX on successors
}
if (Direction == minimising) {
Report the minimum of MINIMAX on successors
}
}
5 MAX
/ | \
4 5 3 MIN
/ | \ / | \ / | \
8 9 4 5 9 6 3 9 16 MAX
/|\ /|\ /|\ /|\ /|\ /|\ /|\ /|\ /|\
8 7 3 9 1 6 2 4 1 1 3 5 3 9 2 6 5 2 1 2 3 9 7 2 16 6 4
? >=2 2 MAX
/ \ / \ / \
? ? 2 ? 2 <=1 MIN
/\ /\ /\ /\ /\ /\
2 7 ? ? 2 7 ? ? 2 7 1 ?
Last position is not evaluated.
MiniMax(State,Direction,Alpha,Beta,Depth) {
if (Depth == Limit) {
return(h(State));
}
if (Direction == maximising) {
while (alpha < beta && there is another Child) {
Alpha = max(Alpha,MiniMax(Child,minimising,Alpha,Beta,Depth+1));
}
return(Alpha);
}
if (Direction == minimising) {
while (alpha > beta && there is another Child) {
Beta = min(Beta,MiniMax(Child,minimising,Alpha,Beta,Depth+1));
}
return(Beta);
}
}
5 MAX
/ | \
4 5 3 MIN
/ | \ / | \ / | \
8 9 4 5 9 6 3 9 16 MAX
/|\ /|\ /|\ /|\ /|\ /|\ /|\ /|\ /|\
8 7 3 9 1 6 2 4 1 1 3 5 3 9 2 6 5 2 1 2 3 9 7 2 16 6 4
* = NE * * * * * * * * * * *
MAX MIN MAX
alpha beta alpha beta alpha beta Static
-MAX MAX -MAX MAX -MAX MAX 8
8 7 (not used)
3 (not used)
<- 8 --------------
8 -MAX 8 9
9 (stop, not used)
----------------
-MAX 8 2
2 4
4 1 (not used)
<- 4 --------------
4
<- 4 -----------------------------
4 4 MAX 4 MAX 1 (not used)
3 (not used)
5
<- 5 --------------
5 4 5 3 (not used)
9
9 (stop, not used)
----------------
4 5 6
6 (stop, not used)
----------------
<- 5 -----------------------------
5 5 MAX 5 MAX 1 (not used)
2 (not used)
3 (not used)
<- 5 --------------
5 5 (stop, not used)
_ MAX
/ | \
_ _ _ MIN
/ | \ / | \ / | \
_ _ _ _ _ _ _ _ _ MAX
/|\ /|\ /|\ /|\ /|\ /|\ /|\ /|\ /|\
8 7 3 9 1 6 2 4 1 1 3 5 3 9 2 6 5 2 1 2 3 9 7 2 16 6 4
_ MAX
/ | \
_ _ _ MIN
/ | \ / | \ / | \
_ _ _ _ _ _ _ _ _ MAX
/|\ /|\ /|\ /|\ /|\ /|\ /|\ /|\ /|\
8 7 3 9 1 6 2 4 1 1 3 5 3 9 2 6 5 2 1 2 3 9 7 2 16 6 4