Skip to content

Commit

Permalink
Fixed issues with action nodes not handling update promise rejections…
Browse files Browse the repository at this point in the history
… properly and added specs
  • Loading branch information
Nikolas Howard committed Feb 26, 2024
1 parent c1dd5d3 commit 7c54e03
Show file tree
Hide file tree
Showing 14 changed files with 388 additions and 79 deletions.
139 changes: 137 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
[![npm version](https://badge.fury.io/js/mistreevous.svg)](https://badge.fury.io/js/mistreevous)
[![Node.js CI](https://github.com/nikkorn/mistreevous/actions/workflows/node.js.yml/badge.svg?branch=master)](https://github.com/nikkorn/mistreevous/actions/workflows/node.js.yml)

A tool to declaratively define and generate behaviour trees, built using Typescript. Behaviour trees are used to create complex AI via the modular heirarchical composition of individual tasks.
A library to declaratively define, build and execute behaviour trees, written in Typescript. Behaviour trees are used to create complex AI via the modular heirarchical composition of individual tasks.

Using this tool, trees can be defined with a simple and minimal built-in DSL, avoiding the need to write verbose definitions in JSON.
Using this tool, trees can be defined with either JSON or a simple and minimal built-in DSL (MDSL), avoiding the need to write verbose definitions in JSON.

![Sorting Lunch](resources/images/sorting-lunch-example.png?raw=true "Sorting Lunch")

Expand Down Expand Up @@ -97,6 +97,7 @@ Composite nodes wrap one or more child nodes, each of which will be processed in
This composite node will update each child node in sequence. It will succeed if all of its children have succeeded and will fail if any of its children fail. This node will remain in the running state if one of its children is running.
[Example](https://nikkorn.github.io/mistreevous-visualiser/index.html?example=sequence)

*MDSL*
```
root {
sequence {
Expand All @@ -107,10 +108,35 @@ root {
}
```

*JSON*
```js
{
"type": "root",
"child": {
"type": "sequence",
"children": [
{
"type": "action",
"call": "Walk"
},
{
"type": "action",
"call": "Fall"
},
{
"type": "action",
"call": "Laugh"
}
]
}
}
```

### Selector
This composite node will update each child node in sequence. It will fail if all of its children have failed and will succeed if any of its children succeed. This node will remain in the running state if one of its children is running.
[Example](https://nikkorn.github.io/mistreevous-visualiser/index.html?example=selector)

*MDSL*
```
root {
selector {
Expand All @@ -121,10 +147,35 @@ root {
}
```

*JSON*
```js
{
"type": "root",
"child": {
"type": "selector",
"children": [
{
"type": "action",
"call": "TryThis"
},
{
"type": "action",
"call": "ThenTryThis"
},
{
"type": "action",
"call": "TryThisLast"
}
]
}
}
```

### Parallel
This composite node will update each child node concurrently. It will succeed if all of its children have succeeded and will fail if any of its children fail. This node will remain in the running state if any of its children are running.
[Example](https://nikkorn.github.io/mistreevous-visualiser/index.html?example=parallel)

*MDSL*
```
root {
parallel {
Expand All @@ -134,10 +185,31 @@ root {
}
```

*JSON*
```js
{
"type": "root",
"child": {
"type": "parallel",
"children": [
{
"type": "action",
"call": "RubBelly"
},
{
"type": "action",
"call": "PatHead"
}
]
}
}
```

### Lotto
This composite node will select a single child at random to run as the active running node. The state of this node will reflect the state of the active child.
[Example](https://nikkorn.github.io/mistreevous-visualiser/index.html?example=lotto)

*MDSL*
```
root {
lotto {
Expand All @@ -147,9 +219,30 @@ root {
}
```

*JSON*
```js
{
"type": "root",
"child": {
"type": "lotto",
"children": [
{
"type": "action",
"call": "MoveLeft"
},
{
"type": "action",
"call": "MoveRight"
}
]
}
}
```

A probability weight can be defined for each child node as an optional integer node argument, influencing the likelihood that a particular child will be picked.
[Example](https://nikkorn.github.io/mistreevous-visualiser/index.html?example=weighted-lotto)

*MDSL*
```
root {
lotto [10,5,3,1] {
Expand All @@ -161,6 +254,35 @@ root {
}
```

*JSON*
```js
{
"type": "root",
"child": {
"type": "lotto",
"children": [
{
"type": "action",
"call": "CommonAction"
},
{
"type": "action",
"call": "UncommonAction"
},
{
"type": "action",
"call": "RareAction"
},
{
"type": "action",
"call": "VeryRareAction"
}
],
"weights": [10, 5, 3, 1]
}
}
```

## Decorator Nodes
A decorator node is similar to a composite node, but it can only have a single child node. The state of a decorator node is usually some transformation of the state of the child node. Decorator nodes are also used to repeat or terminate execution of a particular node.

Expand All @@ -169,14 +291,27 @@ This decorator node represents the root of a behaviour tree and cannot be the ch

The state of a root node will reflect the state of its child node.

*MDSL*
```
root {
action [Dance]
}
```

*JSON*
```js
{
"type": "root",
"child": {
"type": "action",
"call": "Dance"
}
}
```

Additional named root nodes can be defined and reused throughout a definition. Other root nodes can be referenced via the **branch** node. Exactly one root node must be left unnamed, this root node will be used as the main root node for the entire tree.

*MDSL*
```
root {
branch [SomeOtherTree]
Expand Down
36 changes: 24 additions & 12 deletions dist/bundle.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/bundle.js.map

Large diffs are not rendered by default.

36 changes: 24 additions & 12 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/nodes/leaf/Action.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default class Action extends Leaf {
/**
* The finished state result of an update promise.
*/
private updatePromiseStateResult;
private updatePromiseResult;
/**
* Called when the node is being updated.
* @param agent The agent.
Expand Down
Loading

0 comments on commit 7c54e03

Please sign in to comment.