Giter VIP home page Giter VIP logo

snakeai's Introduction

SnakeAI

Snake game self played with genetic algorithm and neural network - NEAT. the game is developed using p5.js framework for the canvas and the game and the tensorflow.js library for the neural network.

Live demo:

https://jonatan5524.github.io/SnakeAI/Snake

Installation:

Required:

npm

Installing:

git clone https://github.com/jonatan5524/SnakeAI
cd SnakeAI
npm install -g p5-manager
p5 server

Usage:

After running the local server for the snake AI, go to the address with the port that presented in the terminal and to the path Snake

Example:

example

Algorithm:

there are multiple snake game, as the number of population count, for each game there is a snake and an apple with its own score, for each snake there is a "brain" - a neural network that decide each turn what move to play.

Neural Network

inputs:

  • 0 or 1 if the block on the left is free
  • 0 or 1 if the block on the right is free
  • 0 or 1 if the block above is free
  • 0 or 1 if the block below is free
  • the angle to the apple
  • suggestion what action to do

the suggestion is decided by where is the apple where need to turn.

outputs:

  • turn left
  • turn right
  • defualt (dont turn)

Genetic Algorithm

  • population: array of snake games.
  • fitness: gitness is increased when the snake as eaten an apple and increase when the snake is moving toward the snake and decrease when the snake moving ืŸn the opposite direction of the apple.
  • mutation: changing the weight of on the neural network by mutation rate.
  • selection: the parent for the next generation is selected by the highest fitness.

there is one more factor for the snake, hunger, each turn the snake hunger is decreased and increased when the snake is eating an apple.

snakeai's People

Contributors

jonatan5524 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Forkers

echosystemmark

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.