AI agent learns how to play Snake using Deep Reinforcement Learning (PyTorch).
The goal of this project is to develop an AI Bot able to learn how to play the Snake game from scratch.
- Implemented the Snake game from scratch using pygame library
- Implemented a Deep Reinforcement Learning algorithm : Q-Learning and use a neural network to approximation the policy. Besides, I use epsilon-greedy exploration.
- Visualized how the Deep Q-Learning algorithm learns how to play snake, scoring up to 67 points after only 10 minutes of training.
Install the following packages in your pytorch environnement:
pip install numpy
pip install pygame
The code was tested on Python 3.10 and PyTorch 2.0.
python play_cobra_game.py
python rl_agent.py
Models will be saved in the models/
folder.
python rl_agent --model_path pretrained_models/pretrained_model.pth
This code is distributed under an MIT LICENSE.