This project showcases an AI that learns to drive a car in a 2D environment using the deep Q-learning algorithm. No hardcoded pathfinding โ the agent improves by trial, error, and reward-based learning. ๐ง ๐
๐ฎ 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.
๐ค 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 :
- Python 3.x ๐
- pytorch for neurons ๐ง
- numpy for tracking and plotting results ๐
- pygame for visualization ๐ฎ
โณ 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).