Wilden

Seeing what an animal knows

By Robin Dowling ยท 4 days ago

Every animal in the world carries a small memory. It remembers where it found food, where its herd was, and which other organisms turned out to be good or bad to eat. Animals even share what they know when they meet. But until now, all of that lived on the server. If you controlled an animal, you had no idea what it knew. Now you can see it.

An animal

A memory of 25 things

An animal can hold at most 25 pieces of knowledge at once. Each piece is either GOOD or BAD, and belongs to a category: a position where it found energy, a position where it met its own species, or a kind of organism it has learned to eat or avoid. When the memory is full, something old is forgotten to make room for something new.

This knowledge already shapes behavior. A hungry animal heads back toward a place it remembers being fed. A lost one drifts toward where it last saw its kind. The player just couldn't see why.

Most of it is hearsay

Then I measured what the animals actually know. About 80% of the herd locations an animal remembers are places it has never been. They're hearsay, passed from animal to animal, some of it passing generations. Nothing marks a memory as secondhand, so the animal follows all of it with the same confidence.

That's by design. Most of what any of us knows works the same way.

Who does the work?

The server supports up to a thousand players controlling animals at the same time. So the first question was where to decide which arrow points where.

The arrows depend on the animal's position, and the animal moves every tick. If the server picked the nearest remembered place for every player on every tick, it would spend most of its time redoing the same sums. The client, on the other hand, already knows exactly where its animal is, sixty times a second, and only ever serves one player.

So the server only sends what the animal knows, and the client does the rest. The memory is tiny, so sending all of it is cheap. And it only changes every few seconds, so the server only has to send it when it actually changes.

Sending only what changed

Each animal already keeps a running checksum of its memory, a single number that changes whenever anything is added or forgotten. Every tick, the server compares that number with the one it saw last time. If they match, it's done. That one comparison is all a quiet tick costs.

When the checksum does change, the server filters the memory down to what the player will actually see: only the GOOD positions. If the filtered result is the same as last time, for example because the animal only learned about a bad place, nothing is sent. Only a real change goes out, stamped with a new version number, so the client always knows which copy is newest.

The server remembers just one thing per player: what it last sent for the animal they control. Switch animals and it's overwritten. Let go of control, or disconnect, and it's gone. It can never grow into a list.