Want a quick email when a new article is published? Subscribe
Ninety numbers and a racetrack: how a car learns to drive with nobody teaching it
A thousand cars sit on a start line, each controlled by a brain made of random numbers. When the clock starts, 603 of them never get going and 397 drive straight off the track. None of them gets more than 121 metres round. Five generations of breeding after a start like that, the best descendant laps the track faster than the driver created by hand, the one that can see the whole track and knows exactly where the corners are. Nobody told the learning car how to drive. It practised, it was scored, and the less bad ones were copied.

These articles are mostly about computers learning to fly, but this piece is about a computer learning to drive a car, because that’s simpler. If you’ve heard the phrase “neural network” a thousand times and never seen one learn something, this is a gentle place to start. It’s one of the simplest complete examples of machine learning you’ll see: a car, a track, a brain of 90 numbers, and a way of choosing better numbers. This page explains what a neural network actually is, how this one learns, how that differs from the other main kinds of machine learning, and why it will happily cheat if you let it.
A simple track and two drivers
The world is deliberately simple: a flat track seen from above, 400 metres long and 10 metres wide, with a long straight, sweeping corners and a tight hairpin. Leave the tarmac with any corner of the car and you’re out.

The physics is simple too. The car has two controls, each a number between -1 and +1. One is throttle and brake together: +1 is full acceleration, -1 full braking. The other is steering: +1 full left, -1 full right. The tyres have a grip limit, so if you try to turn too sharply at speed the car runs wide instead of turning as tightly as the wheels ask. That one rule is what makes driving fast a skill: you have to slow down for corners, and you have to know how much.
There are two drivers.
Pro is hand-written code, and it cheats in ways the learner never will: it can see the whole track. For steering, it picks a point on the centre line a little way ahead (further ahead the faster it’s going) and steers along the curve that would reach it, like a person looking down the road rather than at the bonnet. For speed, it works out the fastest speed each corner allows, then works backwards from every corner to find where it needs to start braking. It drives with deliberate safety margins: it only uses 85% of the tyres’ grip in corners and 70% of the brakes. This is all code, no machine learning, no AI driving here. Pro laps the track from a standing start in 31.97 seconds.
The Learner is told nothing. Not where the track goes, not which way is forward, not that leaving the tarmac is bad, not how to steer, brake or accelerate not even what its two outputs do.
The Learner sees seven distances and its own speed
The Learner’s only senses are seven imaginary lines, called rays, fanning out from the centre of the car: one straight ahead, and on each side one at 20 degrees, one at 45 degrees and one pointing straight out sideways. These represent the driver’s vision. Each ray reports how far it goes before it hits grass, up to 40 metres. Think of a person in a dark room holding seven laser measures.
From the start line, on the right-hand side of the track, it sees this:
| Ray | Distance to the grass |
|---|---|
| 90° right | 3.0 m |
| 45° right | 4.0 m |
| 20° right | 7.5 m |
| Straight ahead | 40.0 m (as far as it can see) |
| 20° left | 22.0 m |
| 45° left | 11.0 m |
| 90° left | 7.5 m |
A human would read that instantly: “I’m near the right edge, there’s a long clear run ahead”. To the car it’s just seven numbers. Add its speed and that’s eight numbers, every sixtieth of a second, and that is everything it will ever know about the world.

A neural network is a recipe with 90 adjustable quantities
The brain that turns those eight numbers into two controls is a neural network. Despite the biological-sounding name, it’s just arithmetic.
Start with one neuron. It takes some numbers in, multiplies each by its own weight, adds them up, adds one more number called a bias, and squashes the total into the range -1 to +1. That’s all. The weights say how much each input matters and in which direction: a big positive weight on “distance to the grass on the right” means “the more room on the right, the more this neuron fires”. The squashing function here is called tanh, and all it does is turn any number into something between -1 and +1, so that big inputs can’t produce absurd outputs: tanh of 0.5 is about 0.46, tanh of 5 is just under 1.
The Learner’s brain has two layers of these:
8 inputs 8 hidden neurons 2 outputs
(7 rays + speed) -> (weighted sum, squash) -> (throttle/brake, steering)
Each of the 8 hidden neurons has a weight for each of the 8 inputs plus a bias: 72 numbers. Each of the 2 output neurons has a weight for each of the 8 hidden neurons plus a bias: 18 numbers. That’s 90 numbers in total. The middle layer is called “hidden” only because you never see its values directly; it’s where the network can combine inputs into something more useful, like “the road is bending left” from several rays at once.
A good analogy is a mixing desk with 90 knobs. The inputs come in, every knob changes how much of each signal gets through to the next stage, and two outputs come out. The network’s entire “knowledge” is the position of those 90 knobs. There’s nothing else. Learning to drive means finding 90 good knob positions.
Here’s the whole brain, for anyone who reads code. It runs every car’s brain at once, which is why it looks more compact than the description:
def think(genomes, inputs):
w1, b1, w2, b2 = unpack(genomes) # cut each car's 90 numbers into weights and biases
hidden = np.tanh(np.einsum("ci,cih->ch", inputs, w1) + b1)
return np.tanh(np.einsum("ch,cho->co", hidden, w2) + b2)
How many hidden neurons to use is a judgement call. More neurons means the brain can represent more complicated behaviour, but there are more knobs to find good settings for, and a bigger search takes longer. Eight was enough here.
A brand new brain is filled with random numbers. Take one and show it the view from the start line. It decided on throttle +0.98 and steering -0.47: nearly full acceleration and a firm turn right, straight towards the nearest grass. There was no intent behind it at all; a different set of random numbers would have done something different and equally meaningless.
The score is the only part that knows what you want
Nobody tells the car how to drive, but the score does tell it how well it drove. That’s the fitness, a single number for each attempt:
- One point for every metre the car gets along the track before it stops.
- Once a car can finish a lap, ten more points for every second it had to spare out of a 60-second limit. A car that laps in 30 seconds scores 400 points for the distance plus 300 for the time.
A referee ends each attempt. A car is crashed the moment any corner of it touches the grass. It’s stalled if it hasn’t got a metre further round the track in three seconds, which stops cars that sit still or circle aimlessly from wasting simulation time. It’s finished when it completes a lap, and anything still going after 60 seconds has run out of time.
The most important idea here is that the brain knows nothing about the goal. “Drive well” means nothing to the car, but “get as far as you can, then go as fast as you can” is something the process can act on, and it will act on exactly that.
Keep the best, copy them badly, repeat
The learning method is called neuroevolution: evolution, as in Darwin, applied to the numbers in a neural network. One round of it is called a generation, and it goes like this:
- Make 1,000 brains, each a list of 90 random numbers.
- Let all 1,000 cars drive at once from the same start line. (They’re ghosts: they pass through each other rather than crashing into one another.)
- Score each one.
- Keep the top 5% exactly as they are, so the best brain found so far is never lost.
- Fill the other 95% with children. Each child is a copy of one of the top 20%, picked at random, with a small random nudge added to every one of its 90 numbers. The nudge is called mutation, and it’s typically about 0.1 either way.
- Repeat from step 2 with the new 1,000.
Here’s what mutation looks like in practice, for the first ten numbers of the best brain in generation 0 and one of its children:
| Parent | 0.12 | -1.03 | 0.23 | -0.44 | 0.40 | 0.96 | -0.15 | 0.85 | 1.13 | -0.19 |
| Child | 0.12 | -0.91 | 0.37 | -0.40 | 0.44 | 0.87 | -0.14 | 0.89 | 1.10 | -0.17 |
That’s all the learning there is. No car is ever told what it did wrong. Nobody works out which knob caused the crash. Brains that happened to score well get more copies, and the random nudges occasionally make a copy slightly better. Do that enough times, and “slightly better” accumulates into “good”.
The whole breeding step is seven lines of code:
def next_generation(genomes, fitness, rng, keep=0.05, parents=0.20, mutation=0.1):
n = len(genomes)
ranked = np.argsort(-fitness) # best first
n_keep, n_parents = max(1, int(n * keep)), max(1, int(n * parents))
survivors = genomes[ranked[:n_keep]]
chosen = ranked[rng.integers(0, n_parents, size=n - n_keep)] # a random good parent for each child
children = genomes[chosen] + rng.normal(0.0, mutation, size=(n - n_keep, genomes.shape[1]))
return np.vstack([survivors, children])
The settings are judgement calls too. Mutate too little and learning proceeds very slowly, if at all. Mutate too much and children lose what their parents knew. Use too few cars and there aren’t enough lucky accidents per generation to build on.
Thirty generations, five minutes, one beaten driver
Generation 0 is a shambles. Some cars sit still, because their random brain happened to “decide” to brake. Some drive straight into the grass. Some spin in circles. In the full run, the typical car got nowhere at all, and the best got 206 metres round before crashing. But that best car was slightly, accidentally, less bad than the others, and that accident is what evolution builds on.
Here’s how the run went, generation by generation:
| Generation | Best car | Typical car | Cars finishing a lap | Best lap |
|---|---|---|---|---|
| 0 | 206 m | 0 m | 0 | none |
| 1 | 238 m | 12 m | 0 | none |
| 3 | full lap | 115 m | 3 | 35.25 s |
| 5 | full lap | 114 m | 8 | 28.12 s |
| 10 | full lap | 241 m | 301 | 26.17 s |
| 15 | full lap | 259 m | 439 | 25.22 s |
| 22 | full lap | full lap | 504 | 25.02 s |
| 29 | full lap | full lap | 620 | 24.63 s |
The first lap was completed in generation 3. By generation 5 the best Learner had lapped in 28.12 seconds, beating Pro’s 31.97. By generation 22, the typical car, not just the best, got all the way round. After 30 generations, which took about five minutes on a desktop PC, the best brain lapped in 24.6 seconds, nearly 7.4 seconds faster than Pro.


Notice the shape of the typical car’s curve. It doesn’t climb smoothly. It sits flat for several generations, then jumps, then sits again. That’s normal for this kind of learning, and anyone judging the project at a flat bit would think it had stalled.
The simulation contains no randomness once the brains exist, so the same brains always drive exactly the same way. That means nothing needs recording: to watch any generation again, you just drive its brains again. It matters much more in the flying project.
It found a racing line nobody showed it
Put the two drivers’ lines side by side and the difference is obvious. Pro follows the centre line with its margins. The Learner uses the whole width of the track: it swings out wide before corners and cuts across to the inside, which is roughly what a racing driver would call the racing line. Nobody mentioned racing lines. That’s simply what got its ancestors further and faster.

To be fair to Pro, part of the Learner’s win is that Pro is cautious by design. It uses only 85% of the grip and 70% of the brakes. The Learner has no notion of caution, because caution isn’t in its score.
You can’t read meaning from 90 numbers by looking at them, but you can question the brain: put it somewhere on the track, at a given speed, and see what it does.
| Situation | Speed | Throttle | Steering |
|---|---|---|---|
| Drifting towards the right edge | 60 km/h | -0.80 (braking) | +0.94 (hard left) |
| Drifting towards the left edge | 100 km/h | -0.99 (braking) | -0.54 (right) |
| 10 m before a left-hand corner | 60 km/h | +0.98 (accelerating) | +0.95 (hard left) |
| 10 m before the right-hand hairpin | 100 km/h | -0.99 (braking) | +0.75 (left) |
Some sensible habits have appeared. It steers away from an edge it’s drifting towards. It brakes hard at 100 km/h in every situation tried, so it has effectively learned a speed limit. It turns in for the left-hander. Some answers look odd: it steers left before a right-hand hairpin. That’s probably the swing out to the outside before turning in, but it’s a reminder that these habits are simply whatever happened to work and survived. Nobody wrote any of them down, and they can’t be read as rules.
Three ways to say what “good” means
Neuroevolution is one of three broad families of machine learning. The clearest way to tell them apart is how often, and how precisely, the learner is told what “good” looks like.
Evolution gets one number per whole attempt. “That drive scored 512.” It never learns which moment of the drive was good or bad, or which of its 90 numbers to blame. It compensates with brute force: lots of attempts, and keeping whatever happens to work. That’s crude, but it asks almost nothing of the problem. The score doesn’t need to be smooth or clever, the simulator doesn’t need to be understood, and the method only needs to be able to run attempts and rank them.
Reinforcement learning gets feedback as it goes, a bonus or penalty at each step: a little for progress this moment, a penalty for touching the grass now. It then tries to work out which of its actions led to good outcomes later, and adjusts the brain in that direction. That’s more efficient with practice, and it’s how game-playing systems and many robot controllers learn, but it’s considerably more complicated to get working, and much harder to understand when it doesn’t.
Supervised learning is told the right answer for every situation. To use it here, you would record Pro driving, and train the network to output exactly what Pro would have done at every moment. That’s the most precise feedback of all, and it’s how most practical machine learning works, from spam filters to image recognition. Here, that means the best a copy of Pro can hope to be is Pro. Supervised learning needs a teacher, and it inherits the teacher’s limits. Pro didn’t know about racing lines, so a supervised learner wouldn’t have figured that out.
It does exactly what you score
The catch with a learner that only knows its score is that it will find every gap between the score and what you meant. There is no intent to deceive; anything that raises the score simply gets copied, whether or not you’d have approved.
In the car, the gaps are mild. The score counts distance and speed, and nothing else, so the Learner drives with no safety margin at all, using the whole width of the track and as much grip as it can get away with, because leaving any spare never raises its score. Take the lap-time bonus away and only distance counts, so once cars can finish there’s nothing to make them go faster.
In the flying project that followed, the gaps were anything but mild. A take-off pilot rolled down the runway eight or nine metres to one side of the centreline, take-off after take-off, because nothing said to stay on it. A landing pilot stopped on the runway by holding full throttle and full brakes at the same time, because the score only cared that it stopped; it works but it’s not good for the aeroplane and a real waste of fuel. Every one of them did exactly what it was scored on. In each case the fix was to change the score; the learner stayed the same.
From a racetrack to the sky
Once the car worked, the obvious next question was how far the same idea could go. The next project was harder in every direction: teach a light aircraft to take off, fly a circuit round an airfield and land, in a simulator, BigSkySim.
Some things carried over unchanged. The breeding step is word for word the same code: keep the top 5%, children of the top 20%, a nudge of about 0.1. The brains are still tiny: the take-off pilot has 99 numbers, against the car’s 90. And the score still does all the talking.
Plenty changed. An aeroplane moves in three dimensions, not two. It has more controls: the stick (forwards and back, left and right), rudder pedals, throttle, brakes, flaps. Wind pushes it around, so the same brain has to cope with situations that differ every time. A whole flight has three stages: take-off, circuit and landing, each needing a different skill. And the simulator was a browser page answering over the web, which at first ran at about real time. The car learned in five minutes because a whole generation took a few seconds to simulate. A thousand pilots each flying a dozen take-offs, a hundred times over, is 30,000 hours of flying.
How that got solved, and what the pilots learned once it was, is next.

Where next
- See the same method fly an aeroplane: Teaching a pilot to fly.
- Curious about the world the pilots learned in? BigSkySim explains the simulator.
- Want the whole flying project with the code and the machine learning explained? The walk-through, with code and the ML explained.
- Just want the lessons? From the other end.
Share this article
Comments
Leave a Comment
All comments are moderated and may take a short while to appear.
Loading comments...