Undergraduate AI Course Final Project · May 2005 · Web port, 2026

Genetic Algorithm Simulation

A population of single-pixel organisms lives on a bitmap world. Each organism’s genome is its color — a 24-bit string, eight bits each for red, green, and blue. Organisms sense the pixels around them, feed on green in the terrain, breed with neighbours by crossover and mutation, and die when their energy runs out. What survives is whatever persists through the entropy.

Loading the 2005 island map…
×2

Click any organism to inspect its genome. The map shown is the author’s original island.bmp / globe.bmp from May 2005, converted losslessly to PNG.

Live statistics

–
Population
0
Generation
0
Births
0
Deaths
Mean genome color
R – · G – · B –
R meanG meanB meanper generation

Organism inspector

Hover or click an organism in the world to read its genetic string — the 24 bits that are its color, its heredity, and its appearance at once.

How it works

The genome is the color. Every organism carries a 24-bit genetic string — 8 bits each for red, green, and blue — and is drawn as a pixel in exactly that color. There is no separate genotype and phenotype; what it looks like is what it inherits and passes on.

The world is an image. The terrain is a 500×500 bitmap. A cell is livable only where the map’s own color satisfies the original’s rule — R ≤ 148, G ≥ 50, B ≤ 128 — which in practice means land, not water or sky. Organisms spawn, and children are placed, only on livable cells, retrying until they land on one.

Sensing and feeding. Each organism reads the cells north, south, east, and west of itself — the original code’s neighbour sensing, written “for finding food or breeding objects” — and moves toward the richest food. Food is the green in the terrain: standing on green feeds the organism and restores its energy budget; grazed cells are depleted and slowly regrow.

Selection and breeding. Every generation, organisms enter a mating pool in proportion to their fitness — fitness-proportionate (roulette-style) selection, as in the 2005 design. Only organisms sharing one of the world’s 50×50 regions can breed. Two parents’ 24-bit strings are spliced at one random crossover point to make two children, and exactly one random bit in each child’s string is then flipped: mutation. Children are placed beside a parent, breeding costs the parents energy, and an organism whose budget empties dies. Population starts at 100, as in the original; this port caps it at 4,000 for the browser (the 2005 cap was 25,000).

What was fixed in the port

The 2005 source designed more than it finished. This port completes the design and repairs the defects, without changing the algorithm’s character:

  • The lifecycle is wired in. The original’s entity status struct declared Alive, Eating, Breeding and a tillDeath clock that no loop ever used. Here energy drains, feeding restores it, breeding spends it, and death removes the organism — the boom-and-crash ecology the design intended.
  • Generations run automatically. In 2005, propagation happened only when the spacebar was pressed. The step button above remains, in homage; the simulation no longer needs it.
  • The fitness formula can no longer zero out. The original’s fitness-proportion arithmetic could silently assign an organism no chance of breeding; selection here uses a corrected proportion with a floor.
  • A spawn-collision check compared one entity’s Y coordinate to another’s X. Placement now checks the actual cell.
  • modifyGeneticString was an empty stub (bitwise AND/OR/XOR genome modification was planned and never written). Genetic change in this port flows through the operators the original did finish — crossover and single-bit mutation.

Reading the result

Watch the mean swatch. Random founding genomes average out to grey. As feeding and selection favour organisms adapted to green terrain, the population’s mean color drifts — evolution made visible in a single square, and traced per generation in the chart.

Booms and crashes are the ecology working. When food is plentiful the population grows until grazing outruns regrowth; budgets empty, deaths outnumber births, and the survivors are the lineages that fed best. Nothing in the code scripts this — it emerges from the same operators the 2005 program used.

Inspect individuals. Clicking an organism shows its exact 24-bit string grouped by channel. Two organisms that look almost alike can differ by one flipped bit — that difference is precisely what their children may inherit.

Provenance

Genetic algorithm simulation originally written in C++ and OpenGL in May 2005 by Mark R. Havens (with Michael Coody) as an undergraduate AI course final project. Pixel organisms carry their genome as color; they sense neighboring pixels, feed on green, breed by crossover with mutation, and die. This page is a faithful web port of the recovered 2005 source, with the lifecycle the original designed but left unwired now completed. The world maps are the original 2005 bitmaps.

entity.h — genome, crossover, mutation, fitness, neighbour sensing (comments dated MRH050506–0507)
finalproj.cpp — world, livability rule, propagation, rendering
settings.h — 500×500 world, population cap 25,000
island.bmp / globe.bmp — world maps, May 6 2005