Skip to content

Genetic neural network controlled snakes with a goal to eat food and not crash.

Notifications You must be signed in to change notification settings

medk42/SnakesEvolution

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Evolution with Genetic Neural Network

Introduction

This Java program simulates genetic algorithm teaching a neural network to drive a Snake based on the following rules:

  • Snake needs to eat - if snake doesn't eat for some time, it will starve to death
  • Snake can't crash into wall - if snake is too close to the wall, it will die
  • Snake can't crash into itself - if snake touches itself, it will die
  • Snakes can't interact with each other - they live in a same box and share food, but can't see or affect each other

Neural Network Design

Snake's vision is divided into 16 different sectors covering area of 120 degrees in front of the snake. Snake can also see how far an object is as demonsrated on the picture below.

There is 49 neurons in the input layer - 48 input neurons and a bias.

  • 0: Bias neuron
  • 1-16: Input neurons for seeing itself
  • 17-32: Input neurons for seeing food
  • 33-48: Input neurons for seeing walls

Then there are two hidden layers with 16 (plus bias) neurons and output layer with two neurons for steering - snake steers based on the difference between the two values.

Controls

  • "ESC": to exit
  • "n": shows/hides the real-time graphical representation of the neural network behind the leading snake (also shows snake's field of view)
  • "f": displays current FPS (simulation is set to run at 60FPS)
  • "g": displays basic graph of score of the best snake over time
  • "SPACE": pauses/continues the simulation

Running the project

Running my build

Easiest way to run the project is to download it and run "dist/ProcessingTemplate.jar". The only other file you need is "dist/lib/core.jar" because of the library.

Building project on your own

Project requires you to compile it with Processing library (file core.jar).

Resources

About

Genetic neural network controlled snakes with a goal to eat food and not crash.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages