Creating Neural Networks for games

gradImageArtificial Intelligence is an important component for modern games. A particularly powerful concept in AI is machine learning, and Neural Networks are one method of many machine learning techniques.

The project I created in order to demonstrate a neural network within a game is L-Robot. You can see a video I created that demonstrates L-Robot below:

How does it work?

Neural networks are a technique generally used for pattern recognition. A large neural network can compute huge amounts of data and are proficient in finding solutions for problems such as character recognition, image recognition or even stock market predictions. But how can we use neural networks in games?

The neural network implemented into L-Robot is his brain, which controls how L-Robot moves. The network takes in two inputs and processes these inputs through a number of layers of neurons to produce an output.

The inputs for the network are:

  • The current fitness
  • The position of L-Robot relative to the closest platform

These numbers are processed to output these values:

  • A number to determine whether L-Robot should move left or right
  • A number to determine whether L-Robot should jump

The network is processed every frame and will run for 150 frames. If a solution is not found within this time, then a genetic algorithm is used to evolve the network.

Genetic Algorithm

The genetic algorithm within the project is used to evolve the weights of the neural network. A generation of thirty genes is created at the start of the program, each gene representing a different brain. After a generation has completed its run through the game, the genetic algorithm is executed.

The genetic algorithm uses roulette-wheel selection to create a new population of genes. Roulette-wheel selection consists of creating a mating pool of copies of each gene. The number of copies of each gene correlate directly to the fitness value of the gene – i.e. if a gene has 60% fitness, then 60 copies are pushed onto the mating pool – this promotes elitism, meaning the next population has a good chance of being more successful than the previous.

After a mating pool is created, random genes are selected to crossbreed a new child gene. These new children are then used to create a new population of genes to be given to the neural network. This is how the neural network is adapted and how L-Robot learns.

If you would like more information, leave a comment or email me at:

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s