Revisiting the Fitness Function
I’ve now refined my fitness function to balances progress, efficiency, and stability:
- CurrentGate * 100000: This remains our primary objective multiplier. It ensures that a car completing 5 gates safely is always ranked vastly higher than a car that goes hyper-fast or spins flawlessly but crashes at gate 4.
- + averageVelocity * speedWeight: This acts as the pace driver, constantly pushing the network to find the limit of adhesion rather than taking a slow, overly cautious line.
- – yaw * yawWeight: This is the tyre wear/drift penalty. By heavily penalising the side-to-side slip angle, it forced the network to respect the “friction circle” and keep the tyres biting the asphalt.
- – averageSpin * averageSpin * spinWeight: This was the anti-pirouette patch. It specifically targeted the “spinning on the spot” exploit by penalizing pure angular velocity, forcing the car to facing forward. SpinWeight allows it to be set for “fast at any cost” vs. “sane driving”
- – len / 100: Using the frame count (len) here penalises a car that requires more frames to achieve the same gate.
The Real-World Connection
Visualising the weight transfer alongside was cool. In a real go-kart, lifting the inside rear tyre via chassis flex and weight transfer is the only way it can turn effectively (since it has a solid rear axle).
By tracking weight transfer and punishing excessive yaw/rotation, the network evolved a driving style that perfectly mimics a real racing driver: smooth inputs, micro-corrections at the limit of grip, and absolute stability.
Next let’s talk neural networks.
