AgentJS agent-based modelling in the browser

Points with a behaviour tree

Ninety points each run their own behaviour tree: rest when tired, go to the marker when it is near, otherwise wander.

starting

resting (ring)approaching the marker (square)wandering (dot)colour: energy, from low to high

Every point owns a BehaviorTree whose root is a SelectorNode, which tries its branches from left to right until one succeeds. The first branch is a SequenceNode that checks a ConditionNode (is the energy low?) and then runs an ActionNode that rests. That action returns RUNNING until the point has recovered, so the point stays in the branch.

The second branch moves towards the marker if it is within reach, spending energy as it goes; the third is the fallback and wanders. Click the canvas to move the marker.

Colour is the point’s energy, from low to high. The shape says which branch ran last: a ring is resting, a square is approaching, a dot is wandering.

Classes used

BehaviorTree, SelectorNode, SequenceNode, ConditionNode, ActionNode, NodeStatus, MovingAgent (moveToward, wander, stop), ContinuousSpace, RandomScheduler.

Source

This is example.js, the file this page runs.

Loading the source…