DE EN FR ES IT

Game AI & real-time strategy

Utility AI

Also: utility-based AI, utility system

Utility AI is a game AI approach in which every possible action receives a score for how useful it is in the current situation. The AI then takes the highest-scoring action or draws one at random, weighted by the scores.

Background

Rather than hard rules (“flee when health drops below 30 %”), utility AI expresses trade-offs: fleeing grows more attractive the less health is left, attacking the closer and weaker the enemy is. The scoring functions are often simple curves that combine several inputs.

The payoff is soft, hard-to-predict behaviour that can be fine-tuned by nudging weights. Drawing randomly by weight instead of always taking the top option makes an AI even less exploitable without making it look stupid.

The downside: many interacting curves are hard to reason about. When the AI does something odd, you need to be able to trace which scores led there. Typical mistakes are scores with no common scale and actions that never get picked because another one always edges them out.

How we do it

FaxFight’s training opponent (TrainingBot.php) works on exactly this principle, described in the code as a “simple but not stupid heuristic”. For attacks, each zone is weighted by the square of the character’s own striking power; last round’s zone usually drops to zero, because repeating it costs a point of damage. A character with the “Sharp Elbows” trait is allowed to repeat.

For blocks, the bot weights the zones by the opposing character’s striking power but spreads its choices and never picks the same zone three times in a row. It usually fires its special attack once, more likely from round 2 on and preferably at its strongest zone. Each choice is a weighted random draw. Thinking in scores rather than rigid rules goes back to the real-time strategy AI work our founder did in 2000.

Related terms