An AI agent that learns to play the classic Snake game using Deep Q-learning (DQN) with PyTorch and Pygame.
- AI Training: Implemented with the Deep Q-Network (DQN) algorithm.
- Live Visualization: Real-time gameplay screen to observe the AI's learning progress.
- Performance Tracking: Plots scores and mean scores to track learning progress.
- Language: Python
- Libraries: PyTorch, Pygame, NumPy
1. Clone the repository:
git clone https://github.com/masddffee/Machine-Learning-Snake.git
cd Machine-Learning-Snake2. Install dependencies:
# It is recommended to use a virtual environment
python -m venv env
source env/bin/activate # On Windows use `env\Scripts\activate`
pip install torch pygame numpy matplotlib3. Run the training script:
python agent.py4. Run the game with a pre-trained model:
python play_snake.py # Make sure a model.pth file exists