Giter Club home page Giter Club logo

car-game-ai's Introduction

Snake Game AI

AI driven snake game using Reinforcement Learning and Deep Q Learning.

The game of Snake actually has a trivial, unbeatable solution. It can be driven by Simple Non-ML Technique by just traversing every block of the board, this gives the unbeateablre solution but it is very time taking and very brute force approach.

But we will be using reinforcement learning techinque.

Reinforcement Learning

The first question arises in mind that why we are using reinforcement learning instead of supervised machine learning, the answer is, in supervised ML algorithms need to be trained with an input and a “correct answer” called target.In this example, we don’t know what the best action to take at each stage of the game is, so a traditional approach would not be effective.
In Reinforcement Learning, we have two main components: the environment (our game) and the agent (our Snake.. or to be correct, the Deep Neural Network that drives our Snake’s actions). Every time the agent performs an action, the environment gives a reward to the agent, which can be positive or negative depending on how good the action was from that specific state.

Deep Reinforcement Learning (DRL) combines the above ideas of RL with deep neural networks. The neural network learns the “Q function”, which takes as input the current environment state and outputs a vector containing expected rewards for each possible action. The agent can then pick the action that maximizes the Q function. Based on this action, the game then updates the environment to a new state and assigns a reward (e.g. +10 for eating an apple, -10 for hitting a wall). At the beginning of training, the Q function is just approximated by a randomly initialized neural network.

I will explain the implementation of this SnakeAI step by step.
A simple snake board game which is user controlled is designed using pygame module is here https://github.com/vedantgoswami/SnakeGameAI/blob/main/snake_game.py

Algorithm

We have snake and food on the board randomly placed.

  • calculate the state of the snake using the 11 values
  • Now this current state is passed to the RL Model for the next state.
  • After executing the next state calculate the reward. Rewards are defined as below:
    1. Eat food : +10
    2. Game Over : -10
    3. Else : 0
  • Update the Q value and Train the Model.

After analysing the algorithm now we have to build the idea to proceed for coding this algorithm.

Our Project will be divided into three Modules named Agent, Game and Model














Result












               Initial Epochs                                           After 100th Epochs

car-game-ai's People

Contributors

vedantgoswami avatar joyce-yuan 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.