Self-Parking Cars Evolved with Genetic Algorithms in 500 Lines

A breakdown of how simple linear models and evolutionary computation can teach virtual vehicles to park autonomously.

GeoDetect PipelineSeptember 28, 2026
Share

Overview

A new open-source project demonstrates that autonomous vehicle logic can be distilled into approximately 500 lines of code using genetic algorithms. The Self-Parking Car Evolution Simulator allows users to watch a digital vehicle learn to park itself from scratch, evolving its decision-making processes generation by generation.

This guide explains the underlying architecture of the system, breaking down how simple "muscles" and "eyes" are coordinated by an evolving "brain." While the implementation is written in TypeScript, the conceptual framework offers a clear, accessible entry point into the world of evolutionary computation and autonomous control systems.

The Evolutionary Process

The core of the project relies on a genetic algorithm to optimize a car’s behavior. Rather than hard-coding every possible driving scenario, the system creates a first generation of cars with random genomes. These initial vehicles behave chaotically, often failing to move toward their target.

The simulation begins with a population of cars, each possessing a unique genetic makeup. Over successive generations, the algorithm selects the fittest performers—those that come closest to the parking spot without crashing—and breeds them. This iterative process mimics natural selection, gradually refining the vehicle's ability to navigate complex environments.

By approximately the 40th generation, a notable shift occurs. The cars begin to understand the objective of self-parking, making deliberate moves toward the designated spot. While they may still collide with obstacles or fail to align perfectly, this milestone demonstrates the viability of evolutionary strategies for solving navigation problems.

The cars are hitting some other cars along the way, and also are not perfectly fitting the parking spot, but this is only the 40th generation since the creation of the world for them.

Architectural Components

The simulator simplifies autonomous driving into three distinct subsystems: sensors, actuators, and a control function. This modular approach makes the complex task of self-parking understandable and reproducible.

Sensors and Perception

The car is equipped with eight distance sensors acting as its eyes. These sensors scan the immediate surroundings in a 0-to-4-meter range, reporting data every 100 milliseconds. Each sensor outputs a floating-point value between 0 and 4, where 0 indicates no obstacle and values closer to 4 signify an imminent collision risk.

This sensory input provides a simplified but effective representation of the car’s environment. By converting spatial data into numeric arrays, the system can process obstacle proximity without the computational overhead of full lidar or camera recognition.

Actuators and Movement

To move, the car utilizes two types of muscle signals:

  1. Engine Muscle: Controls forward (+1), backward (-1), or neutral (0) motion.
  2. Steering Wheel Muscle: Controls left turn (-1), right turn (+1), or straight path (0).

These signals are discrete, forcing the car to make clear, binary-like decisions at each interval. This limitation is intentional, as it reduces the search space for the genetic algorithm, allowing the brain to converge on a working solution more efficiently.

The Neural Brain

The central component is the brain, a pure function that maps sensor inputs directly to muscle outputs. The formula is straightforward:

movements = f(sensors)

Every 100 milliseconds, the brain receives an array of eight float values. It processes these inputs and outputs two integers representing the engine and steering signals. A secondary function, brainToMuscleSignal, converts raw neural outputs into the acceptable -1, 0, or +1 range required by the muscles.

The genome of each car essentially encodes the weights and biases of this function. With 180 bits of genetic data, the algorithm explores different combinations to find the optimal response to various sensor configurations.

Training from Scratch

Users can launch the simulator to observe the evolution in real-time. The interface allows for manual control using keyboard inputs (WASD), providing an intuitive understanding of how signal values affect vehicle dynamics. From there, users can initiate training from scratch, adjusting genetic parameters to see how different mutation rates or selection pressures impact the learning curve.

The project serves as both a technical demo and an educational tool, proving that sophisticated autonomous behaviors can emerge from simple, evolutionary-driven rules.

Share

Sources

Tools mentioned