Auto-Parking
Sixty baby cars, sixty random brains. Each must roll into the green bay and stop inside the lines. Press Play!
How the best half did, round by round
Checkpoints — the champion car from each round. Tap to watch it park in today's lot.
How it works
Thirteen senses
Each car feels where the bay is, which way it points, how fast it is rolling, and has six distance sensors like a real car's parking beeper: three in front, three behind.
A tiny brain
Those numbers go into a small brain with two answers: how far to turn the steering wheel, and whether to push forward or reverse.
Best parkers win
Getting close, lining up with the bay, being inside the lines, and stopping all earn points. Crashing loses points. The best cars become parents.
Copy with changes
Babies get their parents' brains with small random changes. Some changes help. Those babies park better next time.
Make the lot harder
Add parked neighbours or posts. Old tricks stop working, scores drop, and the cars have to find new tricks.
What just happened?
- In round 1 the cars drove in circles, hit the wall or shot past the bay. Nobody told them how to steer into a parking spot.
- Round after round, cars that happened to head for the bay and slow down had more babies, so the whole fleet learned to park.
- Challenges changed the lot. Scores fell, then climbed again as the cars found new tricks. That is adapting.
- Real self-parking cars use cameras and distance sensors too. Most use a hand-designed planner plus a controller; some research systems learn to park from reward alone, like this.
For grown-ups: what's really going on
This is neuroevolution: a population of 60 small feed-forward networks [13 → 12 → 2] (tanh) improved by a genetic algorithm, with no gradients and no labelled data. The car is a kinematic bicycle model, so it can't slide sideways: it must plan a curved path, which is why parking is a classic motion-planning problem.
- Physics: speed follows throttle with drag, braking is stronger than accelerating, and the heading changes by
v / L · tan(steer)each step (wheel-baseL). Steering turns the front wheels up to about 31°. At speed 0 the car cannot turn, so the brain has to roll while steering. - Inputs (13): the bay's position in the car's own frame (ahead / to the side), sine and cosine of the angle between the car and the bay's axis, speed, the bay's position in the lot's frame (left/right, up/down), and six range sensors (ray-casts, like ultrasonic parking sensors) at 0°, ±40°, 180° and 180° ± 40°.
- Parked means: every sampled point on the car body inside the bay (2.5 px tolerance), the car within about 17° of straight, and speed below 0.2 for two-thirds of a second. Forward-in and reverse-in both count.
- Fitness: shaped reward, summed over two random lots per round (one shown, one scored in the background): how far it got toward the bay, the best moment of "close, lined up, inside, and slow" during the drive, where it ends up, a large bonus for parking (more if quick) and a penalty for crashing that is bigger the closer it got (so ramming the back wall is not rewarded). Without the slow-down term, cars learn to speed into the bay and hit the wall.
- Genetic algorithm: the top 8% are kept unchanged (elitism); the rest are children of the top quarter (30% uniform crossover) with Gaussian mutation whose size is spread from small to large.
- Why the default bay is open: in my Node tests, evolving a parker among parked neighbours from scratch was much slower than learning in an open bay first, then adding neighbours. The same is true of many learned controllers: curriculum learning starts easy and makes the task harder as the skill improves, which is what the Challenges buttons let you do.
- The classic alternative: real parking assist plans a path with geometry (for example arcs and clothoids, or Reeds–Shepp curves, which are the shortest paths for a car that can drive forward and backward) and follows it with a controller. Reinforcement-learning parking systems exist in research and use far more data and compute than this demo.