State spaces represent game trees, but here each alternate level is played by an adversary who will pessimise the search.
If the limit has been reached, report the static evaluation. If maximising report the maximum of MINIMAX on each successor. If minimising report the minimum of MINIMAX on each successor.
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(StaticEval(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,maximising,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) <- 9 -------------- -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) <- 9 -------------- 4 5 6 6 (stop) <- 6 -------------- <- 5 ----------------------------- 5 5 MAX 5 MAX 1 (not used) 2 (not used) 3 (not used) <- 5 -------------- 5 5 (stop)
_ 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