Skip to content

AI agent learns how to play Snake using Deep Reinforcement Learning (PyTorch).

License

Notifications You must be signed in to change notification settings

brightonm/COBRA

Repository files navigation

COBRA 🐍

AI agent learns how to play Snake using Deep Reinforcement Learning (PyTorch).

Alt Text

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.

Installation 👷

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.

How to play the game 🎮

python play_cobra_game.py

How to watch the agent train and learn 🐘

python rl_agent.py

Models will be saved in the models/ folder.

How to use a pretrained model and watch its performance 🚀

python rl_agent --model_path pretrained_models/pretrained_model.pth

License

This code is distributed under an MIT LICENSE.

About

AI agent learns how to play Snake using Deep Reinforcement Learning (PyTorch).

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages