This project implements a reinforcement learning (RL) agent that learns to play the classic Snake game using a neural network and Q-learning. The project consists of three main components:
- Game: The implementation of the Snake game with basic logic, rendering, and user input handling.
- Model: The neural network architecture and the training logic for the RL agent.
- Agent: The RL agent that interacts with the game, trains the model, and learns from its experience.
game.py
: Contains theSnakeGameAI
class, which implements the Snake game logic, including rendering, game rules, and user input.model.py
: Contains theLinear_QNet
class, a simple neural network architecture for Q-learning, and theQTrainer
class, which handles training and optimization.agent.py
: Contains theAgent
class, which implements the RL agent, memory management, and action selection.helper.py
: Contains utility functions for plotting training results, used to visualize scores during training.README.md
: This file, providing an overview of the project.
To run this project on your local environment, ensure you have Python installed, along with the necessary dependencies like PyTorch
, Pygame
, and Matplotlib
. You can set up a virtual environment to manage dependencies and keep your environment clean.