Skip to main content

Module behavior_tree

Module behavior_tree 

Source
Expand description

Behavior Tree system — full implementation with composites, decorators, actions, conditions, blackboard, and a fluent builder DSL.

§Design

  • Tick-based execution: tree.tick(&mut ctx) returns Status.
  • Blackboard: shared key/value store passed through context.
  • Nodes are boxed trait objects — fully dynamic, composable at runtime.
  • Zero unsafe, no external dependencies beyond std.

§Quick Start

use proof_engine::ai::behavior_tree::*;
let tree = BehaviorTreeBuilder::new()
    .sequence()
        .condition(|ctx| ctx.blackboard.get_float("health") > 0.0)
        .action(|ctx| { ctx.blackboard.set("attacking", true); Status::Success })
    .end()
    .build();

Structs§

ActionNode
A leaf that performs an action and returns a status.
AiEntity
Generic AI entity for use in example behavior trees.
BehaviorTree
The top-level behavior tree — wraps a root node.
Blackboard
Shared data store accessible by all tree nodes.
BlackboardHas
Checks if a blackboard key has been set.
CheckFloat
CommonBehaviors
Factory for common pre-built behavior trees using AiEntity.
ConditionNode
A leaf that evaluates a closure against the context.
Cooldown
Prevents child from running until a cooldown expires.
Failer
Always returns Failure regardless of child result.
FireEvent
Fires a named event into the context and succeeds.
Guard
Guards child behind a blackboard condition. Re-evaluated every tick.
Inverter
Inverts the child’s result.
Parallel
RandomSelector
Shuffles children order each activation, then tries them in that order.
Repeater
Repeats child N times, or infinitely if N is None.
RetryUntilFail
Repeats until the child fails.
Selector
Executes children left-to-right. Succeeds on FIRST success. Fails if ALL fail. Memory selector: remembers the currently running child.
Sequence
Executes children left-to-right. Succeeds if ALL succeed. Fails on first failure. Remembers the currently running child (memory sequence).
SetBool
Sets a bool on the blackboard and succeeds.
SetFloat
Sets a float on the blackboard and succeeds.
SubTree
Delegates to a separately defined subtree by name. The subtree is looked up in a SubTreeRegistry stored on the blackboard via a string key. For simplicity, we inline the subtree node directly.
Succeeder
Always returns Success regardless of child result.
TickContext
Context passed to every tick call.
TimeLimit
Limits child execution to a maximum wall-clock duration (in seconds).
TreeRunner
Manages a behavior tree instance for one entity, tracking timing and events.
Wait
Waits for duration seconds, then succeeds.
WaitRandom
Waits for a random duration in [min, max] seconds.

Enums§

FloatComparison
Checks a float comparison against a threshold.
ParallelPolicy
Ticks ALL children every frame. Success/failure policy configurable.
Status
The execution status returned by every tree node.

Traits§

Node
A node in the behavior tree.