A Snake game implementation using Python and Pygame, featuring both interactive gameplay and AI learning capabilities through reinforcement learning.
- Classic Snake gameplay with keyboard controls
- AI mode using Reinforcement Learning (PPO algorithm)
- Training mode to teach the AI
- Configurable grid size and game speed
- Score tracking
- Debug mode for development
- Python 3.12.x
- Poetry 1.8.x
Install dependencies using Poetry:
poetry install
Activate the virtual environment:
poetry shell
The game supports three modes:
Play the classic Snake game using arrow keys:
python src/main.py int
Watch the trained AI play Snake:
# Using latest checkpoint (default)
python src/main.py ai
# Using specific checkpoint training run
python src/main.py ai --checkpoint 20241224_1017
Train the AI model:
python src/main.py train
- Add
--debug
flag to enable debug visualization:
python src/main.py int --debug
Monitor the training progress using TensorBoard:
tensorboard --logdir ./.tmp/tensorboard
src/main.py
- Main entry pointsrc/game.py
- Core game logicsrc/snake.py
- Snake entity implementationsrc/ai_controller.py
- AI training and executionsrc/envs/snake_env.py
- Gymnasium environment for AI