What adversarial search is
Adversarial search is the group of methods AI uses when two or more agents want different outcomes, so one agent’s gain is often another’s loss. The classic case is a two-player game such as tic-tac-toe, checkers, chess, or Go. To choose a good move, the program has to think about how the opponent will respond, not just which move looks best right now.
Ordinary search works differently. Finding a route on a map has no opponent, so the program only needs a path to the goal. With an opponent, the program has to find a move that still holds up after the opponent picks the reply that is worst for the program.
When adversarial search applies
Most textbook examples share a few features:
- Turn-taking. The players move one at a time.
- Zero-sum outcomes. A win for one side is a loss for the other, and a draw falls in between.
- Perfect information. Both players can see the full state of the game. Chess and Go work this way. Poker does not, because players can’t see each other’s cards.
- No randomness. Each move fully determines the next position. Games with dice or shuffled cards need an extra step, covered below.
Game trees
A game tree lays out the possible sequences of moves. Each node is a board position, and each branch is a legal move. The root is the current position. The leaves are finished games, each given a score from one player’s point of view, such as a win, a loss, or a draw.
The two players are usually called MAX and MIN. MAX wants the highest score, and MIN wants the lowest. The levels of the tree alternate between them.
Three terms help when reading about these trees:
- The branching factor is the number of legal moves from a position.
- The depth is how many moves ahead the tree looks.
- A ply is one move by one player. A depth of four plies means each player has moved twice.
Minimax: choosing the best move
Minimax is the basic algorithm for these trees. It scores the leaves first and then works back up to the root:
- At a MAX node, the score is the largest score among its children.
- At a MIN node, the score is the smallest score among its children.
- At the root, MAX picks the move whose child has the largest score.
Here is a small example. MAX has three possible moves. After each one, MIN has three replies, and each reply leads to a final score for MAX.
- Move A leads to a MIN node with leaves 3, 12, and 8. MIN’s best choice gives 3.
- Move B leads to a MIN node with leaves 2, 4, and 6. MIN’s best choice gives 2.
- Move C leads to a MIN node with leaves 14, 5, and 2. MIN’s best choice gives 2.
MAX compares 3, 2, and 2 and picks move A. Against an opponent who plays its best replies, move A guarantees a score of at least 3.
For a finite game tree, minimax always finds this answer, assuming the opponent plays its best. The catch is cost. If the branching factor is b and the game runs m moves deep, minimax may examine roughly b to the power of m positions. That number grows fast. Tic-tac-toe is small enough to search to the end, but chess and Go are not.
Alpha-beta pruning
Alpha-beta pruning gets the same answer as minimax but skips parts of the tree that cannot change the decision. It keeps two bounds as it searches:
- Alpha is the best score MAX can already guarantee.
- Beta is the best score MIN can already guarantee.
Back in the example, after move A is fully checked, MAX has a guaranteed score of 3. When the first reply under move B is checked, its score is 2. MIN can hold MAX to 2 or less in that branch, which is worse than 3, so MAX will never choose move B. The program skips the other two leaves under B. It still picks move A, but it examines 7 of the 9 leaves instead of all 9.
With good move ordering, meaning the strongest moves are checked first, alpha-beta can examine roughly the square root of the positions minimax needs. That lets a program search about twice as deep for the same effort.
Searching deep enough
For most real games, even alpha-beta cannot reach the end. Programs stop at a set depth and estimate the position with an evaluation function. A chess evaluation function, for example, might count material, weigh piece placement, and check king safety. The score is an estimate, not a guaranteed result. An evaluation function is a kind of heuristic. For more on how heuristics guide search, see types of heuristic search in artificial intelligence.
Estimates can fail at the edge of the search. If a bad outcome falls just past the depth limit, the program may not see it. This is called the horizon effect. One fix is quiescence search, which keeps examining forcing moves such as captures until the position is quiet.
Examples of adversarial search in practice
- Tic-tac-toe. The full game tree is small, with about 255,000 possible games. A program can search every line to the end and always play without losing.
- Checkers. In 2007, researchers announced that checkers is solved. With perfect play from both sides, the result is a draw.
- Chess. In 1997, IBM’s Deep Blue won a six-game match against world champion Garry Kasparov, 3½ to 2½. Its search relied heavily on alpha-beta pruning, backed by specialized hardware and a detailed evaluation function.
- Go. Go has a much larger branching factor than chess, so brute-force alpha-beta search was not enough. In 2016, DeepMind’s AlphaGo beat Lee Sedol 4–1. It used Monte Carlo tree search guided by neural networks.
- Video games. Many non-player characters follow scripted rules rather than full search. They need to respond in real time, and they rarely need to play perfectly.
Games with chance and hidden information
Dice and shuffled cards add randomness, so the program has to account for many possible outcomes. Expectiminimax adds chance nodes, where the value is the average of the child values, weighted by their probabilities. Backgammon is a common example.
Hidden information is harder. In poker, players can’t see each other’s cards, so a program must reason about what the opponent might hold. Basic minimax does not handle this directly, and researchers use specialized methods instead.
Uses beyond games
The same ideas appear in settings where another party reacts to what the system does. Security planning is one example. A defender chooses how to protect a system, and an attacker chooses where to strike in response. Models like this borrow ideas from game search, though real security problems are usually more complicated than a small game tree.
Where to start
Draw a small game tree on paper. Pick a simple position, such as a tic-tac-toe board with two moves left, and label each leaf as a win, loss, or draw from one player’s view. Apply the minimax rules to work back to the root. Then do the same with alpha-beta pruning to see which branches you can skip.