Git Product home page Git Product logo

deep-q-snake-pytorch's Introduction

Playing snake game with Pytorch Deep Q-Learning

The main goal of this project is to develop an AI bot which can learn to play the popular snake game. In order to compare the learning result with human performance, this project consists of two modes, namely, manual mode and ai mode. More instruction can be found below.

I adopt the idea of network input data and some training technics from here. According to this article, I used 11 boolean variables as the input. I rebuilt the model by using just 3 (input, hidden, output) fully connected layers. After some refinements, the model can converge after about 50 games.

Installation

To run this project, you need the following packages

  1. Pytorch
  2. Pygame
  3. numpy
  4. matplotlib
  5. other packages - you will find out by running the code :P

Command Base Usage

  1. If you want to run manual play mode:
python snake.py
  1. To train the model, go to Agent.py and uncomment line 299, then do:
python Agent.py
# You can tune the paramenters in Agent.py and network.py.
# You can also change the setting of the game wrapper in snake_ai.py. I set *self.FPS=40* to speed up the training.
  1. To play game based on the pre-trained model, go to Agent.py and uncomment line 300, then do:
python Agent.py
# This will call the model weight you save in './model' folder

UI Usage

To start:

python run.py
  1. Choose your option on game intro page.

  1. If you chose manual mode, you will see a white snake. Use w,a,s,d or up, down, left, right keys to control.

When your snake die, you can restart the game.

  1. If you chose AI mode, you will have to choose to train bot or play bot

  1. If you chose train, game will start to train and save the result in ./model. You can press esc to quit the game

Training result:

  1. If you chose play, game will pick the weight saves in ./model and play the game. Press esc to quit.

TO-DO


Might implement a restart function in the future.

deep-q-snake-pytorch's People

Contributors

charlie0215 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.