More rats do not make a colony. Put many in the same box and you still have several one-rat systems. A colony begins when each rat becomes part of another's input. One rat's position enters another's view. A win changes the next win rate. A smell changes where someone goes. Rank changes who gets to breed.

I don't reproduce collapse here; first I build a colony that persists. And I design none of the structure. I add one local rule at a time to the apparatus, and watch whether rank, herding, and territory come out on their own.

Other rats become input

The starting point is the single rat from before. The difference: results no longer come only from the world, but from other rats too.

for rat in rats
    act!(rat, observe(world, rat))
end

for (a, b) in encounters(world)
    learn!(a, contest(a, b))
    learn!(b, contest(b, a))
end

Approach, avoid, push back, win, lose. Another rat's move becomes my next input. From here, a rat adapts not only to the world but to its neighbors.

Rank appears

I add encounters and contests to the apparatus. Each rat has a confidence, all nearly equal at the start. Meet at the food area and a scuffle happens: win and confidence rises a little, lose and it drops. I never assign who is on top.

win_rate = sigmoid(a.confidence - b.confidence)
winner, loser = contest(a, b, win_rate)
winner.confidence += delta
loser.confidence  -= delta

Run it, and rank appeared. Small differences get amplified through contests. A winner wins more, a loser loses more, until a straight order lines up. The top get into the food area easily, the bottom wait. A social position comes back as a bodily state, hunger.

rat colony where rank separates through encounters at the food area
Encounters at the food area. Rank lines up from wins and losses, and higher-ranking rats get easier access to food.

A herd appears

Next I add a predator. I never write "form a group." The predator picks off whoever is alone. A rat that feels danger moves toward nearby rats, and backs off if it gets too close. That's all. Run it, and when the predator comes, distances shrink; when it leaves, they scatter. I never set a center. The herd is what's left when each rat lowers its own risk in a world where being alone is dangerous.

rats gathering when a predator approaches
When the predator appears, the rats gather; when it leaves, they scatter. Herding comes from lowering the risk of being alone.

Territory separates

Rank and herding still don't fix who lives where. So I add scent marking. A rat leaves smell where it passes; the smell spreads and fades. It avoids places thick with others' smell and returns to its own. No compartments are given.

push!(world.scent[rat.id], rat.position)

own   = world.scent[rat.id][rat.position]
other = other_scent(world, rat)[rat.position]

move_toward!(rat, own - other)

The boundary is not a drawn line. Leave smell, avoid others' smell, and each rat's usable range separates on its own.

Territories separating through scent marking
Territory from scent marking. Without assigned compartments, each rat returns to its own range.

Rank reaches reproduction

Last, I tie rank to reproduction. To see whether a colony carries into the next generation, staying alive isn't enough: who leaves offspring, and what they inherit. Each rat carries a competitive trait; higher rank means more offspring, and a child inherits the parent's trait with small changes.

parents = select_by_rank(rats)

for parent in parents
    push!(next_generation, reproduce(parent; mutation=true))
end

Rank is now not just a momentary result. It is a variable that changes the next generation. When the top leave more offspring, the average competitive trait drifts across generations. Social structure becomes a condition for evolution.

Rank-biased reproduction and changes in competitive traits
Rank tied to reproduction. When higher-ranking rats leave more offspring, the distribution of competitive traits shifts across generations.

I designed none of it. Adding local rules to the apparatus, rank, herding, territory, and evolution came out of the colony. The next apparatus keeps food and water plentiful, and looks for the condition that breaks this colony.

Notes

  1. Winner-loser effect: A winner is more likely to win next time, and a loser to lose. Used here to grow rank from the history of encounters instead of assigning it.
  2. Scent marking: Leaving body scent where you pass and avoiding others' scent, so ranges separate. Territory appears without any compartments being assigned.