https://github.com/jonatan5524/SnakeAI
Snake game self played with genetic algorithm and neural network - NEAT
https://github.com/jonatan5524/SnakeAI
javascript neat-algorithm
Last synced: about 1 month ago
JSON representation
Snake game self played with genetic algorithm and neural network - NEAT
- Host: GitHub
- URL: https://github.com/jonatan5524/SnakeAI
- Owner: jonatan5524
- License: mit
- Created: 2020-09-13T17:13:25.000Z (almost 5 years ago)
- Default Branch: gh-pages
- Last Pushed: 2021-09-11T17:15:18.000Z (almost 4 years ago)
- Last Synced: 2024-11-18T08:55:25.655Z (7 months ago)
- Topics: javascript, neat-algorithm
- Language: JavaScript
- Homepage:
- Size: 578 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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:
## 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 dothe 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.