Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

⚡ EvolvoBird: Flappy Bird Neuroevolution Simulator

EvolvoBird Simulator Screenshot

EvolvoBird is an interactive, browser-based simulator that teaches an artificial intelligence flock to play Flappy Bird using a Genetic Algorithm (GA) and a Feedforward Neural Network.

You can watch the birds evolve their neural connections in real-time, inspect their synapses, speed up or slow down time, adjust mutation rates, save/load models, or jump into the game yourself in manual play mode.


🚀 How to Run

Since the application uses modern JavaScript ES6 Modules, it must be served via a local web server (loading directly from file:// will trigger browser CORS restrictions).

Option 1: Using Node.js (Recommended)

From the project folder, run:

npx http-server -p 8080

Then open http://localhost:8080 in your browser.

Option 2: Using Python

From the project folder, run:

python -m http.server 8080

Then open http://localhost:8080 in your browser.


🧠 How the AI Works

The simulator combines a neural network (representing the bird's brain) and a genetic algorithm (simulating evolution).

1. The Neural Network (nn.js)

Each bird has its own small feedforward neural network structure: 4 inputs -> 5 hidden neurons -> 1 output.

  • Inputs:
    1. DX (Distance X): Horizontal distance to the next obstacle.
    2. DYT (Distance Y Top): Vertical distance to the bottom edge of the upper pipe.
    3. DYB (Distance Y Bottom): Vertical distance to the top edge of the lower pipe.
    4. VY (Velocity Y): The bird's current vertical speed.
  • Hidden Layer: 5 neurons mapping non-linear relationships.
  • Output: A single neuron yielding a float between 0.0 and 1.0. If output $> 0.5$, the bird flaps its wings.

2. The Genetic Algorithm (ga.js)

Evolution optimizes neural connection weights and biases over successive generations:

  1. Fitness Evaluation: A bird's fitness score increases with its survival time. Passing a pipe awards a large fitness bonus (+1200 points).
  2. Elitism: The single best-performing bird (the "Elite") is copied directly into the next generation without modification, ensuring the AI never regresses.
  3. Roulette-Wheel Selection: Parent birds are selected probabilistically. Birds with higher fitness have a higher chance of passing their genes down.
  4. Crossover: Offspring inherit weights and biases randomly mixed from two selected parent birds.
  5. Mutation: Small random offsets (Gaussian noise) are added to the weights and biases of children to discover new strategies.

📁 File Structure

  • index.html: UI structure, sliders, buttons, canvas elements, and data display cards.
  • style.css: Glassmorphic dashboard styles, neon grid background effects, and custom sliders.
  • nn.js: Forward propagation logic, mutations, and uniform crossovers.
  • ga.js: Breeding, fitness aggregation, and roulette-selection handlers.
  • game.js: Physics updating, parallax starry skyline, collision handlers, and flock renderers.
  • app.js: Coordination script connecting UI actions, storage interfaces, chart renders, and the active animation loops.

🕹️ Interactive Features

  • Speed Multipliers: Speed up physics updates (2x, 5x, 10x, 20x, or MAX) to accelerate training speeds.
  • Manual Mode: Take control of a custom red bird by pressing Spacebar or clicking the canvas to challenge the AI.
  • Live Neural Network Diagram: Highlights active neurons and shows positive (cyan) and negative (red) weights of the leading bird.
  • Fitness Graph: Plots the highest and average fitness scores over time to visualize training trends.
  • Save/Load Brain: Export the current leading brain to LocalStorage so you can restore training progress later.

About

🧠 Simple simulation of genetic algorithm and flappy bird game play

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages