ADVERSARIAL SEARCH · 9 MIN
Minimax
In two-player games, MAX picks the move with the best worst-case outcome assuming MIN plays perfectly.
NEURA explains
- Build the game tree; leaves have scores.
- MAX layers take the maximum of children, MIN layers the minimum.
- Alpha-beta pruning skips branches that cannot change the decision.
Real world: Tic-tac-toe and chess engines.
Code
def minimax(node, maximizing):
if isinstance(node, int): return node
vals = [minimax(c, not maximizing) for c in node]
return max(vals) if maximizing else min(vals)
print(minimax([[3, 5], [2, 9]], True))Output ›
3Try it in the online compiler →Checkpoint quiz
minimax([[3,5],[2,9]], MAX first) =