Description
This is a Python program that plays the game of Snake with AI. The snake moves on a small 6 by 6 grid, and the project implements two strategies. The first uses graph search: when the snake is long enough, it looks for a Hamiltonian cycle that fills the board safely, otherwise it searches for shortest paths to the food and checks that the snake can still reach its tail afterwards. The second uses reinforcement learning, where the snake learns by trial and error without prior knowledge, and a pre-trained model is provided. 3 with a 50 percent success rate. 10 or newer. Graph search needs only the mandatory dependencies, while the reinforcement learning mode needs PyTorch, which runs on CPU or GPU. Command-line options are available, and you can train your own model.…
Highlights
- Snake played by a graph search algorithm
- Reinforcement learning player with a pre-trained model
- Benchmarks reported over 1000 rounds
- Train your own reinforcement learning model
- Command-line options and CPU or GPU support
Ratings & Reviews
No ratings yet
Be the first to rate Snake.
People also visit
Snake FAQ
What does this project do?
It plays the classic game of Snake automatically using two AI approaches and reports how well each one does.
Which AI strategies are included?
A graph search strategy that finds paths and cycles on the grid, and a reinforcement learning agent that learns the game by trial and error.
How well does it play?
Over 1000 rounds, the README reports an average length of 35.86 and a 94 percent success rate for graph search, and 29.33 and 50 percent for reinforcement learning. The grid is 6 by 6, so the maximum length is 36.
What do I need to run it?
Python 3.10 or newer, ideally in a virtual environment, with the mandatory dependencies installed. The reinforcement learning mode also needs PyTorch.
Can I train my own model?
Yes. The README gives a command to train a reinforcement learning model, and a pre-trained model is also available.
What are the best Snake alternatives?
Popular alternatives to Snake include Tetris Game, Command Line Chess and Jumping-Agent-platform. See all Snake alternatives



