{"id":18647719,"url":"https://github.com/nikorasu/snakeai","last_synced_at":"2026-04-09T02:31:18.790Z","repository":{"id":230455604,"uuid":"597870334","full_name":"Nikorasu/SnakeAI","owner":"Nikorasu","description":"WIP project to use machine learning to play Snake!","archived":false,"fork":false,"pushed_at":"2025-01-18T18:09:59.000Z","size":69,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-03T18:52:01.413Z","etag":null,"topics":["ai","deep-learning","dqn","educational","machine-learning","ml","neural-network","numpy","pytorch","q-learning","reinforcement-learning","snake-game","supervised-learning","supervised-machine-learning","terminal"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Nikorasu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-02-05T21:42:23.000Z","updated_at":"2025-01-18T18:10:00.000Z","dependencies_parsed_at":"2024-03-29T21:28:41.349Z","dependency_job_id":"767b4832-ae6e-4531-855c-40a0bb045fe1","html_url":"https://github.com/Nikorasu/SnakeAI","commit_stats":null,"previous_names":["nikorasu/snakeai"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Nikorasu/SnakeAI","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nikorasu%2FSnakeAI","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nikorasu%2FSnakeAI/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nikorasu%2FSnakeAI/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nikorasu%2FSnakeAI/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Nikorasu","download_url":"https://codeload.github.com/Nikorasu/SnakeAI/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nikorasu%2FSnakeAI/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31582583,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-08T14:31:17.711Z","status":"online","status_checked_at":"2026-04-09T02:00:06.848Z","response_time":112,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","deep-learning","dqn","educational","machine-learning","ml","neural-network","numpy","pytorch","q-learning","reinforcement-learning","snake-game","supervised-learning","supervised-machine-learning","terminal"],"created_at":"2024-11-07T06:27:37.764Z","updated_at":"2026-04-09T02:31:18.771Z","avatar_url":"https://github.com/Nikorasu.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Using ML to play Snake\n\nThis project is still being worked on, and it's mostly just to satisfy my curiosity. I don't know what I'm doing.\\\nUses a modified version of [MiniSnakes](https://github.com/eliasffyksen/MiniSnakes) and just requires PyTorch and Numpy for now.\\\nI've setup the base game with rewards, hopefully that can work with for reinforcement learning.\\\nAlso made an old-school bot version (`snake_smrtbot.py` \u0026 `snake_tutor.py`) to record data for training.\\\nThe bot version can usually fill over half the play area with snake, highest score I've seen so far was 62/64!\\\nThe 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.\n\n- `snake.py` is the base game, with modifications for manual or agent to play.\n- `agent.py` contains the code for the neural network to train, save, and playback.\n- `snake_tutor.py` collects data from tons of best-games played by a simpler bot.\n- `snake_user.py` enables manually recording perfect games, including a backspace feature.\n- `loading_anim.py` adds a waiting animation to indicate things are processing.\n- `snake_smrtbot.py` the bot I came up with, which snake_tutor is based on, not perfect.\n- `snake_dumbot.py` an older less effective bot, kept as a reference.\n\nI haven't had much luck getting reinforcement learning working yet, so I've been trying simpler methods.\\\nUsing the _tutor version, I recorded thousands of games to file, along with the action each turn made.\\\nWith that, should be able to train a basic neural network on what move to make for whatever the game state might currently look like.\n\nExample game state:\n\n${\\large0~~~0~~~0~~~0~~~0~~~0~~~0~~~0}$\\\n${\\large0~~~0~~~0~~~0~~~{\\color{green}1~~~2}~~~0~~~0}$\\\n${\\large0~~~0~~~0~~~0~~~0~~~{\\color{green}3}~~~0~~~0}$\\\n${\\large0~~~0~~~0~~~0~~~0~~~{\\color{green}4}~~~0~~~0}$\\\n${\\large0~~~0~~~0~~~{\\color{green}7~~~6~~~5}~~~0~~~0}$\\\n${\\large0~~~0~~~0~~~{\\color{green}8}~~~0~~~0~~~0~~~0}$\\\n${\\large0~~~0~{\\color{red}-1}~~0~~~0~~~0~~~0~~~0}$\\\n${\\large0~~~0~~~0~~~0~~~0~~~0~~~0~~~0}$\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnikorasu%2Fsnakeai","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnikorasu%2Fsnakeai","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnikorasu%2Fsnakeai/lists"}