How Minimax Works:

  1. Build the game tree: Represent all possible moves
  2. Evaluate leaf nodes: Assign scores to terminal states
  3. Propagate values upward:
    • MAX nodes choose the highest value from children
    • MIN nodes choose the lowest value from children
  4. 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