← back to projects

Self-Driving Car with Neural Networks and Genetic Algorithm

A C++ and SFML simulation where a population of cars learns to drive through evolution, one generation at a time.

Self-driving car project preview

What is this project?

This project is my 2D self-driving car playground built from scratch in C++ with SFML. The main idea is simple: each car starts with a small random brain, drives inside a map, and tries not to crash. The better cars survive and pass their traits to the next generation.

I wanted this to stay minimal and educational, so instead of relying on heavy frameworks, I kept the core pieces explicit: sensors, neural network decisions, fitness scoring, and a genetic algorithm loop. That made it easier to inspect mistakes and understand why one generation performs better than the previous one.

How does the learning loop work?

Every car uses wall sensors and feeds those distances into a tiny neural network. The network outputs control values like steering and speed. If the car hits a wall, it is out. If it travels farther without crashing, it earns higher fitness.

After each round, the best cars are selected as parents. Their parameters are combined through crossover, then slightly perturbed by mutation. This cycle repeats for many generations, and the behavior gradually improves from random motion to more stable driving.

The map setup in the repo uses a 1280 x 720 image where black pixels represent walls. Keeping this format fixed made map experiments easier and gave a clear baseline for evaluating whether changes in evolution strategy really help.

What I learned and what is next

The most interesting part for me was seeing how much behavior can emerge from very simple rules. Even with a compact neural model, selection pressure alone can produce visible improvements over time. It also reminded me that debugging simulation logic is mostly about instrumentation, not guesswork.

The next upgrades I want are similar to what I listed in the README: richer tracks, better network visualization, saving/loading top performers, and cleaner speed indicators during runs. Those additions should make comparison across experiments much more practical.

Check out the project's Repo ↗

Image Gallery

Placeholder image for future simulation screenshot
Placeholder for training view (replace later).
Placeholder image for neural network or debug panel
Placeholder for sensors and neural output visualization.
Placeholder image for generation comparison
Placeholder for generation progress comparison.