Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I just looked at that implementation and I find myself wondering why so much code is needed for something relatively simple.</p> <p>From what you say, you want a simple way of composing behaviours. A behaviour here, I presume, is a mapping from a state to zero or more actions by an agent. You can model this very easily using C# lambdas. For example:</p> <pre><code>Action Selector(Func&lt;bool&gt; cond, Action ifTrue, Action ifFalse) { return () =&gt; { if cond() then ifTrue() else ifFalse() }; } Action Sequencer(Action a, Action b) { return () =&gt; { a(); b(); } } </code></pre> <p>The leaves of your tree are simple Actions that do something appropriate to the state. You "run" a tree simply by executing it.</p> <p>If you want to get fancy, you can parameterise this scheme to make the state explicit.</p> <p>Hope this helps.</p> <p>---- Addendum ----</p> <p>Jason asked for an example of how you could use this approach, so here's a simple "AI" patrolling guard example (I assume WorldState corresponds to a description of the environment at the time the behaviour tree is evaluated):</p> <pre><code>Func&lt;bool&gt; ifPlayerIsInSight = () =&gt; ...true iff WorldState shows guard can see player...; Action shootAtPlayer = () =&gt; { ...aim guard's weapon at player and fire... }; Func&lt;bool&gt; ifUnderFire = () =&gt; ...true iff WorldState shows guard hears player gunfire...; Action takeCover = () =&gt; { ...guard runs for nearest shelter... }; Action walkBackAndForthGuardingDoorway = () =&gt; { ...default guard patrol behaviour... }; Action patrollingGuardBehaviour = Selector(ifPlayerIsInSight, shootAtPlayer, Selector(ifUnderFire, takeCover, walkBackAndForthGuardingDoorway)); </code></pre> <p>To make the guard do something, just call <code>patrollingGuardBehaviour()</code>. Note that the various subactions and tests can be implemented as methods with the right signatures rather than inline as lambdas. You can add other combinators to <code>Selector</code> and <code>Sequencer</code>, e.g., for parallel activity.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. CORafe... behavior trees are a bit more involved actually... let me try to simply explain them: The tree starts with a root.. and then it branches into seperate branches of logic from there. Each branch has a "filter" that decides whether or not the AI needs to take that branch or not. There are also "sequencers" that run a sequence of actions, returning upon the failure of any action, and "selectors" that run actions until a success is found (disregards failures). There are other things, but that is the core of it. Could we talk about this a bit more over chat somehow?
      singulars
    2. COI'm just really confused at how I could actually impliment something like that in C#.. your example is really good but.. again I can't really understand it. Maybe for your implimentation you could write a little example that would show actually using the structure?
      singulars
    3. COFirst you build the tree: you define actions and when (conditions) and how (in parallel, sequentially, etc.) they are executed. For simplicity, start with a tree that always starts execution from the root node and chooses its child(ren) depending on current conditions (sensory input). There are many implementation details and improvements, but that's the simplest workflow. Are you sure you understand BTs as a concept? If you're not, try http://aigamedev.com/insider/presentations/behavior-trees/ (free registration required) and their forums.
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload