Swarms
Many small, cheap bots instead of one big one: three Bestiary herds that line up by sight, follow each other by password, or pass an alarm along by word of mouth, with no boss at all.
After the tutorials you're left with a bot that is a unit: it sees, chases, shoots and divides. The idea of a swarm is the opposite: instead of one big, expensive bot, many small, cheap ones that all do the same thing. Each copy is expendable; the herd isn't. This page dissects three Bestiary swarms with three different ways of getting together—by sight, by password and by warnings—and shows what each one gains and what it pays.
What it gains and what it pays
The first thing a swarm gains is coverage. A single bot, with the factory eyes, covers 90 degrees (Vision); twenty copies spread out cover twenty different fields, and the first one that finds food drags the rest along. Also, a small bot is a small target: the eyes measure from edge to edge, so at the same distance a tiny body gives lower numbers and is detected later (Vision).
The second is resilience. A predator can kill one bot; it can't kill thirty without one of them dividing in the meantime. Reproducing is cheap in itself: .repro hands out a percentage of energy and body, so 10 .repro makes a small child and 50 .repro one that is born with half of everything (Reproduction). A herd that loses twenty members comes back from the ten that are left.
And what it pays. Every living bot is charged upkeep per cycle: a fee per point of body and another for each DNA instruction (Energy, body and waste). Ten copies pay ten times the fee for the whole genome; and every birth, besides the tax, pays for its copy of the DNA (DNA copy). With costs at 0, as the app starts, living is free; under F1 rules, every extra member weighs.
The other price is physical: the members bump into each other. A collision separates the two and changes their velocity (Physics), so a tight herd spends thrust pushing itself around. You'll see it in this page's runs: the real Bestiary swarms live with the collision, they don't avoid it.
Coordinating without a boss
No boss is possible: no bot can give global orders, each one reads only its own senses. The Bestiary's swarms come together along three paths, from least to most signal:
| Path | Mechanism | Bots here |
|---|---|---|
| Loose behavior | Everyone follows the same local rule and order appears on its own | SWARM 2.0 |
| Following by sight | Copy the heading of the brother you see, or recognize it by signature or password | Mr_Swarm |
| Warnings through out/in | Publish data in .out1 and .in1 for others to read | SocialSwarmX |
The first row is the idea of flocks of birds: nobody steers, each one imitates its neighbor. The second and the third use what you saw in A bot that recognizes its own species: the DNA signature (ref* against my*) and the public password.
Lining up by sight: SWARM 2.0
SWARM 2.0 F2 Elite (in the Bestiary, SWARM_2.0_F2_Elite_-10.03.07.txt) is a swarm of barely ten genes that doesn't even use a public password to recognize its brothers: it only compares signatures. It opens its front eye .eye5 to a width of 1220, almost the whole way around, and since range falls with width, it sees only about 150 units around itself: it's a short-range radar, not a telescope.
' Panoramic front eye
cond
*.robage 0 =
start
1220 .eye5width store
stop
' Every 5 cycles: if I see a brother, look where he is looking
cond
*.robage 5 mod 0 =
*.eye5 0 >
*.refeye *.myeye =
start
*.refaim .setaim *.robage sgn mult store
stopThat second rule is the whole swarm: every five cycles, the nearest brother falling in the panoramic eye dictates the heading, by copying its .refaim with .setaim. Since everyone always moves ahead at full speed (*.maxvel *.vel sub .up store), a herd that crosses paths up close ends up sailing together toward wherever the first one was looking. Nobody leads: each one imitates its neighbor, and the order comes out on its own.
Against a stranger the signature doesn't match (*.refeye *.myeye !=) and it becomes food: it chases it at full speed and, as it closes in, shoots it with −6 (*.eye6 34 > means “I see it off to the side”), the shot that steals body and gives back a −2 with the loot. In the run, a single copy bled a stationary prey dry in 16 cycles and ended with 13375 energy from 3000: the other bot's body converted into its own energy, which is where the whole herd comes from. After that, with *.body 700 >, each one splits off 30% and the herd grows by itself.
Its two weak spots, measured: it pays no attention to the edges of the world (in a field with walls it ends up piled against them, pushing), and the birth gene also draws a turn (314 rnd .aimdx), which keeps it turning at random while the birth retries. In a small field, a pair gets tangled: they see each other with 32000, collide and their headings go around in circles. The swarm wins in the open field.
The herd with a password: Mr_Swarm
Mr_Swarm (Mr_Swarm.txt) bets on the password. Each copy publishes a 43 in .out1 in its first cycle and never again; whoever has a brother in its focus eye reads it in .in1 (A bot that recognizes its own species). In a run with six copies, all of them had the 43 published and received within 20 cycles, without a shot between them.
' A brother ahead: note it down once
cond
*.in1 43 =
*.eye5 1 >
*.shoot 0 =
*27 0 <=
start
27 inc
stop
' And copy his heading
cond
*27 1 >=
*.shoot 0 =
*.reffixed 0 =
start
*.refaim .setaim store
27 dec
stopFollowing the brother means copying its heading with .refaim—the same mechanism as SWARM, with a counter so it isn't rewritten every cycle—and moving toward it. Measured with two copies: the headings converged and stayed pinned there (460 and 460, then 759 and 759, for twenty cycles). The password also arrives by collision, not just by sight: the in* get filled the same way when bodies touch (Vision).
It treats the stranger who doesn't publish the 43 differently: it shoots it with −1, the shot that drains energy, while aiming at it and advancing.
' Something ahead that isn't from the herd: drain its energy
cond
*.eye5 1 >
*.in1 43 !=
start
-1 .shoot store
1 .out2 store
1 .up store
stopIn the run against a stationary prey, it found it within ten cycles, raised its flag in .out2 (which its brothers can read through .in2) and left it dead before cycle 20, finishing with 6164 energy. Apart from that, it breaks the birth tie in the first cycle and, when it touches an edge, turns at random and stops reacting to the edge for thirty cycles (*.edge with a timer), so it doesn't pile up against the walls like SWARM, and it only reproduces with 120 body, more than 8000 energy and 100 cycles of life: first the herd, then the children.
The alarm by word of mouth: SocialSwarmX
SocialSwarmX (SocialSwarmX.txt) doesn't follow: it passes data along. The one that sees food publishes where it is, using the pair of cells as coordinates:
' I see a stranger: publish its position
cond
*.eye5 0 >
*.refeye *.myeye !=
start
*.refxpos .out1 store
*.refypos .out2 store
*.refveldx .dx *.eye5 sgn mult store
stop
' I see a brother who already has the data: repeat it
cond
*.eye5 0 >
*.refeye *.myeye =
*.in1 0 !=
*.in2 0 !=
start
*.in1 .out1 store
*.in2 .out2 store
stopSince any bot that sees you reads your out* in its in*, the warning jumps from brother to brother: whoever sees publishes, whoever sees that one repeats. In the run, one member published the exact position of the prey (114, 486) and in that same cycle another already had it noted in its in1. The alarm only matters between brothers, so the relay requires the signature.
Who answers it? The hungry one:
' With little body and a position in hand: go there
cond
*.body 500 <
*.out1 0 !=
*.out2 0 !=
start
*.out1 *.out2 angle .setaim store
stopWith angle the stored position becomes a heading. The full ones don't move; the skinny ones converge. At the end of the run the whole herd was crowded into the corner where the prey had died, eating it with −6 shots: since the out* don't clear on their own, the alarm stayed lit over the corpse, which was exactly the place worth going to.
One extra lesson from this bot: read what the DNA does, not what its name promises. Its first gene wants to break the birth tie with an address calculation, but the calculation incidentally overwrites the .repro cell: at 9 cycles each copy writes a 1 there and gives birth to a child with 1% of its energy. In the run these dwarf children (41 energy, 9 body) kept appearing and slowly dying. The swarm works all the same; the real strategy is messier than the legend.
A minimal swarm
To see the alignment mechanism with nothing on top, three genes are enough. The local rule is just one: if the nearest one I see is a brother, I look where he is looking.
' Panoramic front eye, just once
cond
*.robage 0 =
start
1221 .eye5width store
stop
' A brother in sight: copy his heading
cond
*.eye5 0 >
*.refeye *.myeye =
start
*.refaim .setaim store
stop
' Always move ahead
cond
*.velscalar 20 <
start
20 .up store
stopSeed four copies in a small field and watch .aim: in the run, by ten cycles all four pointed at exactly the same heading and held it, sailing as a school until they hit the wall (they have no edge gene, like SWARM). Change *.refaim to *.refxpos *.refypos angle and instead of following him they go straight at him: the same channel, a different behavior. Add .repro with a small percentage and a hunger condition, and you have a herd that reproduces instead of piling up.
What to try next
Dividing up roles. Publish a role number in .out1 at birth (a different one per copy, with rnd): the ones that come out as hunters shoot, the ones that come out as gatherers collect. Mr_Swarm's password already separates “mine” from “stranger”; separating “hunter” from “gatherer” is the same channel with another number.
A swarm that flees. The warning works for the opposite too: whoever gets shot publishes the shooter's direction and the others avoid it. Attack signals and danger signals live in the same family; for the defenses that complement this, see Defensive bots.
Tied or loose. The difference from a multibot is the tie: tied, an organism shares energy and carries out commands through ports, but it pays for each tie and loses the whole organism together (A multibot). Loose, each copy dies alone and the herd goes on. Compare your swarm against a Bestiary multibot in a match.
Letting it evolve. With mutations switched on (Mutations), each copy's signature drifts on its own and the herd can split into new species: the 43 password is written once per copy, so a mutation in that gene is enough for a lineage to stop recognizing its brothers. A swarm is a good substrate for your first evolution experiment: there are plenty of copies, and the ones that mutate badly die on their own.