Checking how many agents are working

How this works
Contatti
← Blog
A row of small matte resin figures on a dark steel table, one of them holding a tiny brass wire to a small steel box, warm amber light on that figure, in teal and steel with a warm amber rim light, the AMARBARO mark and wordmark centered over it.
✎post del blog

NPCs: the game characters a computer controls, and how they decide

The short version

A scripted game character still beats our learning brain in a calm world, 0.631 to 0.530, and learning wins back about 0.10 only after the world changes.

What this is about

NPC stands for non-player character. It is a person in a game that the game controls, not you. The shopkeeper, the guard, the stranger on the street are all NPCs. Most of them follow a script. We are testing a different kind, with a small brain that can learn from what happens to it.

This article shows both ways to decide, side by side, in plain words. Our series NPC-mind has five longer parts. This is the gentle entry to it.

Why it matters

Watch a scripted character for a day and you learn its pattern. It walks to the same place at the same hour and says the same line when you speak to it. After a few minutes it stops feeling like anyone in particular.

A character that remembers you feels different. If you threatened it yesterday, it might refuse you today, or run, or call for help. That small change makes a game town feel like it has a memory.

So the question we test is simple to say and hard to answer: can a learning brain make a character feel more alive than a script does, without making the game worse?

How a script decides

A script is a list of if-then rules and a timetable. It might say:

  1. At 8 in the morning, go to the market.
  2. If a wolf is near, run away.
  3. If hungry, find food.
  4. If another character talks to you, answer with the usual line.

Game makers often store these rules as a behavior tree, which is a branching list of such conditions. A script has real strengths. It is easy to read, it is cheap to run, and it does what the designer wanted every single time. If you want a character to behave in a known way, a script is a good tool.

Its weakness is that it cannot adapt. If the world changes in a way the designer did not plan for, the script keeps doing the old thing.

How our learning brain decides

Our brain is a small neural network, which is a set of simple artificial neurons wired together. Every tick, which is one decision step in the game, it does three things.

  1. It looks. The brain receives 64 numbers. They describe what the character sees (eight rays that each report food, a workplace, a wolf, another character or a tree or wall), its four needs, a few touch and hearing flags, which way it faces, what it just did, and the time of day.
  2. It thinks. The numbers flow through 192 hidden neurons. Most of that brain is shared by all characters and stays frozen. Only a small layer of 216 weights belongs to each individual character.
  3. It acts. The brain picks what to do next.

The brain gets no map and no arrow pointing to the nearest food. A character finds food only when one of its rays hits it. We built it this way on purpose, because a brain that knew where everything was would be cheating, and the script does not know that either.

Each character has four needs: hunger, safety, social contact and purpose. Each need runs from 0, which means met, to 1, which means empty. We score a whole life by satisfaction, which is 1 minus the average of the four needs. A satisfaction of 1 would mean nothing was ever missing.

The honest score

In a calm world, our best brain scored 0.530. The script it was copied from scored 0.631. The script is better by about 0.10 on a scale from 0 to 1.

That surprised us, because we built the brain to beat the script. It does not yet. We wrote the test and its pass line before running anything, and the brain cleared the line and still lost. The first article of NPC-mind explains the whole result.

The brain does win in one case. At tick 1000 of a 2000-tick life, we made one habit start to hurt. The favorite habit of the characters was talking. After the change, talking raised the safety need and gave no relief. The scripted characters fell to 0.051 on the second half of life. The frozen instinct fell to 0.211. The learners recovered about 0.10 more than the instinct did. When a world changes in a way nobody planned for, learning pays. When nothing changes, it costs a little. We tell this in In-life learning wins back about 0.10, but only after a shift.

What the game runs today

The game itself does not run the network at the moment. It runs a simpler learner called a bandit, with the script as a fallback. A bandit tries each answer, keeps score, and leans toward the one that pays. We explain it in The multi-armed bandit. The network waits for a harder question, one that needs more than three answers.

That is an honest state of affairs. We did not hide it.

Glossary

  • NPC: a non-player character, a game character controlled by the computer.
  • Script: a fixed set of rules and times that tells a character what to do.
  • Behavior tree: a branching list of if-then rules, often used to store a script.
  • Neural network: a set of simple artificial neurons wired together, which can learn by changing its weights.
  • Tick: one decision step in the game.
  • Weight: a number that says how strongly one neuron pushes another.
  • Satisfaction: our score for a life, 1 minus the average of the four needs.

Try it

  • Visit aiazic.com, our online 3D world. It has a robot guide, which is a computer-controlled character that walks a visitor to a room on request. That guide runs on path-finding rules, not on a learned brain, so it is a good example of the script side of this article. Watch how it keeps a distance from people and chooses a route.
  • Street Simulator, the game these brains were built for, has no public page we can point you to yet, so our progress articles are the way in. Start with A street game where every number is a setting.
  • For a small learner you can read in your head, continue to the multi-armed bandit.

Next in NPC-mind: The multi-armed bandit: how a character learns what works.

Commenti

Ancora nessun commento.

Accedi per commentare.