So I'm working with my BehaviorTree implementation as part of my Sim AI (FPS like Sim, but alot of social interaction).

I keep coming to the issue where I am at a particular node of my BT (say part of the idle subtree), but at that point there are a large number of things the player can do that an observing AI agent(s) needs to respond to (gaze zones, (non)aggressive postures, picking up various object in the scene, shooting at, dropped a grenade, all the things you can can say, gestures, and many more).

Another instance where this type of thing happens is player to NPC dialogs.

This need to respond to a large number of things (at any time), quickly really complicates the BT (at least the way im constructing it). Also my BT visual editor becomes a mess that is dificult to navigate and understand. With BTs I was trying to avoid the mess that happens with a visual HFSM editor.

How do people usually deal with this in a BT framework? Lots and lots of monitor nodes high up in the tree (or a high up active selector with MANY children)? Also if a monitor picks up a specific event, that event needs to be handled with respect to previous context (where you were in the tree before the event), how is that usually accomplished?

Is it a common practice for the BT to have a more DAG like structure, where nodes lower in the tree have children that are higher up in the tree (multiple parents for that node), potentially causing cyclical references? Dialogs seem to potentially need something like this.

From your description, it seems that this large amount of events and rules is desired and working well, and the only trouble is with representing and editing a complex rule system. The first suggestion that comes to mind is better encapsulation, like "macros" that can be referenced multiple times without cluttering nodes with excessive numbers of children and abstractions (e.g. a "change feelings depending on gestures and gaze zones etc." black box, decoupled from acting upon the changed feelings) to limit node fan-out.

How do people usually deal with this in a BT framework? Lots and lots of monitor nodes high up in the tree (or a high up active selector with MANY children)? Also if a monitor picks up a specific event, that event needs to be handled with respect to previous context (where you were in the tree before the event), how is that usually accomplished?

What's the point of placing nodes in such unnatural places that they execute with a wrong context?

What I meant by nodes executing with respect to the right context is if for example, I placed many monitor nodes (or an activeselector with condition controlled subtrees) higher up in the tree (would only have to that once) that would respond to all the events that I could be looking for.

One of those monitors might fire, while I am lower in the tree somewhere, but that monitor at a higher level wouldn't know where i was in the tree previously (at least the way I implemented my monitor/activeselector), and just switch out to the tree under the monitor, loosing the context of what was going on.

If every node in the tree that would be considered a special context for an event, were to have the all the monitors duplicated there, that would be ALOT of monitors.

Its not so much a matter of time investment of building up my current framework (although emotionally i guess it irrationally factors in), its that the method (BT) is working for me in a myriad of ways that HFSMs failed me or over complicated things.

The goal is that the AI is almost completely data driven, and there is visual tool, that a semi-layman can use for authoring. I have worked with HFSMs (with a visual tool) this way and found it could be pretty awkward expressing things (that I care aboutfor my AI) that are easy to express in BT.

The many context event problem. may be one of those problems expressed in a BT would be just as cumbersome or even worse. Square peg, round hole.

Every method has its pros and cons. I need to consider other methodology maybe for this type of problem. I just would like to try to continue using BT for most things and another method for this issue. Yet mixing things is often harder than it seems.

I am a big fan of utility-based architectures. You list the available actions, compute a function that maps action to a real number and pick the action for which the number is highest. The real number you compute is an indication of how happy the agent is with the action (technically it should be the expected value of the agent's utility function). The actions of any rational agent can be expressed in this framework (for some definition of "rational" that I happen to like).

For a video game, you can probably get away with your utility function being just a sum of terms that indicate features that make an action desirable or undesirable. In some situations there is a natural scale for measuring utility (e.g., dollars), but sometimes it is tricky to balance terms that are very different in nature. Most of the terms in the utility function can simply be one-variable functions: One for health, one for health of my allies, one for health of my target (if I have one), one for how much money I have, one for obeying an order... The exact shape of those functions could be data driven.

It might take a bit of work to get used to expressing behavior as maximization instead of more direct commands, but I have had very good experiences with these systems. In particular, they are easy to tweak when agents are not behaving as desired (especially if you build some dumping mechanism for debugging), and they prioritize desires extremely well in unusual circumstances (so they don't try to finish their coffee when someone walks into the room with a gun, because the satisfaction of having coffee is dwarfed by the desire to be safe).

I expect it would be relatively easy to integrate BTs and utility-based decisions, for instance by having some action-selection node in the BT that evaluates a utility function to decide which plan to take. I have no experience with these mixed systems, and I prefer to keep things uniform. But if you are heavily invested in BTs, you might want to consider this option.

1) a goal selection system that analyses the current situation and picks the highest priority goal.+ solution (evaluation of this is often the most difficult to come up with equivalency metrics for situational factors)

2) an executor for that goal+solution which is specific to the solution - you could continue to use your Behavior Tree method here - just one 'tree' for each specific solution

Effectively you break up you one ginourmous tree to mutliple specific use trees - with one run when its matching goal+solution is active (this gets rid of excess logic outside its own domain)

The (1) analysis + goal selection does not have to run each cycle, though you may need to do so when certain significant events happen (triggering a general reevaluation...)

If the same goal+solution is selected again it should be resumed (to restore the progress made)

Each BT should have 'cut' checks that would be reevaluated frequently to see if the current solution is still valid (situation hasnt changed) which on failing would push execution back to the goal selection (1) stage

Edited by wodinoneeye, 24 April 2013 - 07:32 AM.

--------------------------------------------Ratings are Opinion, not Fact