Little RallyA browser rally game

I taught a neural network to drive my rally game. Now it beats me.

Gravel stages built from a number, a real car physics model, pace notes read from the road itself, and seven AI rivals that learnt to drive inside the game. It runs in your browser with no install.

  • 24 / 26of my recorded stages where the AI is faster than me
  • Endlessstages, each one generated from a number in the link
  • 240 Hzcar physics, with no hidden forces
  • 35,000lines of JavaScript (22k game, 13k tools & trainers), no build step
Farmland
Hilltops
Snow
Night

Every frame here is the game rendering itself. Same roads, same physics, captured by a film tool built into the game.

Act one · The world

Every road starts as a number

Type a number into the link and you get a stage: its corners, hills, farms, bridges, weather and time of day. Send the link to a friend and they drive the exact same road.

riyad.ing/little-rally/#4821

The generator works like a road engineer. It shapes the land first, then lets the land choose the route: of up to twelve directions, it takes the one that needs the least digging for a 10% gradient. Then it cuts the road into the hillside, with banks, ditches and verges, and builds stone viaducts over dips and bridges over streams—with real arches you can drive right under.

  • No separate road. The road is part of the ground, refined from 4-metre triangles down to half-metre ones near the verge without cracks. Physics and graphics read the same surface, one draw call per 64-metre chunk, and trees between the camera and the car dither out so the low camera never loses it.
  • Pace notes from geometry. The notebook calls are worked out from the finished road's curvature and crests, never from the generator's intent, so a call always matches what the road actually does.
  • Ghosts in a link. Your best run is sampled five times a second, packed as second-order deltas and raw-deflated small enough to live in a URL, so a friend can race it with no server involved.
  • Lived-in countryside. Open-grazing stretches with loose sheep and rumbling cattle grids, plus hay bales, fence rails, snowmen and scattering spectators that come loose when you clip them.
4 left long 2 right tightens 6 left over crest hairpin left

Pace notes as the game draws them: procedural highlighter scribbles behind each number, heavier and inkier the tighter the corner.

Generated, not hand-built
Act two · The car

A real car you can drive with four keys

Dusk stage

No assists. No invented forces.

Drift comes from the throttle spinning the rear wheels. Lift off and the slide relaxes, because that is what the tyres do.

The car is a full rigid body on four simulated springs and dampers, with tyres that lose grip as they slide, load up as weight shifts, and plough a bank of gravel when dragged sideways so big drifts scrub speed instead of spinning out. It runs 240 times a second. There are three cars—the rear-drive Classic G4, the featherweight front-drive Kit 1600 with a helical limited-slip diff, and the four-wheel-drive Turbo 95—each with its own body, differential and gearing.

There are no audio files anywhere in the game either. Every engine note is two harmonically locked oscillators swept through fixed exhaust and intake formants in Web Audio, with an ignition-cut rev limiter, overrun exhaust pops, turbo flutter on the Turbo 95, filtered-noise gravel and wind, and a 16-step chiptune soundtrack that ducks for pace notes.

The hard part was the keyboard. You drive with W, A, S and D (or the arrows), and a key is either on or off, which on a real car means full lock at 120 km/h. So all the help lives in how a key is read, never in the physics: steering gets slower as speed rises, relaxed hands let the wheel self-centre the way a real one does, and holding a key into a slide is read as countersteer.

I tuned the feel with a tool I built into the game. It gives me two cars that differ in one way. I swap between them mid-corner and pick the one I prefer, and after a dozen rounds it has found my taste on eight dials: grip, tail, power, steering, turning, weight, hands and suspension.

In my tuning tool:1 2 swap cars mid-cornerEnter keep the one I like
Act three · The driver

Teaching a network to beat me

The AI in the game, Kite3, plays by my rules: the same car, the same gamepad controls, the same five-second penalty for a crash. It only sees the road ahead. It is faster than my best time on 24 of the 26 stages I recorded.

  • The road aheadEight points on the road, from a quarter second to seven seconds ahead at its current speed, so a hairpin reads the same at 80 km/h as at 140.
  • The ground past each edgeHow far it can run wide before a ditch, a drop, a tree or a wall.
  • WhiskersShort feelers from the bumper for whatever is right in front of it, even when it has spun round.
  • The seatSpeed, slip, weight shift, roll, and which wheels are touching the ground.

A tiny network, running live. Kite3 is just 177 inputs → 256 → 256 → 22 outputs—about 117,000 weights in plain JavaScript, making 30 decisions a second inside the browser.

Why it uses a virtual gamepad. Earlier networks with continuous steering and pedals wobbled down straights and pressed gas and brake together 12% of the time. Switching to 9 discrete stick notches and 5 pedal states—fed through the exact same caster-steering code a gamepad player gets—let it cleanly let go of the wheel and unlocked the jump to Kite.

Kite3 driving in Watch mode with the AI View open: cyan lookahead diamonds along the road, bumper whiskers, green throttle ribbon, and the live neural network panel showing inputs, neurons and controls
In Watch mode, pressing J (or tapping AI view) turns on Kite3's live X-ray: road lookahead diamonds, bumper whiskers, gas and brake trail, and real-time saliency lighting up whichever marker drove its last decision. Watch Kite3 live with AI view →

Five things it taught me

Lesson 1

The copycat

After evolving a tiny driver from scratch (Racer), I tried teaching a network by copying my driving. Because it could see its own last move, it learnt to repeat it. After a crash it braked, and kept braking forever. Hiding that input made it match me worse on paper and drive far better.

Lesson 2

Blame the braking point

In reinforcement learning, the network has to work out which moment caused a crash. Set up badly, it blamed the last third of a second, spent helpless in the trees. Stretching blame to three seconds back reached the braking point, and crashes fell from 0.7 to 0.2 a run.

Lesson 3

The luckiest round

A tiny nudge to the network's weights could flip a run from clean to a crash. My "best" network turned out to be the luckiest of 250 test rounds, not the best driver. Now every driver sits the same fixed test, on stages it never trains on, and I compare them over 300 paired runs.

Lesson 4

Stuck against a tree

Without a reset button, one network sat revving against roadside trees and never finished 28 of 300 runs. It had never needed reverse. I recorded my own escapes for it to learn from, and drills that start it nose-first into a tree stay in training for good. Skills it stops practising, it forgets.

Lesson 5

A 50-minute teacher

Nobody knew how fast the car could really go. So I built an offline iCEM trajectory planner that saves exact 240 Hz snapshots—even standing knocked-over hay bales back up—and searches 3 seconds ahead (plus a 2-second tail) on top of Kite every quarter second. It drives 9% faster than me, at 50 minutes of computing per stage. Kite3 is Kite coached by that planner, mostly on when to brake and when to floor it.

Results: my 26 recorded stages

Time over the game's point-mass ideal—an estimate of the road, not the true physical limit. Shorter is faster. Dashed is me; the striped bar is the offline planner.

Rule-based driverHand-written racing line
+25.9%
Pad5First network on a gamepad
+20.4%
MeGamepad, best of several tries
+15.5%
KiteReinforcement learning and drills
+12.9%
Kite3Kite, taught by the planner
+11.2%
The plannerOffline, 50 minutes a stage
+5.2%

Head to head on 60 stages it never saw, Kite3 beats Kite on 56. The planner is still about 6% faster than Kite3: some of what it works out by trying futures can't be seen from the driver's seat.

Race the whole family tree

In Rivals mode you race seven networks from this history. Before the start, a hidden page swaps three.js for a tiny math stub and quietly time-slices all seven headless runs down your stage—shifting each a few centimetres across the start line so no two races play out alike—then gives you live gaps and split times against them.

  • Racer2,400 weights evolved from scratch; the first brain to finish a stage.
  • Copy2Learnt by imitating my 26 recorded runs, once the copycat echo was cut.
  • Pro5Started from my driving, then evolved further for stage time.
  • RL4First reinforcement-learning driver (PPO), before the gamepad switch.
  • Pad5First brain on the discrete 9-notch gamepad stick and caster steering.
  • Kite177-input sight, 117k weights, hairpin dojo and tree-escape drills; the first to beat me.
  • Kite3Kite coached by the 50-minute search planner; faster than me on 24 of 26 stages.
The whole field, as ghosts
Before

It didn't always look like this

The first commit landed on October 13. Most of the world in the clips above grew over the next three days. Every picture here is an old version of the game from its history, run again on the same stage, in the same golden-hour light, with one fixed camera for each set.

The world fills in

On day one the hills were bare and the road was its own striped strip, laid on top. Overnight it was carved into the ground. By that afternoon there were farms, birches, telegraph poles, fences, cows and sheep, streams and bridges.

Then the land took over: it now picks where the road goes, so the last picture is a different road at the same point of the same stage.

October 13: bare green hills, a few pine trees and a wide striped gravel road Early October 14: the same corner with the road carved into the ground under a blue sky October 14 afternoon: the same corner with a farmhouse, a red barn, a silo and birch trees October 15: a new road through a birch grove with a windmill on the hill

The car

The first car was one boxy wedge with stripes. On October 15 it got wheel arches, flares and round rims.

Three days later it became three cars, each with its own body, handling and engine: the Classic G4, a rear-drive fastback; the Kit 1600, a front-drive hot hatch; and the Turbo 95, a four-wheel-drive turbo saloon.

The October 13 car: a boxy white wedge with orange stripes and no wheel arches
Oct 13The first car
The October 15 car: the same body with wheel arches, flares and round rims
Oct 15Arches and rims
The Classic G4, a white fastback with an orange stripe and a ducktail spoiler
Oct 18Classic G4
The Kit 1600, a short white hatchback
Oct 18Kit 1600
The Turbo 95, a saloon with a rear wing and a bonnet scoop
Oct 18Turbo 95

And along the way

  • Oct 1374 more commits on the first day: a daily stage, ghost cars, the endless road, chiptune music, night stages, and snow that cakes the car white.
  • Oct 16Pace notes became procedural highlighter scribbles, stroked heavier the sharper the corner.
  • Oct 17Hay bales, fences, snowmen, sheep and farm gates started coming loose when you hit them.
  • Oct 19The paddock became a campfire clearing, with stages built only once you hit Drive.
  • Nov 2The first neural driver learnt from scratch (Racer), alongside a 60 Hz recorder for my own runs.
  • Nov 4Live Brain View in 3D, discrete gamepad brains (Pad5), wider Sight V6, hairpin dojo and tree-escape practice.
  • Nov 5Kite beat my recorded times for the first time, and Rivals mode shipped so you can race the whole lineage in the browser.
  • Nov 6–12Built the frozen exam and the 50-minute iCEM search planner, coached Kite3 from its lessons, and launched Watch mode.
  • Nov 15The game learnt to film itself deterministically at 60 fps, with separated audio stems. The clips on this page come from it.

Your stage is ready.

Today's daily stage is the same road for everyone. Try to beat Kite3, or just let it drive and watch what it sees.

More things I made →