Many NPC decisions involve competing options rather than a simple yes or no. Should this enemy attack, retreat, or call for backup? Utility-based AI answers these questions by scoring every available action against current circumstances and choosing the highest-scoring option. Players who encounter adaptable enemies in games through we 999 game are often seeing utility-based selection at work — characters whose responses shift naturally as the situation changes.
A flat priority list struggles when multiple conditions apply at once. If health is low, should an NPC flee? If allies are nearby, is attack better? Utility scoring handles these competing factors by evaluating every possible action numerically and letting the scores settle the competition rather than hardcoding a fixed decision order.
How Utility Scoring Works
Each available action is scored against one or more weighted considerations. Health level, distance to target, number of nearby allies, available ammunition, and threat level are examples of inputs that modify a score. The considerations are combined — often by multiplication or weighted sum — to produce a final utility value for the action. The NPC executes whichever action scores highest.
| Action | Health Factor | Distance Factor | Ally Support | Final Score |
|---|---|---|---|---|
| Attack | 0.8 (75% health) | 0.9 (close range) | 1.2 (allies present) | 0.864 |
| Retreat | 0.2 (75% health) | 0.5 (close range) | 0.4 (allies present) | 0.040 |
| Flank | 0.7 (75% health) | 0.6 (close range) | 1.1 (allies present) | 0.462 |
| Call Help | 0.5 (75% health) | 0.8 (close range) | 0.2 (already present) | 0.080 |
How Circumstances Change the Selection
The same NPC with 15% health instead of 75% would have a much higher Health Factor for Retreat and a much lower factor for Attack. The scores would shift to favour withdrawal. No code change is needed — the same scoring functions applied to different inputs naturally produce a different action selection.
- Weighted considerations allow designers to tune how strongly each factor influences each action
- Changing game state — health dropping, allies dying — automatically shifts scores without code changes
- Score normalisation prevents one factor from dominating all others when its value is very large
- Adding a small random component prevents identical NPCs from always choosing the same action simultaneously
Characters can only make informed decisions using the information available to them. Character perception systems identify nearby players, evaluate visibility, and determine when someone’s presence should influence behavior.