Skip to content

Thibault-GAREL/AI_driving_genetic_version

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🚗 Driving AI Using Genetic Algorithm

Python Numpy Pygame

License
Contributions

Driving_NEAT_gif

📝 Project Description

This project features an AI that learns to drive with my driving game autonomously using genetic algorithm (without NEAT). No hardcoded strategies — the agent improves over generations through genetic mutations and natural selection. 🧬🤖


⚙️ Features

🔄 No supervised learning – only evolution by fitness

🧠 Networks evolve weights with crossover and mutation but not topologies (like NEAT)

📊 Real-time simulation with visualization

🏆 Tracks best fitness, average scores, and generation and save best brains

Example Outputs

Here is an image of what it looks like :

Image_snake Image_snake

Here it's when it starts with all the population alive : Image_snake


⚙️ How it works

🕹️ The AI controls a car (red when alive ❤️, gray when dead 🩶 and green when the best 💚) in a classic grid-based 🐍 Snake game.

🧬 It evolves over time : networks mutate, reproduce, and get selected based on performance (fitness).

👁️ Visual interface shows the best car live as it learns.

🗺️ Schema

💡 Here is a schema for a better explanation :

NN_snake

🧪 You can also withdraw the display for a quicker training (show = False in drive.py) and load a brain (load = True in drive.py and filename = "best_brainXX.npz" in ia.py) !

🔥💻 In 5-10 min, the car is starting to have the best trajectory !


📂 Repository structure

├── Img/
│
├── best_brain.npz
├── best_brain2.npz
├── best_brain__check4.npz
│
├── drive.py
├── ia.py
├── main.py
│
├── LICENSE
├── README.md

💻 Run it on Your PC

Clone the repository and install dependencies:

git clone https://github.com/Thibault-GAREL/AI_driving_genetic_version.git
cd AI_driving_genetic_version

python -m venv .venv #if you don't have a virtual environnement
source .venv/bin/activate   # Linux / macOS
.venv\Scripts\activate      # Windows

pip install numpy pygame

python main.py

📖 Inspiration / Sources

I code it without any help 😆 !

Code created by me 😎, Thibault GAREL - Github

About

AI learns to drive with genetic mutation

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages