How to use it
The rocket world starts running on its own: 150 rockets (100 on a narrow phone screen) launch from the pink start pad on the left and try to reach the target on the right. Within a few dozen generations the best ones usually find the gap. Watch the Reached and Best fitness numbers climb, then change something. Drag the target or the start pad, draw walls with the pointer, load another world, or move the mutation slider and see how the evolution reacts. The Word evolution tab runs the same algorithm on a different problem: it evolves random letters into a phrase you type.
A generation is one flight of the whole population. Step finishes it at once and breeds the next one, Fast-forward does that many times without drawing, and Inspect rocket shows any rocket’s DNA and parents.
Controls
- Mouse: drag the target or the start pad to move them. Otherwise the pointer draws walls (or erases, depending on the tool). Right-click erases.
- Touch: the same by touch.
- Keyboard: Space plays or pauses, S steps one generation, R resets. With the world focused, the arrow keys move the target and Shift plus the arrow keys move the start pad.
- Settings: all numbers can be typed. Settings, seed and world are remembered in this browser.
How it works
A genetic algorithm copies the logic of natural selection. It never solves the problem directly. It keeps a population of candidate solutions, scores them, and breeds the better ones.
- Genes and DNA. A rocket’s DNA is a list of thrust vectors, one gene per time slot of 5 ticks. In each slot the rocket pushes in the direction of that gene. The DNA view shows a gene as a coloured cell: hue is direction, brightness is strength.
- Fitness. After its flight a rocket scores cp, where c = 1 − d / D is its closeness to the target (d is the final distance, D the diagonal of the world) and p is the selection pressure you set. A rocket that crashed scores half. A rocket that arrived scores 1 + 2 × (1 − t / T), so earlier arrival is better (t is its arrival time, T the lifespan in ticks).
- Selection. Parents are chosen with a bias towards high fitness. Tournament draws k random rockets and takes the fittest. Roulette wheel picks each rocket with probability proportional to its fitness. Rank uses only the order, so a huge fitness gap does not dominate.
- Crossover. A child takes genes from two parents: single-point (parent A before a cut, parent B after it), two-point (B between two cuts) or uniform (a coin flip per gene). The DNA view shows which parent each gene came from.
- Mutation. Each gene of a child is replaced with probability r (the mutation rate) by a blend of the old gene and a random one. The strength sets how much of the new gene is used. Mutated genes are marked with triangles.
- Elitism. The best N rockets are copied into the next generation unchanged, so the best fitness cannot go down.
Mutation matters because crossover can only shuffle genes that already exist. Without mutation the population loses variety (watch the Diversity figure) and gets stuck. Too much mutation destroys good solutions faster than selection can keep them, so progress is slow and noisy. Words show it clearly: with 0% mutation the phrase can only contain letters that were in the first random population.
The wall also shows a local optimum. Rockets that touch the wall close to the target score well, so the population can pile up there instead of finding the gap. More variety (larger population, higher mutation, lower selection pressure) helps the swarm escape.
Genetic algorithms are used for design and scheduling problems where a solution can be scored but the best one cannot be written as a formula. They guarantee no optimum and need many evaluations. The demo is simplified: the rockets are points with drag and a speed limit.
Things to try
- Load Open field and press Fast-forward 10. Most rockets should reach the target within a few dozen generations.
- Load Wall with a gap and watch the first generations pile up at the wall. Look for the generation in which the first rocket gets through.
- Load Two staggered walls, set mutation to 0% and elitism to 0, and Reset with several different seeds (New seed). In some runs the Diversity figure drops to almost zero and the swarm stays stuck. Compare with 1–2%, then try 20%, which is too noisy to make progress.
- While the swarm is solving Two staggered walls, move the target to the other side. Watch the population adapt.
- Compare Tournament size 2 with 20, and selection pressure 1 with 8, over 50 generations with the same seed.
- In Word evolution, type a 20-letter phrase and compare the evaluations used with the number of tries random guessing would need.
- Use Inspect rocket to click a rocket and see its two parents.
Frequently asked questions
Is this how real evolution works?
It borrows the main ideas (variation, selection and inheritance) but it is a computer search method, not a model of biology. The fitness function here is chosen by us.
Why do the rockets sometimes get stuck at a wall?
The fitness only measures distance at the end of the flight, so getting close to the target behind a wall looks like progress. This local optimum is a classic problem. More mutation and a larger population help.
Does the same seed give the same result?
Yes. The flight physics has no randomness, and breeding uses a seeded random generator, so the same seed with the same settings and world replays the same run.
Does it work offline?
Yes. Everything runs in your browser and nothing is sent anywhere.