Part 1: Variables

AgentCubes has two kinds of variables.
| Kind | Looks like | Belongs to | Example |
|---|---|---|---|
| Attribute (agent variable) | days_sick |
Each agent has its own copy | How long this person has been sick |
| Global variable | @sick |
The whole simulation; one copy everyone shares | How many people are sick right now |
The @ sign at the front is how you tell them apart.
An attribute: days_sick

Read the person’s rules as sentences (ignore Set p to 0; it’s left over from another model):
- If I’m healthy, a sick person is next to me, and a 50% chance comes up, then I get sick and start my
days_sickcount at 0. - Otherwise, if I’m healthy, then 90% of the time I take a random step.
- Otherwise, if I’m sick, I’ve been sick more than 20 ticks, and a 30% chance comes up, then I recover and become healthy again.
- Otherwise, if I’m sick, then half the time I add 1 to
days_sickand take a random step. - Otherwise, if I’m sick, I add 1 to
days_sickand stay put.
Notice that a recovered person is just healthy again, so they can catch it a second time.
Every sick person keeps their own days_sick. One person might be on day 3 while another is on day 18. That’s why it has to be an attribute: it describes one agent, not the whole world. The test condition is how a rule checks an attribute’s value.
Rules 4 and 5 both count the day. Whether a sick person moves or not, one more tick has passed.
Global variables: @healthy and @sick

The cactus is the controller. Every tick it counts the healthy and sick people and stores the counts in @healthy and @sick. Then it plots both in a window called people: blue for healthy, red for sick.
A count of the whole world doesn’t belong to any one person, so it’s a global. Any agent can read @sick. For example, a person could stay home (stop moving) when @sick gets large.
Part 2: Hill climbing

A killer robot wants to catch people, but it can only look at the four cells next to it. How does it know which way to go?
The answer is a scent. Each person gives off a strong smell. The smell spreads out across the floor and gets weaker with distance. The robot just keeps stepping toward wherever the smell is stronger, which is uphill. That’s hill climbing.
Every person is a source

When a person is created, it sets its attribute p to 1000. That’s the strong scent at the source. While it runs:
- If the robot is next to me, then I’m erased. Caught!
- Otherwise, I hill-climb
x(more onxbelow).
The floor spreads the scent

Each piece of ground, 20 times a second, sets its own p to the average of its four neighbors’ p. p[up] means “the p of the agent in the cell above me.”
That first line is diffusion. A cell next to a person (p = 1000) gets a big average. A cell next to that gets a slightly smaller one, and so on. Run it, and the scent spreads out from every person like heat spreading through a metal plate. Close to a person p is high, and far away it’s low.
The second line does the same thing for a second scent, x, which comes from the robot (see below). So two smells spread across the floor at once.
Notice this is the same kind of rule as the fire: each cell looks only at its four neighbors, and a pattern across the whole floor emerges.
The robot climbs the hill

hill-climb p looks at the four neighboring cells and moves to the one with the highest p. Step by step, the robot walks uphill on the scent, toward the nearest person (or the biggest crowd), even though it never sees a person until it’s right next to one.
Hill climbing is a simple search strategy: you don’t need a map; you just keep taking the step that looks best from where you are.
The people flee
When the robot is created, it sets its x to −1000. The floor spreads x just like p, so x is very negative near the robot and close to 0 far away.
Each person hill-climbs x. Climbing up a negative scent means stepping to the neighbor where x is closest to 0, which is the one farthest from the robot. The same hill-climb action that makes the robot chase makes the people run. The only difference is the sign of the source.
- Why make the robot’s scent negative instead of +1000? What would the people do if it were +1000?
- Watch a run. Do people escape forever, or do they get trapped? What happens when a person runs into a corner or a wall?
Hill climbing can get stuck
Put two people far apart, with the robot exactly halfway between them. Which way does it go? Now picture a scent landscape with a small bump and a much bigger hill farther away. A robot on top of the small bump sees every neighbor as lower, so it stops. That’s a local maximum. Hill climbing finds a peak, not always the best one.
Try it
- Immunity. Right now rule 3 changes a sick person back to healthy. Instead,
changeto a new recovered shape that nothing can infect. Add@recoveredto the cactus and plot it in a third color. Now you have SIR again. How does the plot change? - Stay home. Add a rule so a sick person doesn’t move when
@sickis more than 5. Does the outbreak slow down? - Faster scent. Change
once-every 0.05on the ground to0.5. Can the robot still find people? - Two robots. Add a second robot. Do they chase the same person or split up?