Snake AI

An artificially intelligent player for Snake. The snake's brain is a neural network and is improved using the genetic algorithm. Written in Python using Pygame for graphics/user interaction. Evolution handled by Holland.

See the Github repository's gallery for more sample runs, corresponding genomes are in samples.

Snake Anatomy

Snakes have 5 eyes and can see the closest object that falls along the straight line starting at the snake's head at the angle of the eye.

Snakes brains are neural nets with one hidden layer, 15 input nodes, and 5 output nodes. The 15 inputs correspond to the inputs of the eyes. Each eye receives 3 inputs—2 are the visual encoding of the object, and the final is the distance from the snake's head to the object. Each of the 5 output nodes correspond to turning in the direction of one of the snake's eyes (one eye points forward so this is just not turning).