Black & White: Inside the creature’s mind, part 1 how it feels
Desires, and the logic that drives them
In Black & White (2001), you raise a giant creature. It eats, sleeps, plays, fights, and even learns. It was one of the major selling points of the game and a fairly serious and sizeable portion of the game’s code was dedicated to the creature’s logic. Back in the day, many players thought that it was alive and developed attachments to their creatures.
The code of the original game has been extensively studied thanks to bw1-decomp, a project ran by the openblack team. This series tells you what was found inside the creature’s mind. You do not need to know much about AI here. I’ll attempt to explain each idea when it comes up. The goal here is to talk at a high level about the creature’s logic without digging into the decompiled code or assembly.
Everything written here comes from version 1.20 of the original game. I’ll save the Creature Isle expansion pack for another series as there are some interesting changes. Additionally, I suspect Black & White 2’s creature AI follows roughly the same logic but we’ll see.
- Part 1: how it feels. Desires, and the curve that drives them.
- Part 2: how it chooses. How it acts on those Desires with Plans, and how it picks one.
- Part 3: how it learns. Slaps, strokes, decision trees, and copying.
An agent
In AI, an agent is a thing that senses the world, decides, and then acts. A robot vacuum is an agent, a chess program is an agent, and the creature in Black & White is an agent too.
The designers built the creature on three ideas:
- Beliefs. What the creature knows about each object near it. For example, “That sheep is mine. It is alive.”
- Desires. What the creature wants. “I am hungry.”
- Intentions, or plans. What the creature will do now. “I will eat that sheep.”
AI designers and developers call this a “Belief-Desire-Intention” agent. This first part is about desires. Part 2 is about plans, and part 3 will show you how beliefs and desires change when you teach the creature.
One turn of thought
The creature thinks in short steps. We call each step a turn. There are about ten turns each second. In each turn, the creature does these things in order:
- It looks at the world.
- It updates its desires.
- It decides what to do.
- It does the next small part of its plan.
When you slap or stroke it, it learns. The lesson changes its desires and beliefs. Then the loop starts again.
The loop of thought
Forty desires
The creature has 40 desires. Some are bodily needs: hunger, tiredness, the need to drink, and the need to poo. Some are feelings: fear, anger, compassion, and curiosity. Some are social: the wish to play, to impress a town, or to have a friend.
Each desire is one number. Zero means “I do not want this”. Most desires stop at a maximum near 1 or 2. For example, Hunger can go up to 2.0, and Fear up to 0.92. A creature’s species (tiger, cow, bear) has the same maximum for each desire.
The minimum value a desire can hold is 0.
Sources: where desires come from
A desire does not grow by itself. Inputs will push it up. The game calls these inputs sources. There are 61 sources in total for Black & White. Each source reads one fact about the creature or the world. Here are some examples:
- Low energy pushes Hunger.
- Exhaustion pushes Tiredness.
- Night pushes Tiredness and Fear.
- Damage pushes Fear.
Each source has a threshold.
But the change at the threshold is not sudden. It is a smooth change in a short distance. For this, the game uses a sigmoid function.
Sources can hold a negative value, but in practice they are always zero or above.
The sigmoid, in plain words
Think of a light dimmer with a strange knob. At first, when you turn the knob, almost nothing happens. Near the middle, the light comes on fast. Then the light is at full power. If you turn the knob more, the light does not get brighter.
That is what a sigmoid does. Many AI systems use sigmoids. They are useful when you want a “yes or no” answer that is not too sharp. The answer can be “almost yes” or “a little bit yes”. This might seem like a small detail, but it helps smooth out the creature’s sources for fulfilling desires.
The creature puts each source through a sigmoid. The input is how far the source is above or below its threshold. The output is the drive: how hard this source pushes its desire.
Move the slider. The yellow line is the game’s curve. The blue line is a softer S-curve, for comparison.
Try it: the creature's sigmoid
The game’s curve is very steep. Look at the steps in the yellow line. We noticed the game does not calculate the curve each time. It keeps 41 numbers in a lookup table, and it reads the nearest one. The reason for this is pretty simple: it is fast and inexpensive, and back in 2001, Black & White needed every optimisation to run steady.
The steep curve makes each source act almost like a switch. Below the threshold, the drive is tiny. Above it, the drive is full.
There is one small surprise. Below the threshold, the drive is tiny yes, but it is almost never zero. Near the bottom of the table, it is about 0.000000004. In most cases, while any source of a desire has a value, that desire does not fade by itself. Desires go down when the creature does something about them.
Why a sigmoid?
The code does not tell us why the designers chose a sigmoid specifically, but sigmoid is widespread in gamedev wherever there’s probability and decision-making logic. Think about the other ways to turn a source into a drive:
Use the raw value. Hunger rises as soon as the creature uses any energy. There is no “I am fine for now” zone. A creature that ate one minute ago is already a little hungry.
Use an on/off switch. Hunger is off below the threshold and on above it. Now the creature changes its mood in one jump. When the energy moves up and down near the threshold, the drive goes on, off, on, off.
Use a sigmoid. Below the threshold, the creature is calm. Above it, the drive is full. Between the two, there is a short zone where the change is smooth.
Three ways to read the energy source for Hunger (threshold 0.4)
The sigmoid also gives the game four more good things.
- Every source has the same size. A drive is always from 0 to 1. A desire adds the drives of its sources. One source with a huge value cannot hide the other sources.
- The threshold is easy to teach. When you slap or stroke the creature, the game moves the threshold. The curve moves left or right, but its shape stays the same. “Start to feel hungry sooner” is one number. Part 3 shows this.
- It comes from neural networks. The designers described each desire as a perceptron. A perceptron is the simplest artificial brain cell. It adds its inputs and puts the total through a sigmoid. The creature’s desires work in almost the same way. Marketing win!
- It is cheap. The game reads one number from a table. It does no other calculation and PCs were slow.
The game makes its curve very steep. So it is near a switch, with only a short soft zone. Designers can easily understand a switch: “the creature gets hungry at 40% energy”. The soft zone stops the fast on/off changes.
If we take a source value, apply the sigmoid curve to that value, we get a drive. Each desire can have many drives.
One interesting thing to note, the same source can have different drives, and drives can be shared between desires. For example, the Night source, which tells the creature how dark it is, is used to drive both Tiredness and Fear. The drives differ slightly due to different thresholds which are covered in Part 3.
From drive to desire
In each turn, the game adds all the drives of a desire. Then it divides the total by the desire’s growth time. The growth time tells you how fast the desire can grow:
| Desire | Maximum | Growth time | Main sources |
|---|---|---|---|
| Hunger | 2.0 | 20 seconds | low energy |
| Tiredness | 2.0 | 2 seconds | exhaustion, night |
| Fear | 0.92 | 1 second | dark, damage, magic |
| Compassion | 0.8 | 5 seconds | four sources |
| Anger | 0.8 | 5 seconds | three sources |
With a full drive, Hunger goes up by 1 in 20 seconds. Fear goes up by 1 in 1 second. That is why a creature becomes afraid very quickly, but becomes hungry slowly.
Try it below. Make the energy low, and Hunger grows. Make it night, and Fear and Tiredness grow. The strongest desire is green. Click “Eat a meal” to see Hunger fall.
Try it: desire bars
This demo uses the game's real thresholds, growth times, and maximums for these three desires. The fade speed when no source pushes is for show only.
When a desire is satisfied
A desire goes down when the creature finishes a plan for it. Each action has a factor. When the creature finishes a meal, Hunger is multiplied by 0.3. So a Hunger of 1.0 becomes 0.3.
Some desires have special rules applied to them:
- After the creature poos, the desire to poo stops for 60 seconds.
- After the creature sleeps, Tiredness becomes a little less than its weakest desire.
- After the creature tries to get your attention, that desire stops for 60 seconds.
Opposite feelings
Some desires block other desires. When the creature decides to help someone (Compassion), its Anger stops for about 3.4 minutes. When it decides to attack (Anger), its Compassion stops for about 3.7 minutes.
This makes the creature’s mood stable. A creature that is kind now does not suddenly become cruel one second later.
Summary
- The creature is an agent. It has beliefs, desires, and plans.
- It has 40 desires. Each desire is one number.
- The growth time sets how fast each desire grows.
- 61 sources push the desires up. Each source has a threshold.
- A steep sigmoid turns “how far over the threshold” a source is into a drive from 0 to 1.
- A desire falls when the creature completes a plan for that desire.
Now the creature wants things. But how does it choose what to do? Part 2 tells you.