What this is about
A multi-armed bandit is the simplest learner there is. Picture a row of slot machines. You do not know which one pays best. You pull some levers, watch what comes out, and over time pull the best one more often, while still testing the others now and then. That is the whole idea.
Our street game uses this learner today. When a player threatens a character, the character picks one of three answers: comply, refuse or report. A bandit keeps score of how each answer worked out. This article explains the bandit in plain words and shows how it behaves in our tests.
Why it matters
A learner like this solves a problem that scripts cannot. A script picks its answer ahead of time, based on what the designer expected. If the world changes, the script does not notice. A bandit watches the results and adjusts.
It is also small. It needs no big network, no long training run and no map of the world. For a game, that is a real advantage. It is cheap to run and easy to inspect. You can open it and read exactly what it believes.
And it holds a lesson that matters for anything that learns: you must keep exploring a little. If you only ever pull the lever that looks best today, you never find out that another one has become better.
How it works, step by step
Take one character and one situation, such as a player threatening it. The bandit has three levers, the three answers.
- Start with no opinion. At first, every answer looks equally good.
- Pick an answer. Most of the time, pick the one with the best score so far. Now and then, pick another one on purpose. That is the exploring.
- See what happened. The game pays the answer in health, cash and need, one tick later.
- Update the score. Move the answer's score toward the result you just saw.
- Repeat. Over many rounds, the scores settle, and the bandit leans toward the answer that costs least.
Two ideas sit inside that list. The first is the balance between exploiting, which means using the best known answer, and exploring, which means trying the others. Too much of the first and you get stuck. Too much of the second and you waste your life on bad answers.
The second idea is that the reward must be something the learner can feel. We learned that the hard way. In one game log, a character was threatened 31 times in 8 seconds, and nothing about its health or needs changed with its answer. A learner with no signal learns nothing. We told that story in How a game character learns to say no.
The three levers in our game
In our game, the measured costs of an answer, in the game's units, are these:
| Answer | Cost |
|---|---|
| Comply | 2 |
| Refuse | 6 |
| Report | 8 |
So in the short run, giving in is the cheapest. Refusing costs more, and calling the police costs the most. A learner that counts cost will lean toward complying unless something makes the other answers worth it. That is a reasonable, readable behavior. And it is a good test of the learner: we made complying more expensive, and a character that had been complying switched to refusing. The learner followed the price. That shows the mechanism works. It does not show the character is wise, and we do not claim it.
The bandit works per character and per player, so one character can answer one player differently from another.
How the bandit was tested
First, in a simulated arena: 60 characters, 400 rounds and 10 random seeds. The learner's second-half welfare, a score that adds health, money and needs, was minus 1.32. The best fixed table, which always complied, got minus 2.00. The learner was better by 0.68.
Then we changed the world in a way the script could not know. We made the police corrupt, so that the police flag lied. The script that read the flag did worse. The learner scored minus 3.37 against minus 7.50 for the script that trusted the flag. Our verdict: use a script for changes you can foresee, and use a learner as cover for the ones you cannot.
The arena has limits. We built the world and the learner together, so the world may suit the learner, and none of that ran inside the real game.
Inside the game, we tested four characters in snow, at night, with a fight and police. The hybrid, which pairs the script with the bandit, flipped its answer in four of four pairs within two threats after the change. It never took over falsely, with 0 false takeovers in 14 checks. The script alone flipped 0 of 4.
How it hands over from the script
The game does not throw the script away. A statistical test called a cumulative sum watches how outcomes compare with what the script expected. It is a standard way to detect drift in a stream of numbers. If outcomes drift, the bandit takes over. If they do not, the script keeps the decision.
One lesson came from that test. We first updated the baseline only while no alarm was active. That let lucky samples in and kept bad ones out, so the baseline drifted upward and the alarm went wrong. The fix is to update the baseline on every sample, slowly. We wrote the rule down: never gate a detector's baseline on its own alarm.
Glossary
- Bandit: a learner that tries options, keeps score and leans toward the best one.
- Exploit: use the answer that looks best so far.
- Explore: try another answer on purpose, to learn something.
- Reward: the result the game gives an answer, which the learner uses to update its score.
- Welfare: a score that adds a character's health, money and needs.
- Baseline: the expected result that new outcomes are compared against.
Try it
- Read how the bandit sits in our game in The game runs a bandit, and the network waits for a harder question.
- For a character you can watch right now, open aiazic.com, our online 3D world, and meet its robot guide. It does not learn like a bandit, because it follows path-finding rules, but it is the same kind of character in a different home.
- A paper-and-pencil version: take three coffee shops in your town. For two weeks, visit your favorite most days but try the other two once in a while. Keep a score for each. That is a bandit with you as the learner.
Previous in NPC-mind: NPCs: the game characters a computer controls. Next: Why a simple script still beats our learning NPC.

Comentarii
Niciun comentariu încă.
Conectare pentru a comenta.