Skip to content

All work

Self-Driving Car with Deep Reinforcement Learning: DQN and PPO

A racing simulator in which a DQN agent and a PPO agent learn to drive from seven ray-cast distance sensors, trained side by side on a split screen, on tracks drawn in a built-in editor.

Year
2026
Kind
Reinforcement Learning
Role
Developer
Duration
December 2025 to January 2026
With
Personal project
For
Personal project
Problem
Comparing two reinforcement-learning algorithms fairly needs the same car, the same track and the same sensors, and a way to watch both learn.
Approach
A custom physics model with smooth steering, nine discrete actions, seven distance sensors, and a comparison trainer that runs both agents at once.
Result
Both agents can be trained, evaluated on tracks they have not seen, and compared on success rate, reward and lap time.

Built with

  • Python
  • PyTorch
  • Pygame
  • TensorBoard
Self-Driving Car with Deep Reinforcement Learning: DQN and PPO: cover image

Two ways of learning, hard to see on paper

DQN and PPO learn in different ways: one is off-policy and value-based, the other on-policy and actor-critic. Reading about the difference is not the same as watching it. This project puts both in the same car on the same track.

The car, its sensors and the two agents

The car. Steering uses angular velocity with damping rather than snapping to a direction. The agent chooses one of nine actions: left, straight or right, each at slow, normal or fast speed. So it has to learn speed control and braking, not only steering.

The sensors. Seven rays are cast from the car at angles from minus 90 to plus 90 degrees. Each returns a normalised distance to the wall, and that vector is the network's input.

The agents. DQN uses experience replay with a 20,000-step buffer, Double DQN for stable value estimates and epsilon-greedy exploration from 1.0 down to 0.1. PPO uses generalised advantage estimation (lambda 0.95), a clipped surrogate loss (epsilon 0.2) and an entropy bonus.

The track builder. Tracks are drawn in a visual editor with grid snapping, zoom and pan, and smoothed with Chaikin's algorithm. Caching at three levels keeps training responsive on tracks of about 40,000 points.

Side by side on one track

The comparison trainer runs both agents at once on a split screen. A separate evaluation script tests a trained model, including on a track it was not trained on, and reports success rate, average reward, lap time and steps per episode.

In motion

Twelve seconds of real training on a CPU: DQN on the left, PPO on the right, on the same track. The coloured lines are the seven distance sensors.

Screens