This project implements and compares two reinforcement learning algorithms (Q-Learning and Deep Q-Learning) for training an AI agent to play the Snake game.
- Python 3.10
- Required packages:
pip install -r requirements.txt
- Navigate to the project root directory
- Install dependencies:
pip install -r requirements.txt
- Enter any experiment directory (e.g.,
growing_snake_deep_q_learning
) - Run the training and testing script:
python main.py
Key files in each experiment directory:
File | Description |
---|---|
agent.py |
Implementation of the learning agent (type specified in directory name) |
helper.py |
Visualization and utility functions |
main.py |
Training and testing pipeline |
snake.py |
Game environment (Gym-like implementation) |
state_setting.py |
State representation configuration (customizable inputs for agents) |
Directory: no_growing_snake_q_learning
Directory: growing_snake_q_learning
- Standard game rules with snake growth
- Performance plateaus around score 40 due to algorithm limitations
Directory: growing_snake_deep_q_learning
- Uses neural network
- State representation:
- 5x5 grid around head (values: 0=empty, -1=food, 1=head, 2=body, 3=wall)
- 4-direction food position vector
- 4-direction movement vector
- GPU acceleration available (
agent_gpu.py
) - Shows promising results with extended training
- State Settings: Modify
state_setting.py
to change agent inputs - GPU Support:
- Use
agent_gpu.py
for GPU acceleration (requires CUDA) - Use
agent_cpu.py
for CPU-only operation
- Use
- Environment Constraint: Game width must equal height (required by state representation)
- Hyperparameter Tuning: See
evaluate_agent.py
for optimization experiments (AdamW + Xavier initialization recommended)