Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Reactive Behavior Trees


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 Ender1618   Members   -  Reputation: 243

Like
0Likes
Like

Posted 25 September 2012 - 07:56 PM

So I am back to trying to understand how to use behavior trees for my AI decision making. So right now I am looking at BTs from the perspective of Alex's presentation on second generation behavior trees on AiGameDev. Although i am not going to implement a second generation tree just yet. From my understanding a second gen tree implementation is just an optimization of a first gen tree, where the node layout is identical just traversal is optimized.

So lets start simple with a first gen tree, from what I understand the tree is ticked from the root every think cycle. Sequences and selectors maintain a memory of the current child they left off on since the last tick, and when hitting that sequence or selector again we just continue with the evaluation of that child subtree until it succeeds or fails. After something like a sequence or selector has succeeded or failed the current child node indicator is reset to point at the first child again.

So a tree like this is problematic:
selector
--sequence
----Cond(Health low)
----SubTree(Flee)
--sequence
----Cond(Has target)
----SubTree(Attack)
--Subtree(Idle)
Here the conditions would be checked only once when entering the sequence, so we could not react to changes unless the subtree failed (e.g. attack). For example if we entered the first sequence, checked the condition (which at the time was true), the entered the Flee subtree, that condition would not be checked again until we either succeeded or failed that subtree (which would only have the condition checked once we re-entered the parent sequence later on).

Another way to approach this would be something like this?:
selector
--parallel
----[Not]Cond(Health low)
----[Not]Cond(Has Target)
----SubTree(Idle)
--parallel
----Cond(Health low)
----[Not]Cond(Has Target)
----SubTree(Flee)
--parallel
----[Not]Cond(Health low)
----Cond(Has Target)
----SubTree(Attack)

This seems horribly convoluted, and would get even more complicated for more subtrees i might need to bail out of in this subtree selection.

I heard something about ActiveSelectors being able to always take the highest priority subtree that continually checked conditions will allow, but I am a bit confused on how this wold be implemented (sequence and selectors seem pretty straight forward in their implementations).

Anyone have any insights?

Edited by Ender1618, 25 September 2012 - 09:36 PM.


Sponsor:

#2 alexjc   Members   -  Reputation: 450

Like
0Likes
Like

Posted 26 September 2012 - 04:09 AM

Yes, ActiveSelectors are a nice solution to this particular example. You'll first need to figure out your "specification" for how that should happen, e.g. every frame check all nodes of higher priority than the currently executing one and if one can execute simply deactivate the current one.

Once you have that specification, the code is relatively straightforward. I've done this differently a bunch of times, but most recently managed to get it working by mostly reusing the passive selector logic. Just write unit tests and it'll work out!

Alex

Join us in Vienna for the Game/AI Conference 2014, on July 7-10... Don't miss it!


#3 Ender1618   Members   -  Reputation: 243

Like
0Likes
Like

Posted 26 September 2012 - 07:10 AM

Hmm but how is this implemented?

Does each subtree of the selector have associated with it a condition (or condition subtree) that is ticked every frame (where the actual subtrees that we want to choose from do not necessarily get ticked)? Then the left most (highest priority) subtree whose associated condition has proved true is then run (meaning its subtree is traversed). So its like a parallel that only runs conditions in parallel?

Thx

#4 alexjc   Members   -  Reputation: 450

Like
0Likes
Like

Posted 26 September 2012 - 12:24 PM

You could create a selector as you describe it, with a separate condition tree (read-only) and then a behavior tree (read-write). However, you'll find those are a pain to maintain in a similar way than your previous example.

The way I use active selectors, I basically want the exact same as a passive selector, but instead running those higher priority branches every frame and aborting the lower-priority ones if those succeed. If that's the specification you want, then the implementation of it should be straight forward. (If not, just ask! :-)

Alex

Join us in Vienna for the Game/AI Conference 2014, on July 7-10... Don't miss it!


#5 Ender1618   Members   -  Reputation: 243

Like
0Likes
Like

Posted 27 September 2012 - 01:15 PM

I am a bit confused as to your explanation of the ActiveSelector implementation.

In your description how does an active selector differ than a normal selector. A normal selector will check the highest priority child (left most subtree) first, and then move on to the next child (on the next tick) if the previous child returned failure. How does the active selector differ? Does the child pointer just not increment on the next tick?

What do you mean by aborting the lower priority subtrees? Does that mean just not traversing them?

Thx

#6 Ender1618   Members   -  Reputation: 243

Like
0Likes
Like

Posted 01 October 2012 - 12:17 PM

Thought about it a bit more, by ActiveSelector do you mean a selector that always evaluates from highest priority (left most) to lowest when it is visited, instead of (like a normal selector) continuing with the last visited subtree during the next tick. You have to keep track of what subtree you where in before so that if you need to abandon that subtree on the next tick, you can reset all of that subtree's child iterators. Does that make sense?

Edited by Ender1618, 01 October 2012 - 12:43 PM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS