This project involves training a reinforcement learning agent to play the Snake game. The agent uses a Deep Q-Network (DQN) to learn optimal strategies and improve its performance over time.
game.py
: Contains the implementation of the Snake game, including the game logic and rendering.helper.py
: Includes helper functions, such as plotting results.model.py
: Defines the neural network architecture for the Q-Network and the QTrainer class for training.agent.py
: Implements the reinforcement learning agent, including methods for training, saving, and loading the model.arial.ttf
: A font file used for rendering text in the game.
- Clone the Repository:
git clone https://github.com/afrahshah/snake-rl.git cd snake-ai
- Install dependencies
pip install torch numpy pygame matplotlib
To start training the agent, run the following command:
ls -l
python agent.py
The training script will:
Initialize the game and the agent. Train the agent through multiple games. Save the model state after training.