Difference between revisions of "Behavior history"
m (Added header)
m (Davemark moved page Behavior History to Behavior history without leaving a redirect: Capitalization)
Latest revision as of 13:51, 7 October 2021
This page is part of the IAUS Manual. ♦ Brain ♦ Behavior ♦ Behavior Type ♦ Decision ♦ AI Entity ♦
This page is part of the Brain
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.
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