{ "info": { "author": "Victor Otavio Andrade das Neves", "author_email": "victorneves478@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "License :: OSI Approved :: MIT License" ], "description": "snake-on-pygame\n=================\n\n[![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://github.com/Neves4/snake-rl/graphs/commit-activity) [![made-with-python](https://img.shields.io/badge/Made%20with-Python-1f425f.svg)](https://www.python.org/) [![MIT license](https://img.shields.io/badge/License-MIT-blue.svg)](https://lbesson.mit-license.org/) [![Ask Me Anything !](https://img.shields.io/badge/Ask%20me-anything-1abc9c.svg)](https://GitHub.com/Neves4/ama)\n\n

\n \n

\n\nSnake game that can be controlled by human input and AI agents (DQN). Who's best? :snake: :robot:\n\nTable of Contents\n=================\n\n* [1. Getting Started (for human players)](#getting_started-human)\n * [1.1. Prerequisites](#pre-req-human)\n * [1.2. Installing](#installing-human)\n * [1.3. Playing](#playing-human)\n* [2. Getting Started (using AI agents)](#getting_started-ai)\n * [2.1. Available methods to integrate with any agent](#available-method)\n * [2.1.1. Methods](#methods)\n * [2.1.2. Example usage](#example-usage)\n * [2.2. Using colab-rl](#using-colab-rl)\n* [3. Contributing](#contributing)\n* [4. License](#license)\n* [5. Acknowledgments](#acknowledgments)\n\n## 1. Getting Started (for human players) \n\nLet's get the game up and running on your computer, with the instructions below.\nYou can play the game and compare to the repos benchmark, which includes AI and\nhumans (you can include yourself by a pull request to the file [scores.json](resources/scores.json)).\n\n### 1.1. Prerequisites \n\nTo play the game you need Python 3.4+. If you installed [Anaconda](https://www.anaconda.com/) the only package\nyou need to download is pygame. Before installing it, make sure your Anaconda\ninstallation is up-to-date using the command (conda update conda anaconda)and\nupdating all packages (conda update --all). To install pygame, use:\n\n```\n$ conda install -c cogsci pygame\n\n```\nIt's highly recommended to use Anaconda to manage your Python packages and environments.\nIf you chose not to, make sure you run requirements_human.txt, using:\n\n```\n$ python install setup.py\n```\n\nor\n\n```\n$ python3 install setup.py\n```\n\n### 1.2. Installing \n\nYou can download download the source code or clone the repository to your computer.\n\nTo clone the repository, open bash or command prompt, cd to the chosen directory\nand run the following code:\n\n```\n$ git clone https://github.com/Neves4/SnakeAI.git\n```\n\nTo download the repo, just follow along the gif (click 'Clone or Download' and\nthen 'Download ZIP').\n\n![Download repo](/resources/gifs/download_repo.gif)\n\n### 1.3. Playing \n\nThe GUI allows you to choose between single games and the benchmark mode. It's\nalso possible to choose between difficulty levels.\n\nIf using the repository files, change directory to the root, then to the game folder\nand use:\n\n```\n$ python snake.py [-h]\n```\n\nAn example gameplay for a single player match is shown below.\n\n

\n \n

\n\nIn the benchmark mode, you will play through 10 games and your mean score/steps\nare going to be recorded and you can add to the leaderboards. Pull request\nchanging the benchmark file ([located in here](resources/scores.json)) or open an issue with your score.\n\n## 2. Getting Started (using AI agents) \n\nThis game uses similar usage structure and methods to [OpenAI's gym](https://github.com/openai/gym) and you\ncan easily integrate it with any agent, written in Pytorch, Tensorflow, Theano or Keras.\n\nIt's recommended that you use [colab-rl](https://github.com/Neves4/colab-rl), a repository that integrates\nstate-of-the-art algorithms with games, because it already implements the agents\nand the game, making the process of quick prototyping much easier.\n\n### 2.1. Available methods to integrate with any agent \n\nIn this section, we're going to show the useful methods and properties and also\ndemonstrate how to use in a real case\n\n#### 2.1.1. Methods and useful properties \n\nBelow are listed some useful properties of the game class.\n\n```\n>>> print(game.nb_actions)\n5 # number of actions.\n\n>>> print(game.food_pos)\n(6, 5) # current position of food.\n\n>>> print(game.steps)\n10 # current number of steps in a given episode.\n\n>>> print(game.snake.length)\n4 # current length of the snake in a given episode.\n```\n\nThe methods you could use to integrate with any AI agent are:\n\n```\n>>> state = game.reset()\n # Reset the game and returns the game state right after resetting.\n\n>>> state = game.state()\n # Get the current game state.\n\n>>> game.food_pos = game.generate_food()\n # Update the food position.\n\n>>> state, reward, done, info = game.step(numerical_action)\n # Play a numerical_action, obtaining state, reward, over and info.\n\n>>> game.render()\n # Render the game in a pygame window.\n```\n\n#### 2.1.2. Example usage \n\nTo use with AI agents, you need to integrate the game with the AI agent. An\nexample usage is:\n\n```\nfrom snake-on-pygame import Game\nfrom ai_agent import your_model # import your AI agent of choice\n\ngame = Game(player = \"ROBOT\",\n board_size = board_size,\n local_state = local_state,\n relative_pos = RELATIVE_POS)\nstate = game.reset()\n\nmodel = your_model()\n\nwhile not game.game_over: # Main loop, until game_over\n game.food_pos = game.generate_food()\n\n model.choose_action(state) # CHOOSE ACTION BASED ON MODEL/AI AGENT\n state, reward, done, info = game.step(action)\n\n mode.train(state, reward, game_over, done)\n print(info)\n\nmodel.test()\n```\n\nThe above code is an example usage for one episode. If you want more episodes,\nwrap the while loop in a loop for nb_epochs (you choose).\n\n### 2.2. Using with colab-rl \n\nUsing snake-on-pygame with [colab-rl (click here)](https://github.com/Neves4/colab-rl) is very straightforward\nand you can also experiment with hyperparameters on state-of-the-art algorithms.\n\nA detailed usage is described on the repo's main README, but for short, after\ncloning it you can just execute the run_dqn.py script with:\n\n```\n$ python run_dqn.py [-h]\n```\n\nAnd you can read more about all the possible arguments in the file/repo. An\ntrained DQN model, on a 10 x 10 board with no customization is represented on the\nbelow GIF.\n\n

\n \n

\n\n## 3. Contributing \n\nPlease read [CONTRIBUTING.md](https://gist.github.com/PurpleBooth/b24679402957c63ec426) for details on this repo's code of conduct, and the process for submitting pull requests.\n\n## 4. License \n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## 5. Acknowledgments \n\n* @farizrahman4u - For his [qlearning4k](https://github.com/farizrahman4u/qlearning4k) snake code, I used it as the base of this repo's code.\n\n* @chuyangliu - Also for his snake code, which implemented the relative actions.", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/neves4/snake-on-pygame/", "keywords": "snake pygame reinforcement-learning AI python", "license": "", "maintainer": "", "maintainer_email": "", "name": "snake-on-pygame", "package_url": "https://pypi.org/project/snake-on-pygame/", "platform": "", "project_url": "https://pypi.org/project/snake-on-pygame/", "project_urls": { "Homepage": "https://github.com/neves4/snake-on-pygame/", "Source": "https://github.com/neves4/snake-on-pygame/" }, "release_url": "https://pypi.org/project/snake-on-pygame/1.0/", "requires_dist": null, "requires_python": ">=2.7", "summary": "Snake implemented on pygame meant to be used by human and AI agents", "version": "1.0" }, "last_serial": 5918967, "releases": { "1.0": [ { "comment_text": "", "digests": { "md5": "69553cbb17878aac014672298775d8d7", "sha256": "0d214cd77aa1626c52f151de1cf2c19f45304701ae0c8b4032dd725173fe9050" }, "downloads": -1, "filename": "snake-on-pygame-1.0.tar.gz", "has_sig": false, "md5_digest": "69553cbb17878aac014672298775d8d7", "packagetype": "sdist", "python_version": "source", "requires_python": ">=2.7", "size": 8208, "upload_time": "2019-10-02T16:49:07", "url": "https://files.pythonhosted.org/packages/39/c0/afcd3c5f450ce2f519f687c98aa940ed751f575f6e108fededa83f9dbae9/snake-on-pygame-1.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "69553cbb17878aac014672298775d8d7", "sha256": "0d214cd77aa1626c52f151de1cf2c19f45304701ae0c8b4032dd725173fe9050" }, "downloads": -1, "filename": "snake-on-pygame-1.0.tar.gz", "has_sig": false, "md5_digest": "69553cbb17878aac014672298775d8d7", "packagetype": "sdist", "python_version": "source", "requires_python": ">=2.7", "size": 8208, "upload_time": "2019-10-02T16:49:07", "url": "https://files.pythonhosted.org/packages/39/c0/afcd3c5f450ce2f519f687c98aa940ed751f575f6e108fededa83f9dbae9/snake-on-pygame-1.0.tar.gz" } ] }