All Projects → driescroons → snaike

driescroons / snaike

Licence: other
Snake controlled by a neural network, trained by a genetic algorithm. Built with Typescript, Tensorflow, HTML5s canvas element and React.

Programming Languages

typescript
32286 projects
CSS
56736 projects
javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to snaike

3dstool
An all-in-one tool for extracting/creating 3ds roms.
Stars: ✭ 246 (+884%)
Mutual labels:  snake
AndroidGameSnake
AndroidGameSnake
Stars: ✭ 37 (+48%)
Mutual labels:  snake
python-game-snake
A Game-Snake version of AI to play Snake automatically.
Stars: ✭ 30 (+20%)
Mutual labels:  snake
snake-server
Snake-Server is a pure Go implementation of the famous arcade game 🐍
Stars: ✭ 31 (+24%)
Mutual labels:  snake
snake-reinforcement-learning
AI (A2C agent) mastering the game of Snake with TensorFlow 2.0
Stars: ✭ 37 (+48%)
Mutual labels:  snake
Snake
A simple game built using Python Pygame Library
Stars: ✭ 17 (-32%)
Mutual labels:  snake
Snek
🐍 ‎ A terminal-based Snake implementation written in JavaScript.
Stars: ✭ 210 (+740%)
Mutual labels:  snake
SnakeFX
Snake game in JavaFX
Stars: ✭ 41 (+64%)
Mutual labels:  snake
Python.io
Snake game inspired from Slither.io but features a python instead of a snake. Made in Python 3
Stars: ✭ 15 (-40%)
Mutual labels:  snake
cljs-snake
Snake in 100 lines of ClojureScript using Reagent for a #TechTalk at UCT
Stars: ✭ 21 (-16%)
Mutual labels:  snake
Wortuhr ESP8266
Wortuhr mit ESP8266 WeMos D1 mini und NeoPixel WS2812B LEDs mit mp3 Sounds, Animationen, Transitions, Events und Spiele
Stars: ✭ 33 (+32%)
Mutual labels:  snake
Snake
用Java语言开发的AI贪吃蛇
Stars: ✭ 62 (+148%)
Mutual labels:  snake
wxgame-snake
🐍 微信小程序游戏,贪吃蛇
Stars: ✭ 20 (-20%)
Mutual labels:  snake
Cpp-Snake
A simple snake game written in c++
Stars: ✭ 35 (+40%)
Mutual labels:  snake
snake
Basic Snake Game in TypeScript
Stars: ✭ 25 (+0%)
Mutual labels:  snake
Case
String case utitility: convert, identify, flip, extend
Stars: ✭ 237 (+848%)
Mutual labels:  snake
snake game
This is a simple implementation of the classic snake game in rust
Stars: ✭ 16 (-36%)
Mutual labels:  snake
SnakeClassic
A snake engine written in SpriteKit for all Apple devices.
Stars: ✭ 56 (+124%)
Mutual labels:  snake
snake-go
🐍 Play snake in your terminal. Built using Termloop.
Stars: ✭ 19 (-24%)
Mutual labels:  snake
snax86
A snake game written in x86 Assembly language for windows console
Stars: ✭ 21 (-16%)
Mutual labels:  snake

Snaike 👈 click me

Snaike is a browser trained snake neural network that learns to play, you couldn't have guessed it, snake. I hacked something together over the weekend and figured I'd post it online! It's made using Typescript, Tensorflow, HTML5s Canvas Element and React.

I'd love for you to contribute to the Snaike Repository as I'm looking to elaborate on this (and maybe even write a full tutorial for this). Are you looking for a side project and want to help me out? 📧

Please note that this project is most definitely not finished yet.

Explanation

For snaike, I've created a neural network based on a genetic algorithm.

What is a neural network?

A neural network is a kind of algorithm that can be used to determine the abstract relationship between some input data and a desired output.

For snaike, I went with 13 inputs. For every direction, being up / right / down / left, we check if there is a collision if you'd move one block, wether we would be able to eat the food on that block, and if the food is in that general direction. The last input we provide is a relative, normalized angle from the snakes head to the food.

The output of the neural network gives us one of 4 possible directions.

What is a genetic algorithm?

Instead of picking a network type and then slowly training it based on example Snake gameplay, we are going to create a scenario for one to evolve on its own.

All connections within the neural network will be build up randomly though multiple generations of the application. We reward the snake based on its actions by giving them points. These Points add up to its score and they can be obtained by eating or moving closer to the food. At the end of each generation (when the full population dies), we mutate the snakes their "brains" so that they more closesly mimic the best snakes of that specific generation, the ones who'd gotten the most points.

Getting started

Running the application is fairly easy. Clone the package and run

yarn

Once the packages are installed, run

yarn dev

Stack

  • Typescript
  • Tensorflow
  • HTML5s canvas element
  • React
  • Redux

References

I initially stumbled upon Desigining AI: Solving Snake with Evolution from Peter Binggeser. A really nice article where he explains step by step how you should design a neural network, one specifically for snake. Upon scrolling through the repository, I felt it was a little outdated so I decided to see if I could build it from scratch using a more modern approach. (newer packages...) I've used some of his quotes above.

I've scrolled through many projects during the creation and I most definitely wouldn't have been able to create snaike if wasn't for all of the awesome articles, repositories, videos from everyone here underneath! If you're looking to create something similar, make sure to checkout the following repositories as well:

Vector library used:

Roadmap

  • Better state management
  • Refactoring / Cleaning up
  • Choose your inputs
  • Replays of highscores

Contact

Feel free to contact me on twitter @croewens or on my website if you have any questions.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].