Tier 4 Series 304

304A: The Behavior Tree

Pilot Record
Student Profile
"A simple FSM (State Machine) gets tangled like spaghetti when a unit needs to Patrol, Chase, Eat, Sleep, and Flee all at once. A Navigator creates a "Tree" of logic where complex behaviors are built from small, reusable leaves."

The Concept: Behavior Trees

Unlike State Machines where you transition FROM one state TO another, a Behavior Tree evaluates from the Root down every frame.

* **Composites:** Selectors (OR logic) and Sequences (AND logic).
* **Decorators:** Filters like "CanSeePlayer?"
* **Leaves:** The actual actions (Move, Shoot).
Red Flag Detected

The AI Trap: "The Spaghetti FSM"

You ask the AI: "Make the enemy patrol, but if it sees the player, chase, unless health is low, then flee."

// AI-Generated Code: The State Explosion
if (state == Patrol) {
    if (SeePlayer) state = Chase;
    if (Health < 10) state = Flee;
}
else if (state == Chase) {
    if (!SeePlayer) state = Patrol;
    if (Health < 10) state = Flee;
}
// Audit Fail: You have to copy the "Flee" check into EVERY state.

This is "Transition Maintenance." If you add a "Stunned" state, you have to update the logic in every other state to account for it.

Elite Telemetry

Research shows "Elite" teams achieve 15% faster lead times by keeping AI on a "very tight leash."

  • Small Batches Solving one problem at a time prevents logic drift.
  • Modular Design Localizing the "blast radius" of AI changes.
  • Tight Loops Rapid iteration with constant code review.

The Navigator's Correction

Corrective Protocol
// Corrected: The Tree Structure
root = new Selector(
    new Sequence(new LowHealthCheck(), new FleeAction()),
    new Sequence(new VisionCheck(), new ChaseAction()),
    new PatrolAction()
);
Your Pilot Command
> A skilled Navigator directs the AI to use Nodes.
Next Mission
The Blackboard