The idea
Twenty cars drive a real circuit at once. Nobody programs them to drive. Each one is steered by a small neural network, and the networks get better by trial, error and copying.
Every demo on this page runs the simulator's own code: the same sensors, the same network, the same evolution and the same rules that run on the main page. Nothing here is a mock-up.
The loop is short:
- Each car reads ten numbers about its surroundings.
- Its network turns them into four numbers: throttle, steering, and whether to use straight mode and boost.
- The car drives until it hits a wall, stops making progress, or time runs out.
- The five cars that got furthest are kept. The other fifteen are replaced by slightly altered copies of those five.
- Repeat. A first clean lap usually comes within 20 to 120 rounds.
What a car senses
A car has no map and no camera. It casts five rays from its nose, A to E, and measures how far each travels before hitting a wall, up to 200 m. It also knows its own speed and which way the track points at the next gate, 25 m or less ahead.
Move the car around the Red Bull Ring and watch the readings change.
Grey bar: the distance divided by the 200 m range. Blue bar: what the network is actually given.
The brain shown is random until you train one in the Evolution section.
Why nearby walls get most of the signal
The readings do not go into the network as plain distances. A wall 5 m away and one 10 m away are very different situations, but divided by the 200 m range they are 0.025 and 0.05: almost the same number. For a long time the simulator worked that way, and almost every run got stuck at the first tight corner.
The fix was to present distance so the nearest 25 m uses most of the range (the blue bars above). With that single change, runs that lapped Monza in 300 rounds went from 1 in 10 to 10 in 10.
The brain
The diagram beside the track above is the whole brain: 10 inputs, two hidden layers of 16 and 14 neurons, and 4 outputs. Each line is a weight. Blue is positive, orange is negative, and a stronger colour is a larger number. Each dot is a neuron's current value.
A neuron adds up its inputs, each multiplied by the weight on its line, adds its own bias, and squashes the result to between −1 and 1. That is all the arithmetic there is. The two outputs that drive the car are read directly: throttle below zero is braking, steering below zero is left.
All the weights and biases together are numbers. That list is the car's genome. Two cars with the same genome drive identically.
Evolution
Nothing adjusts a brain while it drives. Learning happens between rounds, to the whole population, by keeping what worked.
A car's score is the number of gates it passed, in order, plus how far it got toward the next one. Gates sit every 25 m. Press the button to run real rounds of training on the Red Bull Ring. The cars start with random brains.
White: the best car. Grey: the average of all twenty. The dashed line is one full lap.
The best brain so far, one bar per number:
Once a brain can lap, go back up to What a car senses and press “Let the brain drive” to watch it.
What “slightly altered” means
A copy is made by nudging every number in the genome by a small random amount. The size of the nudge is the mutation sigma. Too small and nothing new is tried; too large and the copy forgets how to drive.
Parent
Copy
The simulator uses 0.3 while cars are still learning to lap, and drops to 0.05 once racing starts. At 0.3 only about 6 of the 20 cars can complete a lap even with a good parent; at 0.05 about 18 can, which is what makes a race possible.
Straight mode and boost
Two abilities are modelled on the 2026 rules. Each helps, and each has a cost.
- Straight mode opens the wing. Drag falls, so the car gets to a given speed sooner and its top speed rises from 324 to 360 km/h. Steering falls to 40%. It can only be opened inside a marked zone, and it stays open until the car brakes.
- Boost spends a battery for 30% more acceleration. A full battery lasts twelve seconds, and braking is the only thing that refills it.
Choose a combination and compare it with a plain car, both at full throttle from a standstill.
The network has three inputs for this (in a zone or not, battery level, overtake mode) and two outputs (use straight mode, use boost). Whether to use them, and when, is learned like everything else.
Circuits and zones
There are 26 circuits: the 24 on the 2026 calendar, plus Buddh and the Nürburgring 24-hour layout. Each outline is traced from a drawing on Wikimedia Commons and scaled to the official lap length, so distances and corner radii are close to the real ones. Width is a single typical figure per circuit.
Straight-mode zones (white on the map below; lighter bands on the road in the simulator) and the overtake detection gate (a dashed line in the simulator) are worked out from each circuit's shape by one rule: any stretch straighter than an 800 m radius for at least 350 m is a zone. They are not the positions used at the real races.
From solo laps to racing
Training has two stages, and it moves from one to the other by itself.
- Solo. Every car starts on the line and drives alone. Cars pass through each other. This is where they learn the circuit.
- Racing starts once five cars finish a lap in the same round. Each round is then two runs: a qualifying run, driven alone, and a race. In the race the cars line up single file, 40 m apart, and can hit each other. A brain's score is its qualifying distance plus its race distance, less any contact penalties. By default the grid is in qualifying order, with the fastest qualifier in front. A reversed grid is an option: the fastest qualifier starts last, so it has to pass the slower cars to get to the front.
Scoring both runs matters. In testing, scoring the race alone destroyed the cars' driving: within a few rounds the leader went from about three laps to a tenth of one, and never recovered. The qualifying run keeps the skill that the race then builds on.
Passing happens mostly when the grid makes it necessary. In testing on three circuits, a reversed grid gave about three times as much passing as a grid in qualifying order. It also gave about five times as much contact, and the fastest car ended up covering about a fifth less distance. With neither grid did passes become more frequent as training went on: the cars get past each other when they have to, but they are not learning to overtake.
The contact rule
When two cars touch, the car that is behind is at fault and is penalised; the car ahead carries on. If neither is clearly behind (head-on, or side by side) both are penalised. A car reversing into another is the one at fault. A penalty slows the car to 30% of its speed, keeps it clear of contact for three seconds so the two can separate, and takes 200 m (eight gates) off its score. The car stays in the race. A car a lap or more behind lets the leader through: blue flags, in effect, and the two do not touch at all.
Car A is fixed, facing right. Move car B and see the ruling.
Where it lives in the code
There are no libraries and no build step. The simulation runs without a browser, which is how its tests run.
src/car.js | The car: physics, sensors, straight mode, boost, battery, and the contact rule. |
src/nn.js | The network: about forty lines that turn a genome and ten inputs into four outputs. |
src/ga.js | Evolution: keep the best five, refill with mutated copies. |
src/track.js | Builds a circuit from waypoints: walls, gates, zones, grid, ray casting. |
src/simulation.js | One run: steps every car, applies the rules, scores them. |
src/stage.js | When racing starts, the qualifying and reversed grids, and the combined score. |
src/circuits/ | One file of waypoints per circuit, generated by scripts/build-circuits.js. |
src/render.js, src/ui/ | Everything drawn on screen. The simulation does not depend on any of it. |
Run the tests with npm test. Circuit drawings are credited in CIRCUIT-SOURCES.md.