What this is about
In our street game, a player can threaten a computer-run person. The person can obey, refuse or report the player to the police. A character that always obeys feels fake. We wanted characters that sometimes say no, and that learn when no is a good idea.
This article tells how we built that, what went wrong first, and how we tested it. The most useful lesson was not about clever code. It was about what a learner needs before it can learn anything.
Why it matters
Players notice quickly when a character has no will of its own. If every threat works, the game is a vending machine. If no threat ever works, it is a wall. A character that weighs the threat, remembers the player and sometimes pushes back makes a street feel populated by people.
But a refusal has a price. In the real world, refusing a threat can get you hurt. A character that refuses every time would be unwise. So the character has to learn when to give in and when to push back, and the only honest way to learn that is from what actually happens.
How a character talks to the game
The game server runs on Godot. The characters' brains run in a separate program, called the sidecar, written in Mojo. They talk over a local connection, one line of text per message.
Godot server --obs line--> sidecar
<--act line--
Ten times a second, the server sends an obs line for a character: where it stands, its hunger, warmth and energy, who is nearby, and events such as "a player threatened you". The sidecar answers with exactly one act line: where to move, whether to run, and a verb such as beg or report. The server waits for nothing but that answer.
The sidecar keeps up to 8 players in memory per character, so a character can remember who threatened it. If the game server dies, the sidecar notices and exits within about 3 seconds. Before that fix, killing the server leaked a sidecar every time.
Step one: a test arena
Before we wired a learner into the game, we built an arena of 60 characters, 400 rounds and 10 random seeds. Each character picks one of three answers to each threat. We compared a script with a small learner, the three-answer bandit that we explain in another article.
The learner did better than the best fixed answer, which was always complying, by 0.68 on our welfare score. When we made the police corrupt, the learner held up much better than a script that trusted the police flag. The price was a small loss in a calm world, about 0.36 to 0.41.
The arena has limits. We built the world and the learner together, so the world might suit the learner. None of it ran inside the real game.
Step two: the real game said "nothing happens"
Then we tested inside the game, and the first honest finding was bad. One character was threatened 31 times in 8 seconds. Its needs drifted by the same small amount after every threat, minus 0.0077, whatever answer it gave. Its health did not change. In the game, the reward for an answer was zero.
A learner with no reward learns nothing. The arena's costs were not the game's costs. We wrote the lesson down: a learner in a game needs a consequence that it can observe within one tick. Without one, every check is decoration.
Step three: give each answer a consequence
We added consequences as settings, all zero by default, which fits the rule that every number in the game is a setting. A preset we call hybrid sets the price of refusing an armed player at 6 health, and complying at 200 cents or 2 need. Measured in the game, one tick after the answer, comply scored minus 2.00, refuse minus 6.00 and report minus 8.00.
Now a learner has something to learn from. Giving in is cheapest in the short run. Refusing costs more. Reporting costs the most. A character will lean toward complying unless the situation changes, and it will notice if that changes.
Step four: test it under pressure
We tested four characters in snow, at night, with a fight and two armed players. Two game bugs showed up that no earlier test could find:
- Every character opened its own connection, and the sidecar served one at a time. With more than one character, only the first ever got an answer.
- The weather system's shelter override carried only movement, but the server took it whole. In snow, no comply, refuse or report ever got through.
Both are bugs in the game, not in the brain. A test with one character cannot find them. We fixed both. After that, the hybrid flipped its answers in 4 of 4 pairs within two threats after the change, with 0 false takeovers in 14 checks and no deaths. The script alone flipped 0 of 4.
Step five: keep it cheap
Remembering players has a cost. With 60 characters and 1000 threateners, memory grew by 36,472 kB. We capped it at 8 players per character, dropping the oldest first, and growth fell to 1,108 kB. A script now guards that limit.
On speed, we measured 100 characters on 2 November. Per tick, the policy we call "feel" took 6.5 to 7.7 ms, the hybrid took 9 ms and the neural network took 54 ms. Most of the network's cost was route planning.
What we do not claim
We did not show that characters are wise. We showed that the learning mechanism follows the price. A neural network also lost its place in the game for now, because the simple bandit earned its keep on measured costs. And a detector in our hybrid fooled itself once: it updated its baseline only when no alarm was active, so it drifted. The fix, a slow average of every outcome, passed at two noise levels and missed narrowly at a third. We stopped after two attempts, as we had decided before we started.
Glossary
- Sidecar: a second program that runs beside the game and answers questions for the character's brain.
- Tick: one decision step in the game.
- Reward: the result the game gives an answer, which the learner uses to update its score.
- Preset: a named bundle of settings, such as
hybrid. - Welfare: a score that adds health, money and needs.
- Baseline: the expected result that new outcomes are compared against.
Try it
- The full technical account is Teaching street NPCs to say no. The part about the learner's place in the game is in The game runs a bandit, and the network waits for a harder question.
- To see a computer-run character that you can walk up to, visit aiazic.com and meet the robot guide. It follows path-finding rules, not a learned brain, and it keeps a distance from guests. Refusing is not its job, so it makes a good contrast with a character that can.
- A small exercise: think of a game character that always says yes to you. Write down what consequence would make saying no a sensible choice for it.
Previous in Street Simulator Progress: The street simulator in plain words. Next: A whole simulated city on one settings menu.

Comments
No comments yet.
Log in to comment.