Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nikorasu/snakeai
WIP project to use machine learning to play Snake!
https://github.com/nikorasu/snakeai
ai deep-learning dqn machine-learning ml neural-network numpy pytorch q-learning reinforcement-learning snake-game supervised-learning supervised-machine-learning terminal
Last synced: 30 days ago
JSON representation
WIP project to use machine learning to play Snake!
- Host: GitHub
- URL: https://github.com/nikorasu/snakeai
- Owner: Nikorasu
- License: gpl-3.0
- Created: 2023-02-05T21:42:23.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-04-12T17:41:15.000Z (10 months ago)
- Last Synced: 2024-04-13T21:54:19.937Z (10 months ago)
- Topics: ai, deep-learning, dqn, machine-learning, ml, neural-network, numpy, pytorch, q-learning, reinforcement-learning, snake-game, supervised-learning, supervised-machine-learning, terminal
- Language: Python
- Homepage:
- Size: 64.5 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Using ML to play Snake
This project is still being worked on, and it's mostly just to satisfy my curiosity.\
Uses a modified version of [MiniSnakes](https://github.com/eliasffyksen/MiniSnakes) and just requires PyTorch and Numpy for now.\
I've setup the base game with rewards, hopefully that can work with for reinforcement learning.\
Also made an old-school bot version (`snake_smrtbot.py` & `snake_tutor.py`) to record data for training.\
The bot version can usually fill over half the play area with snake, highest score I've seen so far was 62/64!\
The current reward system gives 10 points for eating food, -10 for running into itself. As well as a small reward as it moves around, positive values when actions move it closer to food, negative when it's actions head away from food, scaling from 1 up to 9 (spot next to food) as it gets closer.- `snake.py` is the base game, with modifications for manual or agent to play.
- `agent.py` contains the code for the neural network to train, save, and playback.
- `snake_tutor.py` collects data from tons of best-games played by a simpler bot.
- `snake_user.py` enables manually recording perfect games, including a backspace feature.
- `loading_anim.py` adds a waiting animation to indicate things are processing.
- `snake_smrtbot.py` the bot I came up with, which snake_tutor is based on, not perfect.
- `snake_dumbot.py` an older less effective bot, kept as a reference.I haven't had much luck getting reinforcement learning working yet, so I've been trying simpler methods.\
Using the _tutor version, I recorded thousands of games to file, along with the action each turn made.\
With that, should be able to train a basic neural network on what move to make for whatever the game state might currently look like.Example game state:
${\large0~~~0~~~0~~~0~~~0~~~0~~~0~~~0}$\
${\large0~~~0~~~0~~~0~~~{\color{green}1~~~2}~~~0~~~0}$\
${\large0~~~0~~~0~~~0~~~0~~~{\color{green}3}~~~0~~~0}$\
${\large0~~~0~~~0~~~0~~~0~~~{\color{green}4}~~~0~~~0}$\
${\large0~~~0~~~0~~~{\color{green}7~~~6~~~5}~~~0~~~0}$\
${\large0~~~0~~~0~~~{\color{green}8}~~~0~~~0~~~0~~~0}$\
${\large0~~~0~{\color{red}-1}~~0~~~0~~~0~~~0~~~0}$\
${\large0~~~0~~~0~~~0~~~0~~~0~~~0~~~0}$