ML primer
How a bot learns to play Rocket League by trial and error, one idea at a time.
10 min read
Imagine teaching a car to hit a ball. You could try writing the rules yourself: if the ball is ahead, drive forward; if it's in the air, jump at the right moment… You'd be writing rules forever. Rocket League has a spinning ball, walls, boost and flips, and nobody can write down the right controls for every moment.
Reinforcement learning (RL) takes another route. You don't tell the bot how. You let it try things and tell it how well it did. This page follows one bot from random flailing to playing matches, and explains each idea it needs on the way. The figures are live: drag, click and play.
The loop#
Everything starts with a loop. The bot sees the game, picks an action, the game moves on, and the bot gets a reward.
What it sees, the observation: 119 numbers in a 1v1 match. Where it is, how fast it's going, which way it faces, its boost, the ball, the other car, and its own last few actions.
What it does, the action: one of 90 control combinations (throttle, steering, jump, boost and so on), held for 8 physics ticks. That's 15 decisions a second.
What it gets, the reward: a number saying how good that moment was. Touching the ball is good; scoring is very good.
One trip around the loop is a step. A game from kickoff to the first goal is an episode. Our main 1v1 bot took about a billion steps to learn, which is why it trains in a fast simulator rather than the real game.
The bot rolls dice#
The bot itself is a neural network called the policy. It doesn't output one action. It outputs a probability for every action, then rolls weighted dice.
Why dice? A bot that always does its current favourite never finds out whether something else is better. Rolling keeps it exploring. Entropy measures how spread out the dice are. A new bot is equally likely to pick any of its 90 actions (entropy 4.50), and training slowly sharpens its preferences. A small entropy bonus stops it from becoming certain too early.
A reward later is worth less#
Rewards are rare. A random bot almost never scores, and even a good one goes seconds between touches. So the bot has to judge an action by what follows it, not just by the reward in that instant.
But how much should a goal in eight seconds count, compared with a touch right now? We discount the future: the further away a reward is, the less it counts.
The sum of discounted rewards from a moment on is the return, and it's what the bot tries to make as large as possible. We use a half-life of 5 seconds: a reward 5 s away counts half. Per decision, that's a discount of γ = 0.9908.
Learning from surprise#
Now the key question: after an episode, which actions should become more likely?
"The ones from episodes with a high return" turns out to be very noisy, because a high return might be luck. So the bot keeps a second network, the critic, which predicts the return from any situation. Each action is then judged by how much it beat that prediction:
advantage = what actually happened − what the critic expected
A positive advantage means better than expected: make that action more likely. A negative one means worse than expected: make it less likely. The network that picks actions is called the actor, so this is actor–critic learning. Try it on a tiny world with two choices:
The bot starts with no preference, and its critic expects nothing. Play an episode and watch what the surprise does.
Watch the purple line. The critic quickly learns what an episode is usually worth, and from then on only surprises move the bot. Luck the critic has already priced in cancels out.
Our actor and critic are separate networks with three layers each (512, 512 and 256 units; about 0.93 million weights in all for 1v1). The idea goes back to Barto, Sutton and Anderson in 1983.
How far ahead to look#
An advantage can be measured over a short horizon or a long one. Look one decision ahead and trust the critic for the rest, and it's steady but inherits the critic's mistakes. Add up every real reward to the end of the game, and it's honest but noisy. Generalized Advantage Estimation (GAE; Schulman and others, 2015) blends the two with one dial, λ:
We use λ = 0.95, the usual choice: real rewards count for under a second ahead, then the critic takes over.
One detail matters here. When a game ends with a goal, nothing follows, so the future is worth zero. When a time limit cuts it short, the future still had value, so the learner fills it in with the critic's estimate. That's why the environment reports the two endings separately.
Small steps: PPO#
Learning from advantages works, but it's fragile. Change the policy too much in one go and the bot can lose what it knew, and a bad bot then collects bad data to learn from.
Proximal Policy Optimization (PPO; Schulman and others at OpenAI, 2017) adds a simple brake. It compares each action's new chance with its old one, and once that ratio has moved 20% in the direction the advantage wants, it stops pushing:
Pushing: make this action more likely.
A training round goes like this:
Play. Run the current bot in thousands of games at once: 131,072 decisions per round.
Score. Work out each decision's advantage with GAE.
Learn. Make a few passes over that data (3 for matches), with the clip keeping each change small.
Throw it away and repeat. PPO only learns from games its current self played.
PPO is the workhorse of game RL because it's stable and simple. It trained OpenAI Five, which beat the Dota 2 world champions in 2019, a robot hand that solved a Rubik's cube, language models tuned with human feedback, and the Rocket League bots Necto, Nexto and Lucy-SKG.
Our learner plays the next round while it learns from the last one, so its data is always one round old. Plain PPO handles that badly; decoupled PPO (Hilton, Cobbe and Schulman, 2021) corrects for it. See Making training fast.
Helping the bot find the reward#
There's still a problem. A random car almost never scores, so a reward for goals alone gives it nothing to learn from for a very long time. The fix is shaping: small helper rewards along the way, for driving toward the ball, facing it, or pushing it toward the other net.
Helper rewards are dangerous, though: a bot finds any loophole that pays. In a classic case, a simulated bicycle rewarded for heading toward its goal learned to ride in circles, collecting the reward on every lap. Here's the same trap with a car:
The safe version is potential-based shaping (Ng, Harada and Russell, 1999). Give every situation a score, "how good does this look", and reward only the change in that score. Around any loop the changes cancel, so circling earns nothing, and the best way to play stays exactly what it was without the helper.
Every task here keeps its potential-based terms apart from ordinary rewards. In the main 1v1 run they summed to a flat −0.7 per episode across a billion steps, as the math says they should. The match reward comes from the Lucy-SKG paper (Methodology).
Playing against yourself#
In a two-player game the bot needs an opponent. Too weak and it learns nothing; too strong and it never wins. Self-play uses the bot itself, so the opponent improves exactly as fast as the bot. It's how TD-Gammon learned backgammon in 1992, and how AlphaZero and OpenAI Five learned.
Playing only your current self has a trap: the bot can go in circles, forgetting how to beat a style it no longer meets. So it also plays saved past versions of itself:
Press “Play an episode” to start training.
Our setting: one game in five is against a past version, chosen from the last 20 snapshots (one saved every 10 million decisions), recent ones more often. Details: Self-play.
Keeping score#
How good is the bot? Not its training reward: that includes the helper rewards, and it changes whenever the reward design does. Instead the bot plays evaluation games against fixed opponents, from starting positions it never saw in training, and we count results. Two tools turn the counts into honest numbers:
How sure is a win rate?
30 wins in 50 games: the true win rate is probably between 46% and 72%.
What does a rating gap mean?
A Wilson interval (Edwin Wilson, 1927) says how sure a win rate is. Ten games tell you little; a thousand pin it down.
Bradley–Terry ratings (1952), on the familiar Elo scale, give each bot one number from all its games. The scripted
ball_chaseris fixed at 1000.
Results: Bot standings.
Starting easy#
Some skills are so rare that random play may never stumble on them. A curriculum trains easy versions first (Bengio and others, 2009): our single-agent bots learn ground touches, then easy aerials, then full aerials, each stage starting from the last stage's best bot. Starting states drop the bot straight into situations where a skill matters: matches begin from a mix of kickoffs, random positions, goalie and aerial situations. More in Capabilities.
Where the ideas came from#
| Year | Idea | Who | Also used for |
|---|---|---|---|
| 1927 | Wilson interval | Edwin B. Wilson | Polls, A/B tests |
| 1952 | Bradley–Terry ratings | Ralph Bradley and Milton Terry | Sports and chess ratings |
| 1983 | Actor–critic | Andrew Barto, Richard Sutton, Charles Anderson | Balancing a pole on a cart; most modern RL |
| 1992 | Learning by self-play | Gerald Tesauro (TD-Gammon) | AlphaZero, OpenAI Five |
| 1999 | Potential-based shaping | Andrew Ng, Daishi Harada, Stuart Russell | Robotics and games |
| 2009 | Curriculum learning | Yoshua Bengio and others | Robotics, language models |
| 2015 | GAE | John Schulman and others | Nearly every PPO setup |
| 2017 | PPO | John Schulman and others, OpenAI | OpenAI Five, a Rubik's-cube robot hand, InstructGPT |
| 2021 | Decoupled PPO | Jacob Hilton, Karl Cobbe, John Schulman | Training on stale or very large batches |
The standard textbook is Sutton and Barto, Reinforcement Learning: An Introduction (2nd edition, 2018).
Rocket League bots#
| Project | What it is | What we use |
|---|---|---|
| RocketSim | An open-source copy of Rocket League's physics, much faster than the game | The simulator everything trains in (Simulation accuracy) |
| RLGym | A Python library that wraps Rocket League and RocketSim for RL | The action table, observation scales and reward functions (External projects) |
| Necto | A community PPO bot trained by self-play; won the RLBot Championship 2022 | Past-version opponents, starting states, team spirit (Methodology) |
| Nexto | Necto's successor, about Grand Champion 1 per its README | The same action table |
| Lucy-SKG | A 2023 paper bot that beat Necto and Nexto in its own tests | The match reward and its shaping (Methodology) |
Glossary#
Terms you'll meet in training logs and the Command Center.
| Term | Meaning |
|---|---|
| Rollout | The batch of games played between two updates |
| Approx KL | How far one update moved the policy; about 0.004–0.005 per update in the main run |
| Explained variance | How much of the return the critic predicts: 1 is perfect, 0 is useless |
| Warm start | A run that starts from another run's weights (--init-checkpoint), not an exact resume |
| Sample efficiency vs speed | Steps needed to learn a skill vs steps per second. What counts is wall-clock time to a skill, which needs both |