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)returnsStatus. - 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§
- Action
Node - A leaf that performs an action and returns a status.
- AiEntity
- Generic AI entity for use in example behavior trees.
- Behavior
Tree - The top-level behavior tree — wraps a root node.
- Blackboard
- Shared data store accessible by all tree nodes.
- Blackboard
Has - Checks if a blackboard key has been set.
- Check
Float - Common
Behaviors - Factory for common pre-built behavior trees using
AiEntity. - Condition
Node - 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.
- Fire
Event - 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
- Random
Selector - Shuffles children order each activation, then tries them in that order.
- Repeater
- Repeats child N times, or infinitely if N is None.
- Retry
Until Fail - 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
SubTreeRegistrystored on the blackboard via a string key. For simplicity, we inline the subtree node directly. - Succeeder
- Always returns Success regardless of child result.
- Tick
Context - Context passed to every tick call.
- Time
Limit - Limits child execution to a maximum wall-clock duration (in seconds).
- Tree
Runner - Manages a behavior tree instance for one entity, tracking timing and events.
- Wait
- Waits for
durationseconds, then succeeds. - Wait
Random - Waits for a random duration in [min, max] seconds.
Enums§
- Float
Comparison - Checks a float comparison against a threshold.
- Parallel
Policy - 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.