Self-driving sim in pure NumPy: 9 raycasts + genetic algorithm clears unseen track
rsasaki0109 · x · 2026-08-29
Detailed writeup of the ApexDrive project: a self-driving simulation in pure NumPy + Pygame that cleanly completes an unseen 5,000px track with 5 obstacles, hairpins and chicanes. Key points:
- Perception: 9 raycast distance sensors from the bumper and corners; 13-feature input (ray distances, left-right clearance balance, lookahead, speed, turn rate).
- Brain: custom MLP (13→18→14→2) with pure matrix multiplications and Tanh activations for continuous steering and throttle/brake.
- Training: genetic algorithm instead of backprop — tournament selection, arithmetic crossover, elitism, Gaussian mutations — evaluated across multiple track types per generation to prevent memorization.
- Control & physics: dynamic lookahead braking (140 km/h down to 55 km/h before corners), low-pass steering filter, and an ADAS-style repulsive steering bias within 15px of barriers.
The author says writing the vector math, line intersections and evolution logic from scratch made autonomous-control mechanics far clearer than calling library abstractions. Code is open-sourced on GitHub.
More from coding & agent
- Grok launches shareable Bot templates for AI employees like sales and research agents — minchoi · 2026-08-29
- GLM-5.3 Launches on Together AI with High Reasoning Efficiency and Lower Cost — togethercompute · 2026-08-29
- Can agent Skills be repurposed to fragment repo context beyond 'things to do'? — amzwC137 · 2026-08-29
- llmog: Local tool for automatic dataset annotation and reclassification using LLMs — SavingsWeather1659 · 2026-08-29
- 4 Claude agents competed to build a music video editor, judged blindly by 3 more — BuffaloConscious7919 · 2026-08-29
- Firecrawl Developer Index launches on OpenAI plugin marketplace — devdigest · 2026-08-29