Skip to content
StackDecode
AI & ML Atlas
Artificial IntelligencealgorithmInteractive simulation

Minimax Algorithm

Picks the move that is best assuming the opponent always replies with their best move.

The idea

In a two-player zero-sum game, one player (MAX) wants the score high and the other (MIN) wants it low. Minimax looks ahead through the game tree: at MAX levels it takes the largest child value, at MIN levels the smallest. The value that bubbles up to the root is the best score you can force against a perfect opponent.

V(s) = max over moves of V(child) at MAX, min at MIN

Watch it run

This is a real computation, not a drawing. Pause, step, change the settings, or try new random data.

  • MAX
  • MIN
  • now
  • pruned

Blue circles are MAX (wants a high score), purple are MIN (wants low). Squares are final scores. Minimax visits every leaf.

leaves evaluated:
0
1/81

Try new data: alpha-beta always returns the same value as minimax, with fewer leaves.

Step by step

  1. 1Build the game tree to a chosen depth and score the leaves with an evaluation function.
  2. 2At a MIN node, pass up the smallest child value.
  3. 3At a MAX node, pass up the largest child value.
  4. 4At the root, play the move that leads to the value passed up.

Where it is used

Chess, checkers, tic-tac-toe and other turn-based games.

Watch out for

The tree grows exponentially with depth, so real engines pair it with alpha-beta pruning and a good evaluation function.

Related