In utility AI, how does a survival-game villager choose between eating, chopping firewood and sleeping on each decision cycle?
answer
- compare options on one scale
- inputs mapped onto zero to one
- curves shape how urgent a need feels
- hunger matters little until near starving
- re-score on an interval or a change
basics
~10 sUtility AI scores each candidate action between 0 and 1 from the villager's current needs and surroundings, shaping every input with a response curve, then usually runs the highest-scoring action until the next re-evaluation.
solid answer
~40 sEach action owns one or more **considerations**: an input such as hunger, the hours until dark or the firewood stock, normalised to `0..1` and passed through a **response curve** that says how much that input matters at each value. A power curve such as `hunger^2` keeps eating unimportant at mild hunger and makes it urgent near starving; a falling curve on the firewood stock makes chopping matter more as the pile runs low. The considerations are combined, often by multiplying them, into one score per action, and the villager runs the best one, or picks at random among the near-best for variety. Scores are recomputed on an interval or when an input changes, so the choice follows the villager's needs instead of a hand-wired transition table.
go deeper
Recall the loop: every action gets a score from 0 to 1 from the NPC's needs, and the highest score usually runs until the next re-evaluation.
Explain considerations, normalisation and response curves, and show with numbers how a curve's shape changes which action wins as one input rises.
Show how you debug a utility agent: logging each consideration's contribution, spotting dithering between near-equal actions and adding commitment so choices stay stable.
Weigh what utility scoring costs a team: designers tune curves instead of wiring transitions, which scales to many needs but makes behaviour harder to predict without score-inspection tools.
## What utility AI is **Utility AI** (also called utility-based decision making) is a decision model in which an agent does not follow a fixed chain of transitions. On each **decision cycle** it asks every action it could take "how useful would this be right now?", turns each answer into a number, and acts on the numbers. It suits characters whose needs compete smoothly, such as a survival-game villager who has to eat, keep a fire going and sleep. Key terms: - **Action** (or option): something the agent can do, such as `Eat`, `ChopFirewood` or `Sleep`. - **Consideration**: one factor that affects how useful an action is, such as hunger for `Eat` or the firewood stock for `ChopFirewood`. - **Utility score**: a number, by convention between 0 and 1, saying how desirable the action is now. - **Response curve**: a function that maps one normalised input to that consideration's score. ## Normalising inputs Raw inputs arrive in different units: hunger as a percentage, distance in metres, the time until dark in game hours. Each consideration first maps its input onto `0..1` with a minimum and maximum the designer chooses: `x = clamp((raw - min) / (max - min), 0, 1)`. Without this step the input with the largest numbers dominates, whatever it means. ## Response curves The curve decides how much an input matters at each value. Common shapes: | Shape | Formula for x in 0..1 | Typical use | |---|---|---| | Linear | `m * x + b`, clamped to 0..1 | a need that matters in proportion | | Power | `x^k` with `k > 1` | ignore until the input gets high, then rise steeply | | Falling | `1 - x` | matters more as a resource runs out | | Logistic | `1 / (1 + e^(-k * (x - c)))` | a soft threshold around `c` | The curve is where designers encode personality: a cautious villager might use a logistic fatigue curve centred early, a stubborn one centred late. ## One decision cycle, step by step 1. Gather the inputs the considerations need from the agent and the world. 2. For each action, normalise every input and run it through that consideration's curve. 3. Combine the consideration scores into one score per action, commonly by multiplying them so that a zero on any one rules the action out. 4. Pick the action with the highest score, or pick at random among the actions within a small margin of the best, for variety. 5. Run that action until the next cycle, which comes on an interval or when an input the scores depend on changes. ## Worked example: the villager Take hunger 0.8 (0 is full, 1 is starving), a firewood stock at 0.3 of a full pile, and fatigue 0.5. - `Eat` uses the power curve `hunger^2` and a gate "has food" that is 1 when food is at hand: `0.8^2 x 1 = 0.64`. - `ChopFirewood` uses a falling curve on the stock: `1 - 0.3 = 0.70`. - `Sleep` uses a logistic curve on fatigue with `k = 10` and `c = 0.7`: `1 / (1 + e^2) = 1 / 8.39`, about `0.12`. The villager chops wood. Later hunger reaches 0.9: `Eat` becomes `0.81`, overtakes `ChopFirewood`, and the villager goes to eat. Nobody wired a "hungry" transition; the curves produced the switch. Had `Eat` used a linear curve, it would already have scored 0.8 and won at the start, so the curve shape, not only the input, decides the moment of change. ## Everyday defects - **Dithering**: two actions score nearly the same and the winner swaps every cycle, so the villager walks back and forth. Give the running action a small commitment bonus, or let it reach a natural stopping point before re-scoring. - **Unnormalised inputs**: one consideration on a raw scale swamps the rest. - **Bland curves**: linear curves everywhere make a need matter the same amount at every level, so nothing ever feels urgent. - **Missing gates**: an action scored only on desire (hunger) and not on feasibility (food at hand) sends the agent to do something impossible. - **Opaque choices**: without a log or overlay showing each consideration's contribution, nobody can tell why an action won. Score breakdowns are the main debugging tool for this model. ## Where it sits Utility scoring chooses *what* to do. Carrying the chosen action out, such as walking to the woodpile and swinging an axe, is usually handled by simpler execution logic, a behavior tree or a planner. That split is one reason utility scoring often appears as the top layer of a larger decision architecture.
- Why do a utility villager's considerations need normalising before they are combined?Raw inputs live on different scales: hunger as a percentage, distance in metres, time in hours. Combined directly, the input with the biggest numbers dominates regardless of what it means. Mapping each into `0..1` with a chosen minimum and maximum, clamped, puts every consideration on one scale, so the response curve rather than the unit decides how much it matters, and scores stay comparable across actions.
- What stops a utility-driven villager from switching between two actions every cycle when their scores are nearly equal?Give the running action a small commitment bonus, or let it finish an uninterruptible stretch before re-scoring, so a challenger must beat it by a margin. Without that, small changes in the inputs swap the top action back and forth and the villager visibly dithers between the woodpile and the pantry.
Deciding what to do after work by how urgent each need feels: mild hunger barely registers, but near starving it overrides everything, and an empty woodpile nags harder as night falls. The feeling of urgency is the response curve.
- Utility AI is just a weighted random choice among the actions.
- Raw inputs such as distance in metres can be scored without normalising.
- A linear response curve is the right default for every need.
- Every action's score must be recomputed every frame.
- Once the villager picks an action it never needs re-scoring.