{"id":20171487,"url":"https://github.com/pawel-kieliszczyk/snake-reinforcement-learning","last_synced_at":"2025-04-10T02:42:50.084Z","repository":{"id":44903354,"uuid":"190862050","full_name":"pawel-kieliszczyk/snake-reinforcement-learning","owner":"pawel-kieliszczyk","description":"AI (A2C agent) mastering the game of Snake with TensorFlow 2.0","archived":false,"fork":false,"pushed_at":"2019-07-21T16:57:24.000Z","size":50450,"stargazers_count":41,"open_issues_count":0,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-24T04:13:05.473Z","etag":null,"topics":["a2c","artificial-intelligence","keras","machine-learning","reinforcement-learning","snake","tensorflow"],"latest_commit_sha":null,"homepage":"https://youtu.be/s_vGKtm3bd4","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pawel-kieliszczyk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-06-08T08:06:16.000Z","updated_at":"2024-12-08T16:56:10.000Z","dependencies_parsed_at":"2022-09-01T17:01:26.625Z","dependency_job_id":null,"html_url":"https://github.com/pawel-kieliszczyk/snake-reinforcement-learning","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pawel-kieliszczyk%2Fsnake-reinforcement-learning","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pawel-kieliszczyk%2Fsnake-reinforcement-learning/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pawel-kieliszczyk%2Fsnake-reinforcement-learning/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pawel-kieliszczyk%2Fsnake-reinforcement-learning/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pawel-kieliszczyk","download_url":"https://codeload.github.com/pawel-kieliszczyk/snake-reinforcement-learning/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248145085,"owners_count":21055048,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["a2c","artificial-intelligence","keras","machine-learning","reinforcement-learning","snake","tensorflow"],"created_at":"2024-11-14T01:25:04.891Z","updated_at":"2025-04-10T02:42:50.057Z","avatar_url":"https://github.com/pawel-kieliszczyk.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SnakeAI\n\nTraining AI to play the game of Snake. With reinforcement learning (distributed A2C) it can learn to play a perfect game and score maximum points.\n\n\n## Overview\n\nAI learning to play Snake game \"from pixels\" with Tensorflow 2.0.\n\n![](snake-animation.gif)\n\n\n## Requirements\n\nPython 2 and Tensorflow 2.0 Beta or later\n\n\n## Usage\n\nTo train AI, simply type:\n\n```\n$ python src/train.py\n```\n\nThe agent can be trained multiple times. It will keep improving. Its state is saved automatically.\n\nIf you want to watch your trained AI playing the game:\n\n```\n$ python src/play.py\n```\n\nThe repository contains a pre-trained AI (trained on 1 GPU + 12 CPUs). To watch it playing, type:\n\n```\n$ python src/play_pretrained.py\n```\n\n## Implementation details\n\nImplementation uses a distributed version of Advantage Actor-Critic method (A2C).\nIt consists of two types of processes:\n + **master process** (1 instance): It owns the neural network model. It broadcasts network's weights to all \"worker\" processes (see below) and waits for mini-batches of experiences. Then it combines all the mini-batches and performs a network update using SGD. Then it broadcasts the current neural network's weights to workers again.\n + **worker process** (as many as number of cores): Each worker has its own copy of an A2C agent. Neural networks weights are received from \"master\" process (see above). Sample Snake games are played, a mini-batch of experiences is collected and sent back to master. Each worker then waits for an updated set of network's weights.\n\n\nNeural network architecture:\n + Shared layers by both actor and critic: 4x convlutional layer (filters: 3x3, channels: 64).\n + Actor's head (policy head): 1x convolutional layer (filters: 1x1, channels: 2), followed by a fully connected layer (4 units, one per move: up, down, left, right)\n + Critic's head (value head): 1x convolutional layer (filters: 1x1, channels: 1), followed by a fully connected layer (64 units), followed by a fully connected layer (1 unit - state's value)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpawel-kieliszczyk%2Fsnake-reinforcement-learning","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpawel-kieliszczyk%2Fsnake-reinforcement-learning","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpawel-kieliszczyk%2Fsnake-reinforcement-learning/lists"}