Neuroevolution Snake Game

The Project

My project applies neuroevolution on the classic snake game. There are 1000 snakes generated and each has its own "brain" to play this game. The snakes' brains are each a neural network with 6 inputs, 6 hidden nodes and 2 outputs. The goal of each snake (black) is to find and eat their own food (red) to grow longer. The snake "dies" when it either touches its own body or the walls of the space. The evolution part involves running the simulation in generations with each generation inheriting the "brains" of better snakes. As the generations progress, the length of snakes on average also increase before dying. "K" (yes it's in upper case so that no one would accidentally hit the keyboard and press it) means kill the remaining snakes and start the next generation. "s" means save current longest snake's brain to a json file. The simulation uses ML5.js library for the learning and P5.js for the UI.

Advanced
Art
Fun

Team Comments

I chose to make this project because...

I enjoy watching videos on neuroevolution as the results are fun and fascinating. So, I decided to learn Machine Learning and build a project on neuroevolution myself. I superimposed multiple instances of snakes to monitor and better visualise the performance of each snake relative to the others.

What I found difficult and how I worked it out

I couldn’t find the correct inputs and outputs for the neural network and the snakes weren’t learning the rules of the snake game. I did some research on the internet, tried different ideas and eventually found the inputs and outputs that worked.

Next time, I would...

Following this, I am going to try to add poison, and the snakes will have to learn to avoid the poison.

About the team

  • Singapore

Team members

  • Skyler