What this project is about

Cover image of the self-parking car evolution blog post showing cars maneuvering into a parking spot
The blog post's cover illustrates the self-parking car evolution project, showing cars navigating a parking lot.trekhleb.dev

The opening paragraph introduces the Trekhleb blog post and its TypeScript implementation of a genetic-algorithm parking car, so the cover image gives readers an immediate visual anchor for the project.

The Trekhleb blog post from September 2021 walks through teaching a car to park itself using a genetic algorithm. The project is implemented in TypeScript and the complete source occupies under 500 lines of code.

How the self-parking car works

The car is equipped with eight distance sensors—"eyes"—each reporting obstacle distance in a range of 0–4 meters. Sensors refresh every 100 milliseconds; a reading of 0 means no obstacle is detected, while small positive values indicate proximity. The car has two "muscles": an engine muscle that controls forward, backward, or neutral movement, and a steering wheel muscle that turns left, right, or goes straight while moving. Each muscle receives one of three signals (–1, 0, or +1) every 100ms.

The car's "brain" consists of two linear polynomials, one governing the engine signal and the other the steering signal. Each polynomial takes eight sensor values as variables and nine coefficients as parameters (eight products of coefficient×variable, plus one constant term added without multiplication). The 18 coefficients together define the car's behavior and form its genome.

Genome structure

The 18 decimal coefficients are each converted to a 10-bit binary number (1 sign bit, 4 exponent bits, 5 fraction bits), yielding an 180-bit genome (18 coefficients × 10 bits). This means the car's complete DNA consists of 180 zeros and ones.

Diagram showing floating point decimal numbers converted to binary representations
An example conversion of floating-point coefficients into the binary form used in the car's 180-bit genome.trekhleb.dev

The genome-structure paragraph explains how each of the 18 decimal coefficients is encoded as a 10-bit binary number, and this conversion diagram shows exactly that encoding step.

Evolution process

At the start, cars receive random genomes, producing erratic behavior. After approximately 40 generations, cars begin learning what self-parking entails and approach the parking spot, though they may still hit other cars or fit the spot imperfectly. The project provides a browser-based evolution simulator where users can train cars from scratch, adjust genetic parameters, or inspect the best-performing genome's coefficients and values.

First generation cars with random genomes driving erratically and colliding in the parking lot
The first generation of cars, seeded with random genomes, behaves erratically and rarely parks successfully.trekhleb.dev

The evolution paragraph describes how cars start with random genomes that produce erratic behavior, and this animation of the first generation demonstrates that vividly.

Fortieth generation cars learning to maneuver into parking spots without colliding
By the 40th generation, cars have begun learning how to park themselves, approaching the target spot more reliably.trekhleb.dev

The same evolution paragraph notes that after roughly 40 generations cars begin to understand self-parking, and this animation captures that stage of development.

What remains uncertain

The source does not report exact parking-success rates across generations, nor does it specify a termination condition or final performance benchmark. The blog mentions that the simple polynomial brain limits the car's ability to generalize to unknown surroundings, but quantitative results are not provided.

Evidence

1. The genetic algorithm evolves car genomes over generations, with approximately the 40th generation marking the point where cars start learning self-parking behavior. This is supported by the primary source blog post (excerpt noting "this is only the 40th generation since the creation of the world for them") and the GitHub repository (support-2) whose description states cars start learning by the 40th generation.

2. The car's brain is implemented as two linear polynomials with 18 total coefficients, and when each coefficient is encoded as 10 bits the complete genome is 180 bits. This is supported directly by the primary source's detailed explanation of polynomial structure, coefficient conversion, and genome encoding.

Each claim is mapped only to the exact, directly relevant supplied source IDs. No HN discussion, comments, or unrelated sources are cited.