This repository is a hands-on Deep Reinforcement Learning project combining a playable 2D racing simulator with a DQN agent trained on a custom Gym-like environment.
About this README
The original documentation was written as a very detailed, tutorial-style French README.
This English README is a condensed, “project-first” version.
If you want the full deep dive (RL foundations + why each design choice matters), see THEORY.md.
The original French long-form version remains available as README_FR_LEGACY.md.
Cars_DQLN is a 2D racing simulator where an agent learns to drive to a finish line using Deep Q-Networks (DQN).
The goal is to bridge theory and practice: you can play manually, test a trained agent, or train a new agent on different tracks through an interactive menu.
- The car observes the world through 7 ray-based distance sensors (a simple Lidar-like perception).
- A custom environment
RacingEnvexposes the classic RL loop:step(action) → observation, reward, done. - Observations are the sensor distances; actions control acceleration + steering.
- Rewards encourage progress / staying on track, and penalize crashes / leaving the track.
- Training uses Stable-Baselines3 (DQN):
train_agent.pytrains and saves a modeltest_agent.pyreloads a model and runs inference
For the detailed RL foundations (Q-learning → MDPs → Bellman → DQN + replay buffer + target network) and the exact reasoning behind design choices, see THEORY.md.
pip install -r requirements.txtpython main.pyFrom the menu you can typically:
- Play manually
- TEST (run a trained agent)
- TRAIN (start a new training session)
Notes: Use arrow keys to navigate the menu. You can toggle sensor visualization (e.g., key v, depending on the menu options / version).
-
Class & dependency diagrams (auto-generated):
THEORY.md — RL foundations + Q-learning → DQN, with explanations and visuals & explained programm. README_FR_LEGACY.md — original French long-form documentation (historical / complete)
- Deep Reinforcement Learning Hands-On, Maxim Lapan, Third Edition, Packt — A practical and easy-to-follow guide to RL, from Q-Learning and DQNs to PPO and RLHF.
- Pygame Documentation 1 : https://he-arc.github.io/livre-python/pygame/index.html
- Pygame Documentation 2 : https://www.pygame.org/news
- OpenAI Spinning Up (Reinforcement Learning guide) : https://spinningup.openai.com/en/latest/
- Gym Documentation : https://www.gymlibrary.dev/
- Stable-Baselines3 (Reinforcement Learning Library) : https://github.com/DLR-RM/stable-baselines3
- YouTube Videos :
Project built with contributions from Kérian Dorey (game setup + oral presentation) and Julien Escot (agent, documentation, additional features).


