This project implements a reinforcement learning approach to train an AI agent to play the classic Snake game using Deep Q-Learning (DQN).
- Manual gameplay mode
- AI training with Deep Q-Network
- Dynamic speed control
- Automatic model weight saving and loading
- Pygame-based visualization
- Python 3.8+
- Libraries:
- pygame
- torch
- numpy
normalGame.py
: Manual gameplay modetrain.py
: AI training scriptSrc/snake_trainer.py
: Main training logicSrc/snake_enviroment.py
: Game environmentSrc/model/_3.py
: DQN model definition
- Uses epsilon-greedy exploration strategy
- Implements experience replay
- Periodically updates target network
- Saves model weights every 100 episodes
python normalGame.py
python train.py
- Up/Down Arrow: Adjust training speed
- Spacebar: Pause/Resume training
- Weights automatically saved in
model_weights/
- Latest weights loaded at training start
MIT License