Neural Rocket Landing

Teaching AI to Land Rockets Using Genetic Algorithms

This project showcases a neural network learning to land rockets using a genetic algorithm, all rendered in a browser with JavaScript, HTML5, and the Matter.js physics engine.

Rockets are equipped with three binary thrusters and controlled either manually (W, A, D keys) or by AI. The neural networks are trained from scratch and evolve over generations, optimizing landing performance through selection, crossover, and mutation.

Users can tweak training parameters in real time and monitor learning progress via performance graphs that track average and top scores across generations.

Users

Technology Stack

Neural Networks

Implemented from scratch with two hidden layers of 16 neurons each, using ReLU activation. Fully integrated with a custom training environment.

Genetic Algorithm

Utilizes roulette wheel selection, crossover reproduction from two parents, and an adjustable mutation rate to evolve landing strategies.

Matter.js Physics

Handles realistic physics simulation including thrust, gravity, rotation, and collision detection between rockets and the landing platform.

JavaScript & HTML5

Built entirely in vanilla JavaScript with HTML5 Canvas for rendering. No external ML libraries were used — everything is coded manually.

Implementation Details

Rocket Design

  • Three thrusters: bottom-left, bottom-right, and center
  • Each thruster operates in binary mode (on/off)
  • Movement and rotation governed by real-time physics
  • Ground collision detection for landing evaluation

Neural Network Architecture

  • Inputs: vertical distance, horizontal position, angle, angular velocity, etc.
  • Two hidden layers, each with 16 neurons
  • Activation function: ReLU
  • Outputs: three binary values controlling thrusters

Evolution Process

  • Fitness based on landing success (orientation, impact speed, stability)
  • Roulette wheel selection of parent rockets
  • Crossover combines weights from two parents
  • Mutations applied probabilistically per weight
  • User-adjustable mutation factor and survival rate

Visualization Features

  • Live-updating graph of population performance
  • Tracking of average, top 50%, and top 10% scores
  • Interactive UI for tuning algorithm parameters
  • Replay of top-performing rockets across generations