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:

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

outputs:

Genetic Algorithm

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.