All notes on the Swarm Game
SWARM
Designing Emergent Behaviour Through Pheromone Fields
The idea
I have always been fascinated by the idea of designing a game, but I wanted to make something more than a game with interesting mechanics. I wanted to create a system that could surprise me.
Throughout school, and often even in college, learning rarely feels exploratory. We are taught scientific facts, but not always the experience of discovering them. If we were stranded in an unknown star system with no memory—yes, a Project Hail Mary reference—most of us would have little idea how to determine where we were.
I wanted to capture that feeling of discovery in a game without making an explicitly educational game.
Around the same time, I became increasingly interested in random and emergent systems through Math Circle, and I was inspired by Richard Feynman's experiments with ants. That led to a simple question:
Could I build a system whose behaviour I could influence without directly controlling it?
That question became Swarm.
1. The original experiment
The first version was not a combat game.
It was an experiment in emergence.
Instead of controlling individual ants, I wanted the player to manipulate the environment in which the ants operated. The player could place chemical signals, but the ants themselves followed a set of simple rules.
The interesting part was that the player could never explicitly tell an ant:
"Go there."
Instead, the player had to create the conditions under which the ant would choose to go there.
This distinction became the central design principle of the entire project.
The player controls the environment, not the agents.
I represented pheromones as discrete scalar fields defined over a grid. Every cell contained information about the strength of different chemical signals.
The original system primarily used three types of pheromone:
Trail pheromone
This was the weakest influence. Ants could use it to retrace paths they had already explored.
Player pheromone
This was placed by the player. Rather than specifying a destination, it created a gradient that influenced ant movement.
Home pheromone
Returning ants deposited this pheromone as they travelled back toward the nest. Over time, successful routes became reinforced.
This produced a feedback loop:
ant finds food → returns home → reinforces path → other ants follow it → path becomes stronger → more ants use it.
The player wasn't programming a highway.
The highway emerged from the system.
2. Building the fields
The pheromone system was built around discrete scalar fields rather than simply storing paths.
Each field represented a value at every cell in the environment.
The ants sampled these fields and used their local gradients to influence movement.
The fields also changed over time.
Signals:
- diffused through neighbouring cells
- decayed
- interacted with other signals
- were reinforced by new deposits
This meant that the game wasn't simply calculating:
"Where should this ant go?"
It was continuously evolving a physical-ish environment and allowing the ant simulation to react to it.
One of the things I particularly liked was that the system was not deterministic in the way a traditional pathfinding system is. Exploration, noise, decay and competing signals meant that identical high-level conditions could produce different local behaviour.
That unpredictability was not a bug.
It was the point.
3. The first thing I learned: emergence is fragile
The system initially looked promising, but it was extremely sensitive to the relative strengths of its fields.
If one pheromone became too strong, it dominated everything else.
If decay was too fast, trails disappeared before they could become useful.
If exploration was too low, ants became excessively committed to existing paths.
If noise was too high, the colony stopped behaving coherently.
This became one of the most interesting parts of the project.
I wasn't simply balancing game variables.
I was trying to find a region in parameter space where simple local rules produced interesting global behaviour.
The goal wasn't maximum efficiency.
It was a system that was:
- predictable enough to learn,
- unpredictable enough to explore,
- responsive enough to manipulate,
- autonomous enough to feel alive.
That balance became the real game mechanic.
4. From experiment to game
Eventually I wanted to push the system further.
The original prototype was essentially a real-time puzzle about sculpting emergent behaviour through chemical fields.
I started asking:
What if the same principle became the basis of combat?
That led to the current Swarm prototype, which evolved into a combat roguelite inspired by games such as Hades.
But I deliberately refused to make it a conventional hack-and-slash game.
The player is intentionally weak.
They cannot simply attack an enemy themselves.
Instead, the player influences the swarm.
This preserved the original idea:
The player does not command the swarm directly. They manipulate the ecosystem and allow order to emerge.
5. Turning pheromones into a combat system
I developed several pheromone abilities that give the player increasingly sophisticated ways to influence the swarm.
Passive Nest Pheromone
The player constantly emits a weak nest pheromone.
Nearby ants are gently attracted toward the player, allowing the player to reposition the swarm without explicitly commanding it.
Hunt Pheromone
The player can create stronger directional pheromone gradients that guide ants toward enemies.
I experimented with several behaviours:
Direct Hunt
The swarm moves directly toward the selected target.
Looping Hunt
The pheromone creates a route that sends ants toward the target and then back around, allowing the swarm to repeatedly engage.
Multiple-Target Hunt
The field can coordinate the swarm across multiple targets.
Bounce Hunt
The signal jumps from one target to another, allowing the swarm to chain between enemies.
The important part is that these aren't commands like:
"Ant #12 attack Enemy #3."
They are fields.
The ants still make their own local decisions.
6. Manipulating the swarm without controlling it
I also added abilities that don't tell the swarm where to go at all.
Scatter Pheromone
Disperses nearby ants.
This lets the player break up concentrations when enemies are about to attack.
Amplified Nest Pheromone
A stronger version of the normal nest signal that rapidly attracts ants toward the player.
Localized Scatter Pulse
Creates a strong scattering field around the player, immediately forcing the swarm to spread outward.
Hide Pheromone
Temporarily conceals ants from enemies.
These abilities created an interesting tension.
The optimal strategy isn't simply:
Get as many ants together as possible.
Sometimes concentration is powerful.
Sometimes concentration is exactly what gets the swarm destroyed.
The player therefore has to reason about the state of the entire system, rather than just the position of an individual character.
7. Designing enemies around the system
Once the swarm became the core mechanic, I didn't want enemies to simply have different amounts of health or damage.
I designed enemies specifically to attack different weaknesses in the swarm system.
Assassin — attacks the player
The Assassin prioritizes the player instead of the swarm.
It forces the player to use the swarm defensively while simultaneously managing their own movement.
The problem it creates is:
Can I manipulate the swarm while protecting myself?
Predator — attacks concentration
The Predator searches for dense clusters of swarm units.
When it detects one, it enters a charge state and attacks the cluster.
This creates a direct conflict with the player's natural instinct to gather the swarm.
The player must alternate between:
gather → attack → scatter → reposition → gather again.
Firewall — attacks pheromone reliability
The Firewall is surrounded by a pheromone distortion field.
Nearby pheromones become weaker or distorted.
This means the player enters an area where the very mechanism they normally rely on becomes unreliable.
Instead of simply fighting a stronger enemy, the player is fighting a change in the rules of the system.
Parasite — attacks the information network
The Parasite infects swarm units.
Infected ants emit incorrect pheromone signals, and the infection can spread.
This is particularly interesting because pheromones are effectively the swarm's communication network.
The enemy doesn't merely damage the ants.
It corrupts the information that the ants use to coordinate.
Collector — attacks attention
The Collector stays at range and deploys collection pods that capture nearby swarm units.
Destroying the pod releases them.
This introduces a secondary objective and forces the player to divide attention between the main enemy and the infrastructure threatening the swarm.
Pheromone Flood Mine — attacks signal clarity
The Flood Mine releases a large pheromone burst when triggered.
Instead of directly damaging the player, it changes the environment the swarm is interpreting.
It effectively injects noise into the system.
Pheromone Erasure Mine — attacks infrastructure
The Erasure Mine removes pheromones within an area.
This is the opposite problem.
The Flood Mine gives the swarm too much information.
The Erasure Mine removes the information the swarm depends on.
Together they create two different ways of disrupting the same underlying system.
Inverter — attacks the player's own decision-making
The Inverter temporarily reverses the player's pheromone controls.
Attack commands become Scatter commands.
Scatter commands become Attack commands.
This is probably the most direct expression of the game's philosophy.
The enemy isn't simply making the swarm weaker.
It changes the relationship between the player's intention and the system's response.
8. The technical model
Underneath the game, the core simulation is still based on the original field system.
The Godot implementation re-created the original JavaScript scalar-field model using packed floating-point arrays.
The fields use diffusion and decay to preserve gradients rather than immediately flattening them.
Different decay constants are used for different pheromone types, allowing signals to have different temporal behaviours.
For example, some signals need to persist long enough to establish a route, while others should disappear rapidly so that they function more like temporary commands.
The simulation is also designed to be independent of frame rate, with time-scaled updates rather than simply changing behaviour depending on how quickly the computer happens to render frames.
9. From scalar fields to directional behaviour
One of the biggest technical challenges was translating the scalar field into actual movement.
A scalar field tells an ant:
"How strong is the signal here?"
But the ant needs to determine:
"Which direction should I move?"
The solution was to use the local gradient of the field.
The ant samples neighbouring cells and derives the direction in which the pheromone signal changes.
That gradient becomes an influence on movement.
But I didn't want ants to behave like perfect gradient-following particles.
Realistic-looking swarm behaviour needed imperfections.
So the movement model includes things such as:
- directional continuity
- random noise
- exploration
- homeward bias
- multiple competing pheromone influences
The result is not a clean shortest-path algorithm.
It is a noisy dynamical system.
And that distinction is what makes the swarm feel alive.
10. The loop that emerged
One of the most satisfying behaviours was the emergence of a self-reinforcing loop.
A forager discovers food.
It returns toward the nest.
While returning, it reinforces the home pheromone.
Other ants detect the resulting gradient.
They follow the route.
Those ants then reinforce the route further.
Eventually, the colony develops an efficient source-to-nest highway without ever being told to construct one.
The system creates its own infrastructure.
That was the moment the original idea really worked.
I wasn't watching an animation of ants behaving like ants.
I was watching a set of simple rules produce behaviour that I had not explicitly programmed.
11. What went wrong
The project also taught me that making emergent systems is much harder than simply making complicated systems.
At one point, the implementation became much more computationally expensive after directional/vector-field logic was introduced.
Instead of one shared representation of the environment, the system began creating unnecessary combinations of fields.
With many ants and many fields, the computation grew rapidly.
More importantly, the change damaged something more important than performance:
the emergent behaviour itself.
The original system felt organic because the ants were responding to shared environmental information.
The new implementation made the behaviour too explicitly engineered.
It was faster to reason about locally, but less interesting globally.
That forced me to step back and reconsider what I was actually optimizing for.
I wasn't trying to create the most sophisticated AI.
I was trying to create the conditions for unexpected collective behaviour.
That distinction changed how I approached the entire project.
12. Why I kept building it
The most interesting part of Swarm isn't that I managed to make ants follow pheromones.
It's that the project changed the way I think about control.
Traditional game design often asks:
What should the character do?
Swarm asks a different question:
What conditions should I create so that the character does what I want?
That idea connects the game's mechanics to the way many real systems behave.
A colony doesn't need a central commander.
A traffic system doesn't require one person directing every car.
A market doesn't require someone telling every participant what to do.
Complex behaviour can emerge from relatively simple local interactions.
I wanted to make that phenomenon something the player could feel rather than simply read about.
13. What I am still trying to solve
The project is far from finished.
The biggest challenge is still the interaction between the different fields.
If one signal dominates too much, the swarm becomes predictable.
If the fields are too weak, the player loses influence.
If the system is too chaotic, the player can't understand why something happened.
The ideal system sits somewhere between those extremes:
I should understand enough to form a hypothesis, but never enough to know exactly what every ant will do.
That is the feeling I am still trying to achieve.
Because ultimately, I don't want Swarm to teach the player about emergence.
I want the player to experience it.
The central idea
Swarm started with ants.
It became a game about pheromones.
Then it became a game about combat.
But underneath all of those layers, the idea has stayed the same:
I don't want to tell a system what to do. I want to understand it well enough to create the conditions under which it can surprise me.
That is what I was trying to build.
And, in a strange way, that is also what made the project fun to make.
Comments
Post a Comment
Please share your thoughts, comments, feedback...