Insight 3 min read

The Three Boid Problem: Chaos, Stability, and the Ecology in Your Browser

Three species. No central controller. A digital ecosystem with the same fragility as Liu Cixin's unkind universe — running in your browser.

primitive simulation of ducks and resource patches

In Liu Cixin’s The Three Body Problem, the universe is indifferent. Three gravitational bodies create a system with no closed-form solution — civilizations rise in “Stable Eras” only to be incinerated when a “Chaotic Era” begins without warning.

I’ve spent the last few weeks building a digital ecosystem with that same fragility. But instead of suns and planets, my “bodies” are birds, flies, and dung.

I call it drd.

A Screensaver from 1996

This started with a specific brand of 90s nostalgia. A Windows screensaver — some primitive simulation of ducks and resource patches. It wasn’t programmed to be interesting; it just was. The population would spike, crash, and stabilize in a way that felt more alive than the Flying Toasters of the era.

drd (Ducks Round Dung) is a modern realization of that memory. The question driving it: how deep does that “aliveness” go when you scale to hundreds of thousands of concurrent agents?

The Three-Species Loop

The simulation is a closed loop. No central controller — only local rules and emergent visual patterns.

Birds are the primary hunters, represented by long, sweeping neon-cyan trails. They flock, hunt flies, and deposit dung when energy runs high. Flies appear as jittery, shorter trails swarming in tight clusters, darting toward food sources while trying to outmaneuver the birds. Dung is the fuel — static, golden-yellow clusters scattered across the dark void. It is deposited by birds and consumed by flies.

No species survives alone. Birds eat all the flies, the birds starve. The flies disappear, the dung piles up until the system stalls.

The Search for Stability

Every slider in the control panel sits adjacent to a bifurcation point — a value where the system tips from predictable oscillation into complete chaos.

In Balance, the “Stable Era,” populations rise and fall in a rhythmic pulse. Slow down dung decay and the canvas becomes a carpet of resources; birds gorge into a population explosion that ends in a catastrophic crash — call it Bloom. Constrain movement to cardinal directions and the simulation stops looking biological and starts looking like a flickering, geometric circuit board. That’s Frenzy.

The Optimizer: Finding Life in the Noise

Rather than tuning variables by hand, I wrote a hill-climbing algorithm that hunts for stability. It randomizes every parameter — speed, hunger, vision range — and watches. If a configuration survives longer than the last, it becomes the new parent.

What it finds doesn’t look designed. Dense, slow-moving clusters where agents pile into each other and somehow keep cycling. The algorithm doesn’t care about elegance; it cares about survival. Sometimes it finds the cliff instead — a configuration that fails, populations collapsing in sequence, only the fading trails of a defunct ecosystem remaining.

Genetic Drift: Lineages You Can See

Every agent carries a dna: vec4 signature — four genetic channels that persist and mutate through generations. Activate DNA Color Mode and color becomes a signal for fitness.

A sea of blue birds. A streak of neon green cuts through — faster, more efficient, or just luckier. Watch whether green expands or dies out. That’s natural selection running at frame rate.

Try It

The project is live at drd.edwardkahler.com.

Start with Balance. Watch one full cycle. Then turn on the Optimizer and walk away.

The three body problem has no stable solution. The three boid problem finds one — occasionally, by accident.

Source and architecture notes are on GitHub. The boid model traces to Craig Reynolds’ 1987 paper. The ecology traces to Lotka and Volterra. The original screensaver traces to a flickering CRT monitor scrounged together in the late 90s, running on a machine held together more by curiosity than screws.