Game Lab · Neuroevolution

Lane Keeper

Sixty baby cars, sixty random brains. Each must follow the winding road and stay between the white lines. Press Play!

How the best half did, round by round

Road driven (%)Finished the whole road (%)A challenge started

Checkpoints — the champion car from each round. Tap to watch it drive today's road.

How it works

Nine senses

Each car feels how far it is from the middle of the lane, which way it points, its speed, where the road is at three spots ahead, any cone coming up, and how sharply the road bends right now.

A tiny brain

Those numbers go into a small brain with two answers: how far to turn the wheel, and how fast to go.

Go the furthest

Cars earn points for each bit of road they cover, a bonus for finishing, and lose a little for wobbling away from the middle. Leaving the lane or hitting a cone ends the run.

Copy with changes

Babies get their parents' brains with small random changes. Smoother steering means more babies.

Change the road

Add rain, hairpins or cones. Old tricks stop working, and the cars have to find new ones. Every round has a brand-new road too.

What just happened?

For grown-ups: what's really going on

This is neuroevolution: 60 small feed-forward networks [9 → 10 → 2] (tanh) improved by a genetic algorithm, with no gradients and no labels. The car is a kinematic bicycle model. Staying in a lane is a classic path-following control problem.

  • The road: a path whose curvature is a sum of three sine waves with random phase and size, eased in over the first 120 px. Each round (and each scoring pass) draws a new road, so evolution cannot memorise a track and has to learn a general steering policy. Random roads like this cross themselves about 40% of the time (85% with hairpins), which would let a car hop onto another stretch, so a road is redrawn until no part comes within a lane-width of a far-away part.
  • Inputs (9): lateral offset from the lane centre, heading error against the road direction, speed, the lateral position of the road centre in the car's own frame at three look-ahead distances (34, 78 and 130 px, the white dots), the sideways offset and distance of the nearest cone in the next 140 px, and the current road curvature.
  • Outputs (2): a steering command (tanh, up to about 35° of wheel angle, low-pass filtered because real wheels take time to turn) and a target speed between a minimum and the speed limit.
  • Failure: any part of the car body leaving the lane, or hitting a cone, ends the run. Fitness: road covered (up to 100), plus a finishing bonus (more for finishing early), minus a small penalty for the average distance from the centre line, summed over two random roads per round.
  • Genetic algorithm: the top 8% survive unchanged; the rest are children of the top quarter (30% uniform crossover) with Gaussian mutation whose size is spread from small to large.
  • Measured in Node (best half, one run per setting): on the default road about 90% finished by round 10 and 100% by round 30. With hairpin bends, 100% finished by round 10. Cones were much harder: after 30 rounds only about 13% finished and the best half covered about 55% of the road, because dodging needs a precise sense of where the cone is relative to the lane.
  • The classic alternative: a pure-pursuit or Stanley controller steers directly toward a look-ahead point on the path, using a few lines of geometry. It works very well, and is in many real lane-keeping systems. Evolution here has to rediscover something like it from scratch, which shows why the look-ahead points matter so much.