What you're watching
Every car has its own small neural network: a handful of numbers in, a few layers of arithmetic, two numbers out. The numbers in are what the car's distance sensors see (how far the road goes before its edge, in each direction the sensors point) and how fast it's going. The two numbers out are how hard to steer and how much gas or brake to give. At first every network is random, so most cars drive straight into the grass.
Nobody tells the cars how to drive. Instead they evolve. When every car has crashed, stalled or finished three laps, each one is scored by how far round it got (and a little extra for a quick lap). The best few go into the next generation unchanged. The rest of the new generation are children: two good parents are picked, their weights are mixed, and a few weights are nudged at random (that's the mutation). Do that a few dozen times and the cars find their way round. This is called neuroevolution, a kind of genetic algorithm.
Things to try
Fewer sensors. With one sensor pointing straight ahead a car can tell a wall is coming but not which way to turn. Try 1, then 3.
A new track. Change track and the same drivers carry over. Some cope at once because they learned to follow the road; others learned the old track by heart and crash at the first new bend. That's the difference between learning a general skill and overfitting.
Draw your own. Pick Draw one and drag a loop. Tight hairpins are much harder than wide sweeps.
Mutation. Too little and the cars stop improving once they're stuck on a bend; too much and the good drivers' children forget what their parents knew.
Hidden neurons. The brain has one hidden layer. One or two neurons can still learn a simple track. More neurons can learn more, but there's more to tune, so they don't always learn faster.
How it works
The road is a loop of points with a width. The page works out, once, how far every spot is from the road's edge, which makes the sensors fast: a sensor ray can jump ahead by that distance each step until it reaches the edge. Each car's network has one hidden layer of tanh neurons. Parents are chosen by a small tournament (the best of four picked at random), and about 3% of each generation are fresh random brains, so the search doesn't get stuck. Your settings, your own track and your best driver are saved in this browser; nothing is sent anywhere.