Coder Social home page Coder Social logo

mdecourse / snake-reinforcement-learning Goto Github PK

View Code? Open in Web Editor NEW

This project forked from eidenyoshida/snake-reinforcement-learning

0.0 0.0 0.0 2.42 MB

Applying basic reinforcement learning principles using the Snake game in Python

Python 100.00%

snake-reinforcement-learning's Introduction

Snake-Reinforcement-Learning

Applying basic reinforcement learning principles using the Snake game in Python

Snake.py is a basic snake game.

QLearning.py teaches an agent to play the snake game using Q-Learning. For every move, the game will send a reward. If the snake collides with itself or a wall, there is a negative reward. If the snake moves towards the food, there is a positive reward.

The Q matrix is initially filled with zeros. The size is (number of states, number of actions).

Every move that the agent makes, the Q table is updated as below:

Q[state, action] = reward + gamma * max(Q[new_state, :])

During the training phase, the agent will either choose the action with the max Q value at that state or the agent will randomly choose an action. The Q matrix is then updated using the equation above.

This process is repeated until the game is complete. Many games are played to update the Q matrix.

QLearning.py will automatically animate some samples games at various stages of the training process.

See below for example games using the Q matrix at various stages in the training process.

snake-reinforcement-learning's People

Contributors

eidenyoshida avatar alexanderkrusina 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.