TL;DR
Self-play is a way to train a game-playing agent with no teacher and no dataset. The agent plays games against copies of itself, learns from the results, and then plays the improved version against itself again. Because the opponent gets better at the same pace as the agent, the difficulty rises automatically.
Self-play is a training recipe, not a single algorithm. It works on top of Reinforcement Learning and is most natural for two-player games where one side's gain is the other side's loss.
Where you'll see it: in game programs that learned chess, shogi and Go from the rules alone, and in training agents for competitive video games, where past versions of the agent serve as the opponents.
Intuition
Start from practice against a sparring partner
Imagine learning tennis with nobody to hit with. You could hit a wall, but the wall never returns a clever shot. Now imagine a partner who learns from every point you play and then plays back against you. You both get better, and each new skill you pick up is tested on the next rally.
Self-play is that partner. The agent's opponent is its own past or present self, so the practice is always matched to the current level. A fixed opponent, by contrast, can be beaten by a narrow trick and then teaches nothing more.
Why the idea exists
Learning from human games is expensive, and it caps the agent at the level of the humans who wrote the games. Hand-written opponents encode the designer's guesses about good play. Self-play removes both limits. The only input is the rules of the game and a way to score the result. The agent can discover strategies that no person has tried.
The picture to keep in mind is a loop:
flowchart LR A["Current policy"] --> B["Play games against a copy"] B --> C["Record moves and outcomes"] C --> D["Update the policy"] D --> A
The math
Self-play is most cleanly described for a two-player zero-sum game: two players alternate moves, and at the end one player's payoff is the negative of the other's. Rock-paper-scissors is one; chess and Go are others.
A strategy (or policy) gives, for each situation, a probability for each legal move. Write for the payoff matrix (a table of payoffs, one row per move of the first player and one column per move of the second): entry is the payoff to the first player when the first player uses pure move and the second uses pure move . If the first player uses the mixed strategy and the second uses , the expected payoff is
Here is the probability the first player picks move , and is the probability the second player picks move .
The game value is . A pair of strategies is a Nash equilibrium when neither player gains by changing alone. In a two-player zero-sum game, the minimax theorem says that the equilibrium value exists and equals the game value, and that the equilibrium strategies guarantee at least this payoff against any opponent.
The minimax idea is covered in Minimax Game, and the general solution concept in Nash Equilibrium. Self-play is a way of approaching that equilibrium without writing the matrix down.
Self-play as repeated best response
A simple self-play rule is fictitious play, proposed by George Brown in 1951. Each round, every player chooses the best response to the average of all the opponent's past moves. In a two-player zero-sum game, the empirical frequencies of play converge to an equilibrium, a result shown by Julia Robinson in 1951.
Modern self-play replaces the exact best response with a learned policy. The update is usually a reinforcement learning step such as a Policy Gradient method. The reward for the agent at the end of a game is for a win, for a draw and for a loss. The policy moves toward moves that led to higher on average.
Two details that make it work
- Keep a pool of opponents. If the agent only plays its latest version, it can forget how to beat older strategies. Playing against a mix of past copies keeps earlier skills in the training signal.
- Keep exploring. A policy that becomes too sure of itself stops trying new moves. Add randomness to move choice, especially early in training, so that the games cover more of the game tree.
Worked examples
These examples use small numbers chosen to show the arithmetic. They are not records of real training runs.
Payoff to the first player: win , draw , lose . The only equilibrium is to play each move with probability , which has value .
True fictitious play answers the average of the opponent's whole history. To keep the arithmetic tiny, this example uses a simpler rule: each player answers only the opponent's previous move. Suppose both players start by playing rock, and each later round each player plays the move that beats the other's previous move.
- Round 1: both play rock.
- Round 2: each player's last move was rock, and paper beats rock. Both play paper.
- Round 3: each player's last move was paper, and scissors beats paper. Both play scissors.
- Round 4: each player's last move was scissors, and rock beats scissors. Both play rock again, and the cycle repeats.
Interpretation: over rounds 2 to 4 the agent plays paper, scissors and rock once each. The frequency of each move is , which matches the equilibrium, even though no single round looks balanced. Averaging over the history is what brings the mix to the equilibrium; the individual moves keep cycling. (With the full-history rule of fictitious play, the same averaging is built in.)
Take 10 sticks. Each turn, a player removes 1, 2 or 3 sticks. The player who takes the last stick wins.
Work out which positions are losing for the player to move. With 0 sticks, the player to move has already lost. Call a position losing when every move from it leads to a winning position for the opponent.
- With 1, 2 or 3 sticks, the player takes all of them and wins. These are winning positions.
- With 4 sticks, every move leaves 3, 2 or 1 sticks, all winning for the opponent. So 4 is a losing position.
- With 5, 6 or 7 sticks, the player can leave 4 and win. These are winning positions.
- With 8 sticks, every move leaves 7, 6 or 5, all winning for the opponent. So 8 is losing.
- The pattern continues: the losing positions are the multiples of 4.
Interpretation: with 10 sticks, the winning move is to take 2 and leave 8. A self-play learner that plays many games against itself should, with enough games, value the positions 4 and 8 as losing and learn to leave them to the opponent. It finds this rule without being told it.
A training loop for a board game alternates two phases. In the first, the current network generates many self-play games. In the second, a new network is trained on the results. Before the new network replaces the old one, the two play a set of evaluation games, and the new one is kept only if it wins a clear majority. AlphaGo Zero used a 55 percent threshold over a set of 400 games.
Suppose the new network wins 231 of 400 games.
- Win rate: , which is percent.
- Compare with the threshold: , so the new network replaces the old one.
- Suppose instead it wins 210 of 400. Then , or percent. This is below , so the old network stays as the champion and generates the next round of games.
- Interpretation: the threshold stops training from chasing noise. A small edge in a few hundred games is not strong evidence of a better player, so the loop waits for a clearer improvement.
The numbers are illustrative. The point is the rule, not the exact counts.
Tradeoffs and failure modes
| Situation | Problem | Better choice |
|---|---|---|
| Two-player zero-sum game with a clear winner | Self-play converges well toward an equilibrium | Use self-play with a pool of past opponents |
| Agent plays only its latest version | It forgets how to beat strategies it has moved away from | Keep a pool of past copies as opponents |
| Cyclic games such as rock-paper-scissors | The agent can cycle through strategies without improving | Average over history, or add a population of diverse opponents |
| Cooperative or general-sum game | Two players may agree on a poor outcome, and there is no single equilibrium to aim for | Add reward shaping or other signals from outside the self-play loop |
| Hidden information, such as cards in hand | The state the search sees is incomplete | Use methods designed for imperfect information |
Some failure modes come up again and again:
- Narrow style. If all games come from one policy, the data covers only that policy's favourite positions. The agent can be strong in those positions and weak elsewhere.
- Exploitability. A policy can beat its own copy and still lose badly to a different strategy. Winning against yourself is not a guarantee of strength against others.
- Cycles. Two agents can keep trading wins without either getting stronger, as in rock-paper-scissors.
- Compute. Self-play needs very large numbers of games. Results in published systems depend on this scale, and small reproductions usually learn much more slowly.
Self-play is often combined with Monte Carlo Tree Search during the game, as in AlphaZero, and with a Curriculum Learning schedule that starts from easier positions.
History
In the 1950s, Arthur Samuel's checkers program learned by playing against versions of itself, one of the first demonstrations that a machine could improve at a game without a human teacher. George Brown proposed fictitious play in 1951, and Julia Robinson showed in the same year that it converges for two-player zero-sum games.
In the early 1990s, Gerald Tesauro's backgammon program TD-Gammon learned by playing itself with a neural network and temporal-difference updates. It reached a strong level of play and showed that self-play and learned evaluation could work together.
In 2017, David Silver and colleagues at DeepMind published a Go program that learned from self-play alone, with no human game records, and then the same approach was extended to chess and shogi in the AlphaZero work. Later systems for real-time strategy games used a league of many past agents as opponents, which is the population idea in the definition above.
Recap
Self-play trains an agent against copies of itself, so the opponent's difficulty rises with the agent's skill. In two-player zero-sum games the target is the minimax equilibrium, which fictitious play approaches by averaging over history. In practice you pair a Reinforcement Learning update with a pool of past opponents, enough exploration, and a gate on replacing the champion. It leads on to AlphaZero, which adds Monte Carlo Tree Search, and to league training for harder, multi-player games.
Check yourself
QuestionIn one sentence, what is the main reason self-play does not need a dataset of human games?Show answer
The agent generates its own training data by playing against copies of itself. The opponent improves at the same pace, and each game's result provides a learning signal, so the only input required is the rules and a way to score the outcome.
QuestionIn rock-paper-scissors with payoffs , , , what mix does the equilibrium use, and what is the game's value?Show answer
Each move with probability . No player can gain by moving away from this mix, and its expected payoff against any opponent is , which is the game value.
QuestionIn Nim with 10 sticks, taking 1, 2 or 3 per turn, which move wins, and why?Show answer
Take 2, leaving 8 sticks. Positions with 4 or 8 sticks are losing for the player to move, because every move from them leaves a winning position for the opponent. Leaving 8 hands the opponent a losing position.
QuestionWhy might keeping a pool of past copies as opponents be better than always playing the newest version?Show answer
The newest version may have forgotten how to beat strategies it has moved away from, and it may cycle between strategies without improving. A pool of past copies keeps those earlier skills in the training signal and gives a more varied opponent set.
QuestionAn agent wins 205 of 400 evaluation games against the current champion, and the threshold is 55 percent. Should the champion be replaced?Show answer
No. , or percent, which is below percent. The difference is too small to count as clear improvement over a few hundred games, so the champion stays.