Skip to content
Machine Learning for Asteroids using Neural Network and Genetic Algorithm
Branch: master
Clone or download
Pull request Compare This branch is 19 commits ahead of ssusnic:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Machine Learning Asteroids Genetic Algorithm

This website is designed to teach a neural network to play the arcade game asteroids. 10 ships spawn in and gain points by staying alive, moving, and shooting asteroids, which break into smaller asteroids. The game restarts with new AI's after all ships are destroyed.


Run python -m SimpleHTTPServer within the source folder. Visit the page outputted. Add ?player=true to play as the red fighter.

Element Properties


Asteroids are worth the same amount of points at all sizes.


Property Value
Max Velocity 220


Bullets cost the ship points when they hit nothing. | Property | Value | | ------------- |:-------------:| | Speed | 600 |

Neural Network

The spaceship's brain has 8 input neurons, which recieve the distance to the closest asteroid in each direction.

The spaceship has 6 neurons in its hidden layer, and 4 in the output layer:

  1. accelerates when greater than 0.5 and coasts otherwise
  2. fires a bullet when greater than 0.5 and holds fire otherwise
  3. rotates the ship when greater than 0.5 and maintains orientation otherwise
  4. rotates left when greater than 0.5 and right otherwise

Genetic Algorithm

Spaceships are rewarded for moving, as it is sometimes to their advantage to stay put, but that behavior is boring.

Tutorial Reference

You can’t perform that action at this time.