This project showcases an AI that learns to drive a car in my 2D driving environment using the deep Q-learning algorithm. No hardcoded pathfinding — the agent improves by trial, error, and reward-based learning. 🧠📈
🤖 Uses Deep Q-Learning with experience replay and epsilon-greedy exploration
🧱 Neural network approximates Q-values for discrete actions (e.g., accelerate, turn left/right)
Here is an image of what it looks like :
⏳ Training is unstable at first — the car often spins out or crashes quickly — but over time, it learns to stabilize, turn properly, and sometimes follow simple roads or avoid walls.
🎛️ Hyperparameters (learning rate, epsilon decay, reward shaping) have a huge impact on learning performance.
Here, we can see that over 100 steps, the best path have been found (in just more than 5 min).
It is more hesitant for the borrowed path but adapts better to different circuits than Genetic algorithm such as AI_driving_genetic_version !
🎮 The AI controls a car in a Pygame environment with basic physics and obstacles.
🧠 It uses a Deep Q-Network to estimate the best action to take from any given state.
🧾 Inputs include distance to next checkpoint, velocity, distance to obstacles, and relative angles to next checkpoint.
🎯 Rewards are given based on life time, distance to the next checkpoint, avoiding collisions, velocity to encourage speed and reaching checkpoints.
├── Images/ # Images for the README
│
├── dqn_model.pth # Saved model checkpoint
│
├── ia.py # AI logic
├── main.py # Project entry point
├── drive.py # Driving game implementation
│
├── LICENSE # Project license
├── README.md # Main documentationClone the repository and install dependencies:
git clone https://github.com/Thibault-GAREL/AI_driving_DQN_version.git
cd AI_driving_DQN_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 torch numpy pygame
python main.pyI code it without any help 😆 !
Code created by me 😎, Thibault GAREL - Github

