Behavior history

From AI Product Manuals
Jump to navigationJump to search
This page is part of the IAUS Manual.BrainBehaviorBehavior TypeDecisionAI Entity


This page is part of the Brain

Concept

Behavior Histories keep track of the last time a Behavior was executed by an agent. This allows for checking the runtime of the current behavior and the time since the behavior was run.

This is also tracked for behavior types as well so that one can tell when a type was done regardless of the specific behavior that called it. For example, "when was the last time I did a MoveToTarget?" can be checked even though there might be dozens of different behaviors that call "MoveToTarget".

Additionally, it keeps track of Context times so that information can be accessed on when a particular behavior was run with a particular target. This allows the same behavior to be run without repeating it at a particular target. One example would be waving at a variety of passing villagers but not at the same villager on a repeated basis.

Code

For readability of code, the various maps and their components are kept in typedefs.

	typedef std::unordered_map<unsigned int, float> BehaviorHistoryMap;
	typedef std::pair<unsigned int, float> BehaviorHistoryIdAndTime;

	typedef std::unordered_map<ContextEntry, float> ContextHistoryMap;
	typedef std::pair<ContextEntry, float> ContextHistoryIdAndTime;

	typedef std::unordered_map<BehaviorType, float> BehaviorTypeHistoryMap;
	typedef std::pair<BehaviorType, float> BehaviorTypeIdAndTime;

The actual objects are in the member variables in Brain:

	//////////////////////////////////////////////////////////////////////////
	// History Tracking
	BehaviorHistoryMap behaviorHistory;		// History of recent behaviors I have performed (no context)
	ContextHistoryMap contextHistory;		// History of recent decisions I have performed (incl. behavior and context)
	BehaviorTypeHistoryMap behaviorTypeHistory;	// History of recent behaviors I have performed by type only

Each of the maps has functions for:

  • Storing an entry
  • Getting the last time from an entry
  • Cleaning the history based on an expiry time

Cleaning the histories is called from the iteration of the think cycle