Utility
Scores candidates by considerations and picks the best or a weighted-random one. Use it inside a state to choose what to act on; use transitions to choose what to do.
local chaseConsiderations = {
{ Input = function(agent, root) return (root.Position - agent:GetPosition()).Magnitude end,
Max = 60, Invert = true, Curve = VluxyAI.Utility.Curves.Quadratic },
{ Input = function(agent, root) return if agent.Blackboard.SeenTarget == root then 1 else 0 end },
}
local root = VluxyAI.Utility.Best(agent, agent.Blackboard.NearbyTargets, chaseConsiderations)
Properties
Curves
Utility.Curves: {}Response curves for Types.Consideration. Each maps [0, 1] to [0, 1].
Linear:x.Quadratic:x^2. Rewards the top end.SquareRoot:sqrt(x). Rewards the bottom end.Power(exponent):x^exponent.Logistic(steepness?, midpoint?): an S curve, steepness default 10, midpoint default 0.5.Threshold(at):0belowat,1at and above. A hard veto.
Functions
Score
Scores one candidate: the product of its considerations. A consideration whose Input returns
something that is not a number scores 0, which vetoes the candidate.
Errors
| Type | Description |
|---|---|
| string | A consideration is malformed. |
ScoreAll
Utility.ScoreAll() → {Scored<T>}--
Sorted best first. Stable for ties.
Scores every candidate. Candidates that score 0 are kept, so a debug view can show why
nothing was chosen.
Best
Utility.Best() → (T?,--
The best candidate, or nil when there are none or every one scored 0.
number--
Its score.
)Picks the highest scoring candidate. Earlier candidates win ties, so a stable input order gives a stable choice.
Weighted
Utility.Weighted(candidates: {T},considerations: {Consideration<T>},) → (T?,--
A candidate chosen with probability proportional to its score, or nil when every one scored 0.
number--
Its score.
)Picks a weighted-random candidate. Use it when the best choice every time reads as robotic; a candidate that scores twice as much is picked twice as often.