<spanid="evennia-contrib-tutorials-evadventure-ai"></span><h1>evennia.contrib.tutorials.evadventure.ai<aclass="headerlink"href="#module-evennia.contrib.tutorials.evadventure.ai"title="Permalink to this headline">¶</a></h1>
<p>NPC AI module for EvAdventure (WIP)</p>
<p>This implements a state machine for the NPCs, where it uses inputs from the game to determine what
to do next. The AI works on the concept of being ‘ticks’, at which point, the AI will decide to move
between different ‘states’, performing different ‘actions’ within each state until changing to
another state. The odds of changing between states and performing actions are weighted, allowing for
an AI agent to be more or less likely to perform certain actions.</p>
<p>The state machine is fed a dictionary of states and their transitions, and a dictionary of available
<emclass="property">class </em><codeclass="sig-prename descclassname">evennia.contrib.tutorials.evadventure.ai.</code><codeclass="sig-name descname">AIHandler</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">obj</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/contrib/tutorials/evadventure/ai.html#AIHandler"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.contrib.tutorials.evadventure.ai.AIHandler"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">__init__</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">obj</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/contrib/tutorials/evadventure/ai.html#AIHandler.__init__"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.contrib.tutorials.evadventure.ai.AIHandler.__init__"title="Permalink to this definition">¶</a></dt>
<dd><p>Initialize self. See help(type(self)) for accurate signature.</p>
<emclass="property">property </em><codeclass="sig-name descname">state</code><aclass="headerlink"href="#evennia.contrib.tutorials.evadventure.ai.AIHandler.state"title="Permalink to this definition">¶</a></dt>
<dd><p>Return the current state of the AI.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Returns</dt>
<ddclass="field-odd"><p><em>str</em>– Current state of the AI.</p>
<emclass="property">property </em><codeclass="sig-name descname">states</code><aclass="headerlink"href="#evennia.contrib.tutorials.evadventure.ai.AIHandler.states"title="Permalink to this definition">¶</a></dt>
<dd><p>Return the states dictionary for the AI.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Returns</dt>
<ddclass="field-odd"><p><em>dict</em>– States dictionary for the AI.</p>
<emclass="property">property </em><codeclass="sig-name descname">transitions</code><aclass="headerlink"href="#evennia.contrib.tutorials.evadventure.ai.AIHandler.transitions"title="Permalink to this definition">¶</a></dt>
<dd><p>Return the transitions dictionary for the AI.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Returns</dt>
<ddclass="field-odd"><p><em>dict</em>– Transitions dictionary for the AI.</p>
<codeclass="sig-name descname">add_aidict</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">aidict</span></em>, <emclass="sig-param"><spanclass="n">force</span><spanclass="o">=</span><spanclass="default_value">False</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/contrib/tutorials/evadventure/ai.html#AIHandler.add_aidict"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.contrib.tutorials.evadventure.ai.AIHandler.add_aidict"title="Permalink to this definition">¶</a></dt>
<dd><p>Add an AI dictionary to the AI handler, if one doesn’t already exist.</p>
<codeclass="sig-name descname">adjust_transition_probability</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">state_start</span></em>, <emclass="sig-param"><spanclass="n">state_end</span></em>, <emclass="sig-param"><spanclass="n">odds</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/contrib/tutorials/evadventure/ai.html#AIHandler.adjust_transition_probability"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.contrib.tutorials.evadventure.ai.AIHandler.adjust_transition_probability"title="Permalink to this definition">¶</a></dt>
<dd><p>Adjust the transition probability between two states.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>state_start</strong> (<em>str</em>) – State to start from.</p></li>
<li><p><strong>state_end</strong> (<em>str</em>) – State to end at.</p></li>
<li><p><strong>odds</strong> (<em>int</em>) – New odds for the transition.</p></li>
</ul>
</dd>
</dl>
<divclass="admonition note">
<pclass="admonition-title">Note</p>
<p>This will normalize the odds across the other transitions from the starting state.</p>
<codeclass="sig-name descname">get_next_state</code><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/contrib/tutorials/evadventure/ai.html#AIHandler.get_next_state"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.contrib.tutorials.evadventure.ai.AIHandler.get_next_state"title="Permalink to this definition">¶</a></dt>
<dd><p>Get the next state for the AI.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Returns</dt>
<ddclass="field-odd"><p><em>str</em>– Next state for the AI.</p>
<codeclass="sig-name descname">get_next_action</code><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/contrib/tutorials/evadventure/ai.html#AIHandler.get_next_action"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.contrib.tutorials.evadventure.ai.AIHandler.get_next_action"title="Permalink to this definition">¶</a></dt>
<dd><p>Get the next action for the AI within the current state.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Returns</dt>
<ddclass="field-odd"><p><em>str</em>– Next action for the AI.</p>
<codeclass="sig-name descname">execute_ai</code><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/contrib/tutorials/evadventure/ai.html#AIHandler.execute_ai"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.contrib.tutorials.evadventure.ai.AIHandler.execute_ai"title="Permalink to this definition">¶</a></dt>
<dd><p>Execute the next ai action in the current state.</p>
<p>This assumes that each available state exists as a method on the object, named
ai_<state_name>, taking an optional argument of the next action to perform. The method
will itself update the state or transition weights through this handler.</p>
<p>Some states have in-built state transitions, via the special “change_state” action.</p>