Tests that passed for the wrong reason
With about 170 test entries and agents working in parallel, the worst failures were checks that said PASS while proving nothing. Each one got a rule, and five tests still flake under load.
A learner only beats scripted NPC answers once the game gives each answer a consequence the NPC can feel within one tick.
One computer-run person in our game was threatened 31 times in 8 seconds and learned nothing, because nothing it did changed what happened to it. Fixing that became the most useful lesson of the whole NPC project.
In Street Simulator a player can threaten a computer-run person and force them to beg for the player's crew. The person is not a puppet. Their own "brain" decides: obey, refuse, or report the player to the police. This article is about that brain, how it connects to the game, and what we learned by testing it.
The game server runs on Godot. The NPC brains run in a separate program, the sidecar, written in Mojo. They talk over a local TCP connection with one line of JSON per message.
Godot server --obs line--> sidecar
<--act line--
Each 0.1 seconds (10 Hz) the server sends an obs line for an NPC: position, hunger, warmth, 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 do verb such as beg or report. The server never waits on anything but that answer.
The protocol is on version 3. Older lines are still accepted. The sidecar also keeps up to 8 players per NPC in memory, keyed by account, so an NPC can remember who threatened it last week.
If the game server dies, the sidecar now notices. It checks its parent process once a second and exits within about 3 seconds. Before that fix, killing the server leaked a sidecar every time.
Before wiring a learner into the game, we built an arena in Python: 60 NPCs, 400 rounds, 10 random seeds. Each NPC picks one of three answers to each threat. We compared a scripted table with a learner, a small three-answer bandit (a learner that tries each answer, watches what it pays, and leans toward the best one).
The first result looked good. The learner's second-half welfare (the NPC's health, money and needs added into one score, higher is better) was -1.32, against -2.00 for the best table (always comply). That is a gain of 0.68. A district's bot income fell from 6000 to 613.
Then came the twist, a change the script could not predict. If the script reads the police state, it wins while police behave. But when the police turn corrupt and the flag lies, the learner scored -3.37 against -7.50 for the aware script. The verdict: use a script for changes you can anticipate. Use a learner only as cover for ones you cannot. The price is about 0.36 to 0.41 welfare.
The arena has limits. We built the simulated world and the learner together, so the world may suit the learner, and none of it ran inside the real game.
The first honest finding came from a test inside the game. One NPC was threatened 31 times in 8 seconds. Its needs drifted by the same amount, -0.0077, after every threat, whatever answer it gave. Health did not change. In the game, the reward for an answer was zero.
A learner with no reward learns nothing. So the arena's costs were not the game's costs. The lesson we wrote down: a learner in a game needs a consequence its brain can observe within one tick. Without one, every gate is decoration.
The next build step added consequences as settings, all zero by default. The hybrid preset sets refusing an armed player at 6 health and complying at 200 cents or 2 need. Measured in the game, comply scored -2.00, refuse -6.00 and report -8.00, felt one tick later.
The hybrid scheme switches from script to learner when an answer lands much worse than expected. Under measurable noise the gate failed. The trace was instructive: the baseline updated only while no alarm was active. Lucky samples got in and bad ones stayed out, so the baseline drifted upward.
The rule we recorded: a detector's baseline must update on every sample, slowly. Never gate the baseline on the alarm. The fix, a slow average of every outcome, passed at noise levels 0 and 1.2. At a noise level of 2 it missed the bar narrowly (-0.11 against -0.1). We stopped there after two attempts, as we had decided before starting.
The storm test used 4 NPCs in snow at night, with two armed players. It found two game bugs that no earlier test could:
Both were fixed. Brains now share one connection, and the override covers movement only. After the fix the hybrid flipped its answers 4 times out of 4 within two threats after the turn, with 0 false takeovers in 14 and no deaths. The script alone flipped 0 of 4.
Remembering players has a cost. A test with 60 NPCs and 1000 threateners grew memory by 36,472 kB. Capping memory at 8 players per NPC, dropping the oldest first, cut that to 1,108 kB, and a script now guards it.
On speed, we measured 100 NPCs on 2 November. Per tick, the "feel" policy took 6.5 to 7.7 ms, hybrid 9, and the network 54.
The network's cost was mostly route planning. We found that by switching features off, because the in-code timers showed only 2.8 ms and misled us for hours. Flow fields (one shared map of directions that every NPC reads) replaced A* path search (each NPC planning its own route), and the network dropped to about 20 ms. Later measurements put 100 network NPCs at about 3 ms per server tick, against a budget of 16.
The neural network, npc-mind, did not earn a place over the bandit. Three reasons:
Instead the game gained a setting, npc/answers, with feel as the default and hybrid as a preset, plus a test that checks an NPC complies and begs with no police in sight and reports under police eyes.
A per-NPC memory cell did well on unseen lives in the arena: memory -0.009, a flat policy -0.25, the best counter -0.61, an oracle +0.10. That is arena-only. Its "telling" feature, where an NPC warns others at first meeting, has untested game code.
On 6 November a plan for the next NPC step measured 509 NPCs. Running 509 NPCs pushed server ticks to 54 ms, with NPC decision logic taking 14.6 ms. That is the newest number and it supersedes the older 3 ms figure for a larger crowd. The plan has six phases and 12 intents.
Two other models reviewed it. One said the 14.6 ms covers only the Godot side. The other suggested a simpler bandit. The designer set clear performance boundaries: an NPC decision budget of 4 ms, threat consequences enabled by default, and linear decision policies.
Comentarios
Aún no hay comentarios.
Iniciar sesión para comentar.