← Blog
✎article de blog

The NPC brain still loses to the script it copied

A cinematic photograph of a dress form standing beside a teal upright piano in an empty room in teal and steel with a warm amber light, the AMARBARO mark and wordmark centred over it.

Our best NPC brain scores 0.530 in a stable world, against 0.631 for the scripted schedule it was copied from.

Part 1 of 5 in NPC-mind. Next: One shared brain and 216 private weights per NPC

Our best NPC brain scored 0.530 in a stable world. The scripted schedule it was copied from scored 0.631. That is a gap of 0.10 on a scale from 0 to 1. It is the first thing this series has to explain, because we built the brain to beat the script, and it does not yet.

What an NPC is, and why a script is not enough

An NPC is a non-player character: a person in a game that the game runs, not the player. We are building NPCs for a game called homeless-sim. A player can walk up to one, threaten it, offer it money or ask it for help. The NPC then has to answer: comply, refuse, report the player, or flee.

Many game NPCs run on a script. A behaviour tree (a set of if-then rules) and a timetable say what to do at each hour. If you watch the same NPC for a day, you learn its pattern, and it stops feeling like anyone in particular. Our goal for the first version is simple to state: players should meet NPCs that remember them. A script cannot remember anything. A brain can, if we let it.

Our brain is a small neural network, a set of artificial neurons wired together. Each tick, it reads what the NPC sees and feels, then picks what to do next. A tick is one decision step in the game. Every NPC has four needs: hunger, safety, social contact and purpose. Each need runs from 0, met, to 1, empty.

We score a life by satisfaction, which is 1 minus the average of the four needs. A satisfaction of 1 means nothing is missing at any point. Higher is better. Read 0.530 as the average, over a whole life, of how well the four needs were kept met, on a scale where 1 is perfect. Every number in this series uses that scale.

Why a non-expert should care: a script that always answers the same way is predictable, and predictable NPCs make a game feel fake within a few minutes. A brain that adapts to what a player has done is the approach we are testing to make a town feel like it has a memory. That is the whole reason for the project. Everything after this point is about whether the brain can do that job without losing to the script on the basics first.

The design we are testing

The idea has two layers. All NPCs share one frozen base brain. It is the instinct: trained once by copying the scripted schedule, then never changed again. On top of it, each NPC keeps a small owned layer, a few hundred weights it can change during its own life. When an NPC dies, its owned layer is lost. Its children inherit traits, such as how fast it learns, but never its learned weights.

The base means every NPC starts out sensible. The owned layer should let each one adjust to the life it actually leads.

Before we ran any test, we wrote a kill line, a rule that says when the idea is dead. It says: if base plus owned layer does not beat the base alone on mean satisfaction, or if the NPCs do not behave more differently from one another than base plus traits alone, we stop. Writing that line first is the reason we can report a loss plainly. Without it, every loss turns into an argument about the setup.

We also use a second statistical term, standard error (SE). It is how much a score would wobble if we reran the same test with new random starts. We wanted a difference of two SE before calling it real. A gap smaller than that is noise we could not tell apart from luck.

What the first runs said

The first base arm was broken. We copied the script with about 76 percent accuracy and then sampled actions from that copy. It scored below random, which made beating it easy and meant very little. After we fixed the bugs, the owned layer scored 0.518 against the script's 0.539. The script's own runs spread by about 0.021, so that gap was roughly one standard deviation of the script's score. The kill line passed. We wrote the result down as weakly earned, and we stand by that wording.

Then we gave the NPCs eyes: a cone of eight rays in front of each one, with trees that block sight. Each NPC now knew only what it could see, and it had to turn and look to find food. The gap grew. The owned layer scored 0.490 against the script's 0.632, and the brain sat barely above random at 0.474. The script used the same rays, so the eyes made the task harder for both, and the brain did not close the gap.

Here are the stable-world results for the arms that matter most. Each number is a mean over seeds, where a seed is one random start of the same test:

arm satisfaction
scripted schedule 0.631
base, evolved instinct 0.530
owned layer, learning pooled across NPCs 0.517
base, copied from the script with no evolution 0.419

The evolved instinct varied by 0.006 across seeds, so the gap to the script (0.101) is well outside that spread. "Pooled" means every NPC in one world shares one learned change. It was our best learning arm in that table, and it was still below the script.

We also tried the obvious improvements, and some helped while others did nothing. Evolving the base readout (the last layer that turns the brain's activity into a choice) moved the brain from 0.419 to 0.530. That was the largest gain in our stable-world tables. Learning on top of the evolved base, however, did not add to it. In a world that does not change, the owned layer mostly added noise to a good instinct. Part 3 explains where learning did help, and under what condition.

The gap is sharpest on the basic reflexes. We score a reflex by how often an NPC takes the right action when that need calls for it. The evolved instinct scored 0.52 for eating, 0.24 for work and 0.29 for talk. The script scored 0.97, 0.96 and 0.98 on the same test. So the brain does not yet reliably eat when it is hungry, or work when the work is due. Those are the moves a script gets right almost every time, and they are where a brain has the least to gain from being clever.

What this does not show is that the brain is bad at everything. It shows that on the basic job, in a world with a fixed layout and known needs, the copy of the script and the evolved instinct have not yet matched the script. The scripted schedule was written for exactly that job, so it is the right bar to measure against, and a loss there is the honest starting point.

What would prove us wrong

Here is the test that would change our minds. Run a stable world, on the same seeds and the same kill line, in which the best brain beats the scripted schedule by two standard errors. We have not seen that run. The honest reading of the current numbers is that the script still wins the basic job, and the brain's advantage shows up only once the world changes.

Part 2 shows how the brain is built, so you can see exactly what each NPC is allowed to change.

Commentaires

Pas encore de commentaires.

Se connecter pour commenter.