This project implements the classic Snake Game using Pygame and trains an AI agent using Deep Q-Learning (DQN) with PyTorch.
The agent learns to play Snake by trial and error, improving over time by maximizing its score.
- Snake game built using Pygame 🎮
- AI agent using Deep Q-Learning (DQN) 🤖
- Neural Network built with PyTorch
- Experience Replay & Short/Long Memory Training
- Live matplotlib plots of training progress 📈
- Model saving & loading
. ├── snake_game.py # Snake game environment (Pygame)
├── agent.py # RL agent (Deep Q-Learning logic + training loop)
├── model.py # Neural network model & trainer
├── helper.py # Plotting functions
├── model/ # Saved trained models
└── README.md # Project documentation
python -m venv venv source venv/bin/activate # For Linux/Mac venv\Scripts\activate
pip install -r requirements.txt
python agent.py
The game will run in the background The AI will start training Training progress will be shown in a plot
The AI starts with random moves and gradually learns to avoid collisions and eat food. You’ll see: Score per game Mean score trend improving over time