Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/chuyangliu/snake
Artificial intelligence for the Snake game.
https://github.com/chuyangliu/snake
ai algorithm artificial-intelligence deep-reinforcement-learning game graph-theory python reinforcement-learning snake snake-ai
Last synced: 2 days ago
JSON representation
Artificial intelligence for the Snake game.
- Host: GitHub
- URL: https://github.com/chuyangliu/snake
- Owner: chuyangliu
- License: apache-2.0
- Created: 2016-06-25T02:59:09.000Z (over 8 years ago)
- Default Branch: main
- Last Pushed: 2024-06-18T16:24:00.000Z (7 months ago)
- Last Synced: 2025-01-02T11:06:47.030Z (9 days ago)
- Topics: ai, algorithm, artificial-intelligence, deep-reinforcement-learning, game, graph-theory, python, reinforcement-learning, snake, snake-ai
- Language: Python
- Homepage:
- Size: 3.92 MB
- Stars: 1,667
- Watchers: 108
- Forks: 491
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- my-awesome - chuyangliu/snake - intelligence,deep-reinforcement-learning,game,graph-theory,python,reinforcement-learning,snake,snake-ai pushed_at:2024-06 star:1.7k fork:0.5k Artificial intelligence for the Snake game. (Python)
README
# Snake
The project focuses on the artificial intelligence of the [Snake][snake-wiki] game. The snake's goal is to eat the food continuously and fill the map with its bodies as soon as possible. Originally, the project was [written in C++][snake-cpp]. It has now been rewritten in Python for a user-friendly GUI and the simplicity in algorithm implementations.
***[Algorithms >][doc-algorithms]***
## Experiments
We use two metrics to evaluate the performance of an AI:
1. **Average Length:** Average length the snake has grown to (*max:* 64).
2. **Average Steps:** Average steps the snake has moved.Test results (averaged over 1000 episodes):
| Solver | Demo (optimal) | Average Length | Average Steps |
| :----: | :------------: | :------------: | :-----------: |
|[Hamilton][doc-hamilton]|![][demo-hamilton]|63.93|717.83|
|[Greedy][doc-greedy]|![][demo-greedy]|60.15|904.56|
|[DQN][doc-dqn]
(experimental)|![][demo-dqn]|24.44|131.69|## Installation
Requirements: Python 3.6+ with [Tkinter][doc-tkinter] installed.
```
pip install -r requirements.txt
python run.py [-h]
```Run unit tests:
```
python -m pytest
```## License
See the [LICENSE](./LICENSE) file for license rights and limitations.
[snake-wiki]: https://en.wikipedia.org/wiki/Snake_(video_game)
[snake-cpp]: https://github.com/chuyangliu/snake/tree/7227f5e0f3185b07e9e3de1ac5c19a17b9de3e3c[doc-tkinter]: https://docs.python.org/3/library/tkinter.html
[doc-algorithms]: ./docs/algorithms.md
[doc-greedy]: ./docs/algorithms.md#greedy-solver
[doc-hamilton]: ./docs/algorithms.md#hamilton-solver
[doc-dqn]: ./docs/algorithms.md#dqn-solver[demo-hamilton]: ./docs/images/solver_hamilton.gif
[demo-greedy]: ./docs/images/solver_greedy.gif
[demo-dqn]: ./docs/images/solver_dqn.gif