Utility Based AI
Basic concepts of Utility
Evaluators
Evaluators are responsible for calculating score of assigned Behaviors.
Consideration
Consideration is a number representing a subset of gamestate which, from the perspective of the algorithm, is worth being considered during score calculation.
AttackOpponent
behavior-
agent’s health
-
opponent’s health
-
distance between agents
-
agent’s weapon damage
-
etc.
Curve
Curve is a function which converts one value into another. It usually takes form of an analytical curve.
Aggregator
Aggregators are responsible for merging multiple scores into one.
Selector
Selectors are responsible for selecting most suitable behavior based on scores received from evaluators.
Flow of Utility
-
Evaluators assigned to behaviors recursively gather scores of connected Evaluators.
-
Results of the whole Evaluator tree evaluation are passed to the Selector along with Behavior instances which are described by those scores.
Example
Let’s say that our example situation involves two archers shooting at each other and trying to defeat his opponent.
-
Attack
-
Flee
-
agent’s health
-
opponent’s health
-
distance between agents
All considerations' values will be in range [0, 100]. Additionally we’ll assume simple structure of Evaluators - one Aggregator to which we connect few Curves with one Consideration connected to each of them.
Let’s assume that Attack behavior will look into health considerations while Flee behavior should consider agent’s health and distance.
We want to implement berserk-like behavior, so our character should prefer attacking when he is at full health or at very low health. Additionally the less health his opponent has, the more likely agent is to attack.
Flee should be executed whenever opponent comes too close to us. Also it should be more likely with each health loss.
After curves are prepared we decide that attack evaluations should be aggregated by multiplication, so we connect them to Product Aggregator. On the other hand flee should make use of Min Aggregator.
Let’s check how it will behave in some test scenarios.
Scenario 1
-
agent’s health = 100
-
opponent’s health = 100
-
distance = 100
Attack evaluation = ah
(100) * oh
(100) = 1 * 0.5 = 0.5
Flee evaluation = min
(ah
(100), d
(100)) = min
(0, 0) = 0
Chosen behavior - Attack
Scenario 2
-
agent’s health = 12.5
-
opponen’s health = 100
-
distance = 100
Attack evaluation = ah
(12.5) * oh
(100) = 0.5 * 0.5 = 0.25
Flee evaluation = min
(ah
(12.5), d
(100)) = min
(0.625, 0) = 0
Chosen behavior - Attack