Welcome to the DQN Self-Driving Car simulation project! This project is a reinforcement learning-based simulation where a self-driving car learns to navigate a race track using a Deep Q-Network (DQN). The simulation is built with Python and Pygame and allows users to train, evaluate, and monitor the performance of an autonomous agent in real-time. The goal is to explore how AI can learn driving behavior through rewards and trial-and-error.
The car is equipped with simulated sensors that detect distances to nearby obstacles in five directions. These sensor readings form the state input for the agent, helping it make navigation decisions such as when to turn or go straight.
The agent learns using a DQN, which approximates the optimal action-value function. Experience replay allows the agent to store and sample past experiences (state, action, reward, next state, done), improving learning stability and efficiency.
Once a model is trained, it can be saved as a .pth file. In evaluation mode, the agent runs using this trained model with a fixed epsilon value, allowing users to test performance without additional learning.
The simulation displays a live-updating graph that plots total rewards obtained per episode, helping users monitor the agent's progress and performance over time.
The simulation tracks laps completed by the car and calculates the time taken for each lap. This feature helps assess how efficiently the agent can complete a full circuit.
At the end of the session, a detailed summary is printed in the terminal. It includes the average episode reward, the best recorded lap time, and the total number of laps completed during the session.
The simulation supports loading custom track images (.png) and car sprites, allowing for experimentation with different maps and car designs.
# Clone the repository
git clone https://github.com/BarraHarrison/DQN-Self-Driving-Car.git
cd DQN-Self-Driving-Car
# (Optional) Create a virtual environment
python3 -m venv venv
source venv/bin/activate # On Windows use: venv\Scripts\activate
# Install the required dependencies
pip install -r requirements.txt
# Run the main simulation
python3 main.pyTo switch to evaluation mode, set EVAL_ONLY = True in main.py and ensure a model file exists in the checkpoints/ folder.
This project showcases how reinforcement learning can be applied to a simplified self-driving simulation. Through real-time feedback, reward tracking, and lap timing, users can observe how an AI agent gradually learns efficient driving strategies. It serves as both an educational tool and a stepping stone toward more advanced autonomous driving experiments.
Happy training! 🧠🚗