Blueshell is a Behavior Tree implementation written in Typescript.
It is synchronous for performance - asynchronous operations can be handled by returning async operations to your framework for evaluation, these can then generate new events to drive the behavior tree.
- Handles the event normally and must return a result
- Executes a provided synchronous function (
(state, event) => boolean) and returnsSUCCESSorFAILUREbased upon the boolean result of such function.
- Executes a provided synchronous function (
(state, event) => void) and always returnsSUCCESS.
- Immediately returns
SUCCESSwhen activated.
(aka Priority or Fallback)
- Sends an event to each child until one of them returns
SUCCESSorRUNNING, then returns that value. - If we exhaust all the children, return
FAILURE.
- Sends an event to each child until one of them returns
SUCCESSorRUNNING, then returns that value. - If we exhaust all the children, return
FAILURE. - If a child returns
RUNNING, subsequent events start at that child.
- Sends an event to each child until one of the returns
FAILURE, orRUNNING, then returns that value. - If all children return
SUCCESS, returnSUCCESS.
- Sends an event to each child until one of the returns
FAILURE, orRUNNING, then returns that value. - If all children return
SUCCESS, returnSUCCESS. - If a child returns
RUNNING, subsequent events start at that child.
- Accepts a
conditionalfunction aconsequentnode, and an optionalalternativenode. - If
conditional(state, event)returns true, will return the result of activating theconsequentnode. - If
conditional(state, event)returns false, will return the result of activating thealternativenode, if one is provided. - If
conditional(state, event)returns false, will returnFAILUREif noalternativenode is provided.
Decorators intercept and can modify the event sent to or the result from the child.
- Returns 'FAILURE' when the child returns 'SUCCESS', and vice-versa
- Repeats the child when an evaluation function returns true.
- Repeats the child if it returns the specified status.
- Allows you to swap one result of a child node for another.
- For example, you can use this to mask
FAILUREasSUCCESS.
- The base of all nodes.
- The base class for all nodes which have children.
- The base class for decorators.
- Can only have one child.
- The publisher can be registered with the tree which will log each transition.
The following are sources used when designing this library
- Handling Node Traversal
- Difference between a Decision Tree and a Behavior Tree
- Behavior Trees for AI
- Wikipedia Article
- What is a Behavior Tree?
- Halo 2's AI
- Halo 2 was the first game to popularize Behavior Trees.
Blueshell is named for a Skroderider from the novel A Fire Upon the Deep
by Vernor Vinge. Skroderiders are intelligent plants (trees) that use mechanical constructs to give them locomotion
and short-term memory.
In other words, Blueshell is an intelligent tree. Or a tree with behavior. Get it?