AI learns to control a ball through a maze using neural networks. This simulation is an experiment I conducted to see how a neural network and a genetics algorithm would react in a world bound by physics. Though the physics is abit strange it’s not that realistic but it gets the point across.
- There are a total of 12 input neurons.
A rayCast in 7 direction at different angles. This helps the AI to make sense of the world it is in. These will help us keep track of the distances between the edges in the world.
The current x & y velocity of the ball.
The height of the nearest wall on the right side of the ball. This can be achieved by casting a ray at 90 degrees towards the nearest edge.
Have checkpoints placed in strategic places and record their x & y coordinates then pick the nearest checkPoint the ball may jump to.
- There are 4 neurons in this layer.
-There are 2 output values in this layer.
The velocity of the ball via x. The ball has the ability to control it’s velocity even when it’s midAir.
The jump velocity of the ball via y. The ball can only jump if it hit the bottom edge but it can bounce off walls depending on the velocity it wa moving.
-The network is trained using a neural evolution using the genetics algorithm.
- Population size of 60 agents.
- Children are created using the fitness score of the top 50%.( no cross breeding done)
- Mutation rate of 1% is done to all children for variation.
- A direct copy of the top 3 parents are created and passed to the next generation.