How Minimax Works:
- Build the game tree: Represent all possible moves
- Evaluate leaf nodes: Assign scores to terminal states
- Propagate values upward:
- MAX nodes choose the highest value from children
- MIN nodes choose the lowest value from children
- Choose best move: Root picks child with best value
function minimax(node, depth, isMaximizing):
if node is terminal or depth == 0:
return evaluate(node)
if isMaximizing:
maxEval = -∞
for each child of node:
eval = minimax(child, depth-1, false)
maxEval = max(maxEval, eval)
return maxEval
else:
minEval = +∞
for each child of node:
eval = minimax(child, depth-1, true)
minEval = min(minEval, eval)
return minEval
Real-World Applications:
♟️ Chess Engines
Evaluating millions of positions to find the best move
🎮 Game AI
Creating challenging opponents in strategy games
🤖 Decision Making
Optimal choices in competitive scenarios
📊 Game Theory
Analyzing strategic interactions