Skip to content

Commit

Permalink
Merge pull request #85 from nikkorn/#81
Browse files Browse the repository at this point in the history
Add Race node
  • Loading branch information
nikkorn committed Mar 12, 2024
2 parents e504634 + 1bcf90f commit 000d535
Show file tree
Hide file tree
Showing 16 changed files with 636 additions and 77 deletions.
36 changes: 35 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ root {
```

### Parallel
This composite node will update each child node concurrently. It will move to the `SUCCEEDED` state if all of its children have moved to the `SUCCEEDED` state and will move to the `FAILED` state if any of its children move to the `FAILED` state. This node will remain in the `RUNNING` state if any of its children are in the `RUNNING` state.
This composite node will update each child node concurrently. It will move to the `SUCCEEDED` state if all of its children have moved to the `SUCCEEDED` state and will move to the `FAILED` state if any of its children move to the `FAILED` state, otherwise it will remain in the `RUNNING` state.
[Example](https://nikkorn.github.io/mistreevous-visualiser/index.html?example=parallel)

*MDSL*
Expand Down Expand Up @@ -205,6 +205,40 @@ root {
}
```

### Race
This composite node will update each child node concurrently. It will move to the `SUCCEEDED` state if any of its children have moved to the `SUCCEEDED` state and will move to the `FAILED` state if all of its children move to the `FAILED` state, otherwise it will remain in the `RUNNING` state.
[Example](https://nikkorn.github.io/mistreevous-visualiser/index.html?example=race)

*MDSL*
```
root {
race {
action [UnlockDoor]
action [FindAlternativePath]
}
}
```

*JSON*
```json
{
"type": "root",
"child": {
"type": "race",
"children": [
{
"type": "action",
"call": "UnlockDoor"
},
{
"type": "action",
"call": "FindAlternativePath"
}
]
}
}
```

### 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)
Expand Down
11 changes: 10 additions & 1 deletion dist/BehaviourTreeDefinition.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,15 @@ export interface ParallelNodeDefinition extends CompositeNodeDefinition {
*/
type: "parallel";
}
/**
* A race node.
*/
export interface RaceNodeDefinition extends CompositeNodeDefinition {
/**
* The node type.
*/
type: "race";
}
/**
* A root node.
*/
Expand Down Expand Up @@ -227,7 +236,7 @@ export interface FailNodeDefinition extends DecoratorNodeDefinition {
/**
* A type defining any node definition.
*/
export type AnyNodeDefinition = BranchNodeDefinition | ActionNodeDefinition | ConditionNodeDefinition | WaitNodeDefinition | SequenceNodeDefinition | SelectorNodeDefinition | LottoNodeDefinition | ParallelNodeDefinition | RootNodeDefinition | RepeatNodeDefinition | RetryNodeDefinition | FlipNodeDefinition | SucceedNodeDefinition | FailNodeDefinition;
export type AnyNodeDefinition = BranchNodeDefinition | ActionNodeDefinition | ConditionNodeDefinition | WaitNodeDefinition | SequenceNodeDefinition | SelectorNodeDefinition | LottoNodeDefinition | ParallelNodeDefinition | RaceNodeDefinition | RootNodeDefinition | RepeatNodeDefinition | RetryNodeDefinition | FlipNodeDefinition | SucceedNodeDefinition | FailNodeDefinition;
/**
* A type defining any node type that can be a child of composite parent node.
*/
Expand Down
84 changes: 67 additions & 17 deletions dist/bundle.js

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

6 changes: 3 additions & 3 deletions dist/bundle.js.map

Large diffs are not rendered by default.

84 changes: 67 additions & 17 deletions dist/index.js

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

6 changes: 3 additions & 3 deletions dist/index.js.map

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions dist/nodes/composite/Race.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import Composite from "./Composite";
import Node from "../Node";
import { Agent } from "../../Agent";
import Attribute from "../../attributes/Attribute";
import { BehaviourTreeOptions } from "../../BehaviourTreeOptions";
/**
* A RACE node.
* The child nodes are executed concurrently until one succeeds or all fail.
*/
export default class Race extends Composite {
/**
* @param attributes The node attributes.
* @param children The child nodes.
*/
constructor(attributes: Attribute[], children: Node[]);
/**
* Called when the node is being updated.
* @param agent The agent.
* @param options The behaviour tree options object.
*/
protected onUpdate(agent: Agent, options: BehaviourTreeOptions): void;
/**
* Gets the name of the node.
*/
getName: () => string;
}
Loading

0 comments on commit 000d535

Please sign in to comment.