Skip to content

๐Ÿ Evolutionary algorithm using a neural network to train agents in the game snake.

Notifications You must be signed in to change notification settings

LucyIvatt/snake-ga

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

62 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

snake-ga

Python NumPy Matplotlib SciPy

This repository contains a basic neuroevolution that evolves the weights of a multi-layer perceptron (MLP) using a genetic algorithm. This solution utilises DEAP, a novel evolutionary computation framework for rapid prototyping and testing of ideas.

Neural Network Structure

The final algorithm proposed is a conventional neuroevolutionary algorithm (CNE). The topology of the network is fixed in nature and only the weights of the network are evolved in the algorithm.

The network used is a fully-connected multi-layer perceptron with 2 hidden layers. The input layer has 10 nodes that represent local searches for food & obstacles in the cells immediately above, below, left, and right of the snake, as well as the direction of the food in the x & y axis

image

Experiments

Before deciding on the final algorithm two different experiments were run to determine the most successful variants of the algorithm. One experiment looked at different combinations of inputs to the neural network, and the other looked at modifying the probabilities of crossover and mutation.

Due to the stochastic nature of genetic algorithms, each algorithm variant was run multiple times and the statistics averaged. This produced more rigorous results so that reliable and informed decisions could be made. Each experiment had 2 stages, the exploration stage, and a final stage. The exploration stage used 5 iterations of each algorithm to explore a wide range of alterations. The final stage used 15 iterations of each algorithm to analyse the best two variants found in the exploration stage.

Neural Network Input Experiment

Algorithms Tested

image image

Results

image image

Crossover & Mutation Probabilities Results

image image

Final Algorithm

image

All code submitted as part of the first assessment in the module Evolutionary and Adaptive Computing (EVAC) at the University of York.

About

๐Ÿ Evolutionary algorithm using a neural network to train agents in the game snake.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published