Minimax Algorithm Explained: A Beginner's Guide

Last Updated 20 Aug, 2026
Quick Answer

What is the minimax algorithm?

The minimax algorithm is a decision-making method used in two-player games like chess and tic-tac-toe. It helps a computer choose the best possible move by assuming the opponent will also play their smartest move.

  • How game trees map out future moves and outcomes
  • How MAX and MIN players score potential decisions
  • How alpha-beta pruning optimizes the algorithm's search speed

What Is the Minimax Algorithm?

Imagine playing tic-tac-toe against a computer that never loses. That computer is likely using the minimax algorithm to think ahead.

The minimax algorithm is a decision-making method used in two-player games like chess, checkers, and tic-tac-toe. It helps a computer player pick the best possible move by assuming the other player will also play their best move. One side tries to get the highest score (called MAX), and the other side tries to get the lowest score (called MIN) — that's where the name "minimax" comes from.

This kind of thinking is called adversarial search, because the computer is searching for a move while working against an opponent who is trying to beat it.

What Is a Game Tree?

Before you can understand how the minimax algorithm picks a move, you need to see how a computer pictures a game in the first place — that's what a game tree does.

A game tree is a diagram that lays out every possible move, turn by turn, like a family tree of decisions. Each point in the tree, called a node, represents one possible state of the game board. Each line connecting two nodes represents one move.

Game-tree

  • The top node is the current position.
  • Each level below it represents one player's turn.
  • The bottom nodes, called leaf nodes, show how the game ends — a win, a loss, or a draw.

In apps like a chess app on your phone (for example, Chess.com's built-in bot), the game tree is how the app "looks ahead" before deciding what move to make.

How Does the Minimax Algorithm Work?

Now that you know what a game tree looks like, here's how minimax actually uses it to choose a move.

The minimax algorithm walks through the game tree from the bottom up. Here's the step-by-step process:

  1. Build the tree. List out all possible moves from the current position, and all the moves after that, until the game ends (or until a set depth, for games too large to fully map).
  2. Score the leaf nodes. At each ending point, assign a number: a positive number if MAX wins, a negative number if MIN wins, and zero for a draw.
  3. Work back up the tree. At every MIN node, pick the smallest score among its children (MIN wants MAX to score as low as possible). At every MAX node, pick the largest score among its children.
  4. Repeat until you reach the top. The value that reaches the root node tells you the best score MAX can guarantee.
  5. Pick the move that leads toward that best score.

This is often called "backing up" values through the tree, because scores flow upward from the leaves to the root.

Minimax-Backup

Each player assumes the other will always make their smartest possible move, so the algorithm never gets caught off guard by an opponent playing well.

Minimax Algorithm Example: Tic-Tac-Toe

Tic-tac-toe is small enough that a computer can map out the entire game tree, which makes it the easiest way to see minimax in action.

Say the board is almost full, and the X player (MAX) has two possible moves left:

  • Move A blocks the O player and sets up a win for X.
  • Move B ignores the block and lets O complete a line.

The minimax algorithm scores every path to the end of the game for both moves. Move A leads to X winning, so it gets a high score. Move B leads to O winning, so it gets a low score. Since X is the MAX player, the algorithm picks Move A.

Tic-tac-Toe

This is exactly why tic-tac-toe apps are unbeatable once they use minimax correctly — there is no move you can make that the algorithm hasn't already scored.

What Is Alpha-Beta Pruning?

Mapping out every single move works fine for tic-tac-toe, but a game like chess has far too many possible positions to check them all. That's the problem alpha-beta pruning solves.

Alpha-beta pruning is a shortcut for the minimax algorithm. It skips checking branches of the game tree that can't possibly change the final decision, without changing the answer minimax would have given anyway.

It works by keeping track of two numbers as it searches:

  • Alpha: the best score MAX has found so far.
  • Beta: the best score MIN has found so far.

If, at any point, a branch can't produce a better result than what's already been found, the algorithm stops exploring that branch. This is called "pruning," the same word used for cutting off branches of a tree.

How Does Alpha-Beta Pruning Work?

Here's how that cutting-off decision actually happens while the algorithm is searching.

  1. Start searching the tree just like normal minimax, tracking alpha and beta as you go.
  2. At a MAX node, update alpha whenever a child returns a higher score.
  3. At a MIN node, update beta whenever a child returns a lower score.
  4. If alpha becomes greater than or equal to beta at any node, stop searching the rest of that node's children — nothing found there can change the final answer.
  5. Continue until the search finishes, using far fewer checks than plain minimax.

In the example below, MAX has already found a move worth 3 points from the left branch. While checking the right branch, the algorithm sees that it can score at most 2 points — so it stops early instead of checking every remaining option.

Alpha-Beta-Pruning

Chess engines like Stockfish rely heavily on alpha-beta pruning. Without it, even a powerful computer couldn't search deep enough into a chess game to play well within a reasonable amount of time.

Minimax vs Alpha-Beta Pruning

Both approaches reach the exact same final decision — the difference is speed and how much of the tree gets checked.

FeatureMinimaxAlpha-Beta Pruning
Checks every branchYesNo, skips unneeded branches
Final decisionSameSame
SpeedSlowerFaster
Good for large games (chess)Struggles without helpWorks well
Extra values trackedNoneAlpha and beta

Minimax and Alpha-Beta Pruning in Chess

Chess is the classic real-world example of why alpha-beta pruning matters so much.

A chess game has so many possible positions that no computer could ever build the full game tree. Chess engines instead search a few moves ahead (called "depth"), score each resulting position using rules like piece value and board control, and use the minimax algorithm to pick the move that leads to the best guaranteed outcome.

Because a full search would be far too slow, engines like Stockfish and the bots inside apps like Chess.com use alpha-beta pruning to cut out huge sections of the tree that can't affect the outcome. This lets them search many moves deeper in the same amount of time, which is a big part of why modern chess engines play so well.

Conclusion

The minimax algorithm gives computers a way to make smart decisions in games by assuming both players always play their best move. Once you can picture a game tree and follow scores moving from the leaves up to the root, the whole idea becomes simple to follow. Alpha-beta pruning builds on this same idea, skipping branches that can't change the outcome so the search runs much faster. Together, these two ideas power everything from a simple tic-tac-toe app to world-class chess engines.

Frequently Asked Questions

The MAX player tries to achieve the highest score possible, while the MIN player tries to get the lowest score. The algorithm assumes both players will make their optimal moves.

Alpha-beta pruning is a shortcut for the minimax algorithm that skips checking branches of a game tree that cannot affect the final decision, making the search much faster.

Tic-tac-toe is small enough that a computer can map out the entire game tree, allowing minimax to score every path and guarantee a non-losing strategy.

No, both approaches make the exact same final move decision. The main difference is that alpha-beta pruning is much faster because it checks fewer branches.