Main Loop

Agent's Logic Flow Diagram



Click on the diagram for full size.

The Agent's Main Loop


When an Agent starts up its initialized and then kicks off a Coroutine that runs every X seconds along with a random 0 to Y seconds delay. This random delay helps spread out the Agents planning frames and also adds some noise to Agent's reaction time. This Loop will continue to run as long as the agent isActive.

The first step of detecting Entities causes all of the Agent's SensorTypes to run. Each SensorType detects Entities and adds any new Entity information into the Agent's Memory. The second step is to call its decider.Run() method. This is seen in the above diagram (click for larger version) and is described in the next section. The third step makes time updates to Drive Levels. The fourth and final step is to Update the Agent's location knowledge. This helps the Agent know where its been so it can Explore unseen areas.

Decider.Run


The Decider's main method is Run which handles the high level logic flow for the following:

  • When to Interrupt a currently running Mapping?
  • When to GetPlans from the PlannerType?
  • If a Plan is running and the Decider asked for new Plans, should Agent switch Plans?
  • Choosing which Plan to run.
  • Starting a Plan.
  • Starting a Mapping.

As can be seen in the above diagram all of the key methods have their logic defined in the Decider Type. This allows you to easily customize the logic to your own needs.

For more information on Decider go here.

Behavior


A Behavior is responsible for running a Mapping. It creates its own coroutine in the StartBehavior method. The coroutine runs the UpdateBehavior method every X seconds until the isRunning member variable becomes false. This can happen due to IsFinished returning true or from it being Interrupted by either the Behavior Type or from the Decider. The Behavior Type has all of the core logic for what should occur during the Mapping.

For more information on Behavior and Behavior Type go here.

Interrupt Logic


It is key to be able to interrupt any Mapping at anytime during the Behavior. The Interrupt Logic allows this and provides ways to cleanly interrupt Behaviors from either in the BehaviorType or from the Decider. Any other part of TAI would use the Decider Interrupt. For example, if an Agent is killed it needs to interrupt its Behavior by calling its Decider's Interrupt method and then run the die logic. Since interrupts can come from two sources and both need to know about it, there is logic to inform the other system about the interrupt.