Figure This Out
Driving a car, assuming there’s no obstructions like pedestrians, cars, the odd elephant (or even normal elephants), can be achieved by hugging the left or right edge. What about Formula 1 cars?
Measuring from ahead, left, and right, what do we require to steer / accelerate / break?
Out of fairness for the virtual occupant, maybe a sense of speed, tyre squealing (slip), and lastly how much they are throwing the vehicle around (yaw).
Brain wise, actually, virtually nothing. Anyone willing to bet the house on ZERO hidden neurons?
It would be a safe bet. I am serious. Input > Output, no hidden neurons. And given it’s not braking, we only need the first 2. This is using FULL physics.
Here’s the example for a Go Kart.
steer = Tanh( 0.1873999983072281*visionLeft +0.9449499920010567*visionCentre -0.29230000264942646*visionRight +0.403250003233552*speedSensor -0.26080000400543213*slipSensor -0.527650011703372*yawSensor +0.08739999681711197); throttle = Tanh( 0.43549999967217445*visionLeft) +0.8208999801427126*visionCentre +0.009099990129470825*visionRight -0.084950000513345*speedSensor +0.5587999895215034*slipSensor -0.13870000839233398*yawSensor -0.5140000004321337); brake = Tanh( -0.8230500016361475*visionLeft -0.7856499999761581*visionCentre -0.30640000849962234*visionRight -0.3151999945657735*speedSensor +0.4446999989449978*slipSensor +0.1143999993801117*yawSensor +0.4443500004708767);
Let’s try to explain it, paraphrased from Claude:
┌─────────────────┬───────┬───────┬───────┐
│ Signal │ Min │ Mean │ Max │
├─────────────────┼───────┼───────┼───────┤
│ L beam │ 0.58 │ 0.74 │ 1.00 │
├─────────────────┼───────┼───────┼───────┤
│ C beam │ 0.00 │ 0.20 │ 0.63 │
├─────────────────┼───────┼───────┼───────┤
│ R beam │ 0.59 │ 0.77 │ 1.00 │
├─────────────────┼───────┼───────┼───────┤
│ speed │ 0.00 │ 0.48 │ 0.55 │
├─────────────────┼───────┼───────┼───────┤
│ slip │ −1.00 │ −0.06 │ 1.00 │
├─────────────────┼───────┼───────┼───────┤
│ yaw │ −0.10 │ 0.26 │ 0.45 │
├─────────────────┼───────┼───────┼───────┤
│ steer neuron │ −0.16 │ 0.02 │ 0.23 │
├─────────────────┼───────┼───────┼───────┤
│ throttle neuron │ 0.35 │ 0.63 │ 0.79 │
├─────────────────┼───────┼───────┼───────┤
│ brake neuron │ −0.94 │ −0.85 │ −0.73 │
└─────────────────┴───────┴───────┴───────┘
Braking. Firstly, why is there is no braking? The brake neuron is never positive, and it stays between −0.73 and −0.94. The cause is the left and right beams.
- The side beams always see grass. They never drop below 0.58, because the ±90° beams with a 200 px reach always hit the verge on this track.
- They swamp everything else. That gives about −1.1 from the left and right beams alone, against a maximum of about +0.1 from speed, slip and yaw. The brake can’t go positive.
- Brake and throttle are never on together. Inputs.Brake is 0 for the whole lap.
Throttle. Inputs.Throttle1 is exactly 1.5 on all 800 samples. The raw neuron is always between 0.35 and 0.79, which ×500 saturates at that ceiling meaning this lap has no partial throttle at all. The speed dips on the trace come from corner drag or sliding, not from the kart lifting.
- Throttle is always positive because the side beams are always high. Left and right contribute about +0.4 on top of the +0.30 bias, and yaw adds a little more.
- Yaw is positive almost all the time (mean +0.26), so this circuit turns one way.
Steering. The raw steer output is small (−0.16 to +0.23), but ×100 gives logged values up to about ±23. It’s a high-gain controller, so the kart is close to bang-bang on steering.
- Centre beam at 0.63 is where it matters. It only gets large in corners, and that’s what swings the steer positive.
- The ±90° beams behave like a lateral-offset sensor. The steer neuron needs very little else, and the centre beam only matters in corners.
Top speed. The speed input peaks at 0.55, so the speed scale is about twice the kart’s top speed. The speed terms are therefore small (about −0.13 in throttle at most).
It learned to drive flat out with steering as its only control, because the sensors give it no usable braking information. Shortening the beam depth, or narrowing the field of view so the side beams read 0 on a clear road, would give the brake neuron something to learn from.
Ah.
Claude says… Braking needs “a corner is coming and I’m too fast“, and nothing in the six inputs says that. If a centre beam only reads non-zero within 70 px of the verge, braking is late, and flat-out plus steering is cheaper.
Except it was a 200px beam, and thus has plenty of time to adjust.
To test out Claude’s theory, I set the beam length to less than half the width, and this happens. It veers slightly to left wall, when the centre beam detects it deflects 95 or so degrees. No surprise, Claude.

Claude then made the front facing beam 200px, so side beams can be reduced to less than half the width of the road whilst retaining a long view ahead.
No difference, Claude.
Claude:
- Reduce the badDriving weight from 10,000 to a few hundred.
- Lower the brake modulation from 100 to about 2 to 5.
- Braking becomes graded, so a small positive output gives a light brake and evolution can tune it.
- Braking might still not win. This is a small kart with strong tyre grip, so lifting or steering through a corner may be just as fast, and then a brake gets no reward.
It made NO difference, Claude, not even with my F1 cars. F1 cars brake hard, steer, accelerate hard.
I love AI assisted coding. The alternative telemetry, the driver-view*, lap-times, speed trace are beautiful. The ability to tweak the physics, the track-drawing spline, done without drama. But sometimes advice is flawed…
* = I had to change them, but Claude did the hard part of rotating a 2 dimensional from above into 3D. I made the LCD screen fixed to the steering wheel on the Go Kart, and dashboard on the FWD/RWD cars.
As we include tanks, and a 3D view needed to exist, Claude did this. I stopped short of adding tank physics.

Credit: Claude for the 3D view, speed trace, and adjusting my car physics for Formula 1, and FWD.
Is this the only way to train an AI to go around a 2D track? No, but it worked well. I’ve also created a version which uses reinforcement learning, and not only does it steer, it also overtakes cars. Maybe I’ll get around to posting about it soon.

