2.4 – Utility Architecture

2.4.0 – The design
Utility theory highlights the “motivation” behind every decision the AI makes. Each AI has a list of Actions. Each action contains a list of Considerations. Each consideration has a Response Curve and a Input channel. Via the response curve, a normalized Input value is remapped to another normalized value. The resulting values are then multiplied together to get the score of each action. AI searches through the list of action. Whoever has the highest score is selected to be performed next.

2.4.1 – Response curves
To make the remapping simpler, I created a preset of curves that are commonly used–Step, Linear, Polynomial, Logistic, Logit, Normal, Sin–based on Mike Lewis and Dave Mark’s GDC talks and articles. It has been proven that, using 4 parameters–slope, exponent, xshift, yshift–can build a wide variety of curves.

Step:

output = (_input - m_dXShift < 0.5) ? m_dYShift : m_dSlope + m_dYShift;

Linear:
output = (m_dSlope * (_input - m_dXShift)) + m_dYShift;

Polynomial:
output = (m_dSlope * pow(_input - m_dXShift, m_dExponent)) + m_dYShift;

Logistic:
output = (m_dSlope / (1 + exp(-10.0 * m_dExponent * (_input - 0.5 - m_dXShift)))) + m_dYShift;

Logit:
output = m_dSlope * log((_input - m_dXShift) / (1.0 - (_input - m_dXShift))) / 5.0 + 0.5 + m_dYShift

Normal:
output = m_dSlope * exp(-30.0 * m_dExponent * (_input - m_dXShift - 0.5) * (_input - m_dXShift - 0.5)) + m_dYShift;

Sin:
output = 0.5 * m_dSlope * sin(2.0 * M_PI * (_input - m_dXShift)) + 0.5 + m_dYShift;

2.4.2 – Data
XML is used for data storing and loading. The structure of a Utility file is like this:

  <Action id="Run">
    <Consideration name="Health">
      <ResponseCurve type="Linear" slope="-1" exponent="1" xshift="0" yshift="1"/>
      <Input id="Health"/>
    </Consideration>
  </Action>

I use a separate XML file to store input information, mainly for re-using.
  <Input id="Distance" min="0" max="10000"/>
  <Input id="EnemyHealth" min="0" max="100"/>
  <Input id="Health" min="0" max="100"/>
  <Input id="SeeEnemy" min="0" max="1"/>

You May Also Like

1 Comment

Leave a Reply to Jan Kantola Cancel reply

Your email address will not be published. Required fields are marked *

The AI Project