Kingdom Ant Farm: Simulating a Real Ant Colony from Scratch
Four days ago, Kingdom Ant Farm didn’t exist. Today it’s a working prototype with grain-level terrain physics, biologically accurate ant behavior, and a colony that grew itself from a single founding queen to 71 workers. Sixty-eight commits in four days. Here’s why it exists and what makes it interesting.
Why Ants, Why Now
I’ve always been fascinated by ant colonies as systems. Not the “ants marching in a line” surface-level stuff, but the deeper question: how do thousands of individuals with no central authority build something that functions like a single organism? Most ant games treat the colony as a strategy game — you place buildings, assign workers, manage resources from a god’s-eye view. I wanted to go the other direction. What if every ant was a real agent, making its own decisions based on its own hunger and the chemical signals around it? What if the dirt was real dirt?
The project started on April 1st with a game design document. The premise is simple: you’re watching a colony establish itself in a backyard. Zones unlock as the colony grows. The core loop is idle-first — the ants do their thing whether you’re watching or not, but you can nudge priorities, place food sources, and manage threats. I originally scoped it for Steam with a species roster and DLC plans, but before any of that matters, the simulation has to feel alive. So that’s where I spent the next three days.
Throwing Out the Grid
The first prototype used a tile-based terrain system. Standard approach — the world is a grid, each cell is either dirt, air, or tunnel. Ants dig by flipping tiles from one state to another. It works, and almost every ant game I’ve seen does it this way. But it looked wrong. Tunnels came out as blocky corridors. Chambers were perfect rectangles. Nothing about it felt like something an animal had carved.
So on day three, I threw it out and replaced it with grain-level cellular automata. Every visible speck of soil is an individually tracked grain. The terrain is a dense grid at the grain level, not the tile level. When an ant digs, it removes one grain. When it deposits excavated material on the surface, that grain obeys simple physics — it falls, it piles up, it finds a resting angle.
Night and day. Tunnels naturally narrow to about two grains wide, because that’s the width the ants carve as they walk. Mounds form organically on the surface as excavated dirt accumulates, grain by grain, into the little volcano-shaped hills you see around real ant nests. Chambers aren’t rectangles — they’re rough ovals carved out one particle at a time. None of this is authored. It’s emergent from the physics.
The performance cost is real — the world is 2400 pixels deep, 1200 grains of vertical space. But the simulation is idle-friendly and runs at selectable speeds (1x, 2x, 5x, 10x), so I can spread the physics updates over frames without anyone noticing.
Building Ants from Biology
The behavior system is modeled on Lasius niger, the common black garden ant. I chose this species because it’s the most studied ant in the world and its colony lifecycle is extremely well documented. I didn’t want to invent fake game-ant behavior when the real thing is already more interesting than anything I’d design.
Every ant has a crop (a social stomach) and a personal hunger level. Task switching isn’t controlled by a job board or an assignment screen. It’s driven by an exponential hunger curve. A well-fed ant stays on its current task — digging, nursing, foraging, whatever. As its crop empties, the urgency to find food rises exponentially. At a threshold, it drops everything and goes looking for a meal. No job boards, no assignment screens. Just ants being ants. It looks like chaos, which is exactly what a real colony looks like.
The queen’s egg-laying is physiology-driven, not timer-based. She lays when her body condition supports it, which depends on how well-fed she’s been. Feed the queen well and the colony booms. Neglect her and growth stalls. No artificial spawn timers.
Trophallaxis — the mouth-to-mouth food sharing that real ants do — was one of the trickiest systems to get right. Two ants meet, one has food, the other needs it, and they exchange. Simple in concept, nightmarish in practice. Without cooldowns, two ants would pass the same food back and forth forever in a ping-pong loop. With cooldowns too aggressive, food wouldn’t distribute through the colony fast enough and the queen would starve.
Nurse ants were another challenge. In a real colony, nurses tend the brood — feeding larvae, grooming eggs, moving pupae to the right temperature zones. But nurses are also ants with their own hunger. I had to build a priority system where a nurse will break away from brood care to forage for herself when her own crop gets low, then return to nursing once she’s eaten. Foragers, meanwhile, don’t hoard food at the source. They fill their crop and carry it back to the nest to share with the colony, just like real foragers do.
The Colony Expansion Planner
Random digging makes for interesting-looking tunnels but a dysfunctional colony. Real ants build with purpose — entrance tunnels, brood chambers, food storage, waste areas. I built a colony expansion planner that identifies when the colony needs a new chamber (based on population and brood count), picks a location connected to the existing tunnel network, and assigns digger ants to carve it out.
When a chamber is completed, it gets registered in the colony’s spatial map. The queen migrates to the largest available chamber. Brood gets placed in dedicated nursery areas. This is where the grain physics and the behavior engine meet — the planner decides what to build, but the shape of the result is entirely determined by individual ants removing individual grains. Two colonies will never look the same.
What Went Wrong (and Got Fixed)
Sixty-eight commits in four days means a lot of bug fixes. The queen kept starving because nurses wouldn’t prioritize feeding her. Pathfinding broke when tunnels got too narrow or too winding. The entrance would clog with ants trying to enter and exit at the same time. Mound deposits would pile up asymmetrically because ants always dropped dirt on the same side. Camera controls fought with user input when trying to follow an ant and scroll simultaneously. Food hoarding loops emerged where foragers would pick up food, walk two steps, drop it, pick it up again.
Each of these bugs was a lesson in emergent systems. You don’t get these problems in a game where you script behavior from the top down. You get them when agents are actually making decisions, and their decisions interact in ways you didn’t predict. That’s also what makes it fun to watch. When it works, it works for the right reasons.
Where It Stands
Right now Kingdom Ant Farm has grain-level physics, a biology-based behavior engine, colony growth from queen to 71+ workers, save/load/reset, speed controls, brood rendering, and chamber lifecycle. It’s a prototype, but you can sit and watch ants dig and feed and build and it feels real. That was the bar.
Long road ahead — threats, zones, multiple species, the full idle loop. But the hard part was always the simulation core. If the ants don’t feel like ants, nothing else matters. They feel like ants.
More updates coming as the colony grows.
— Bruno