Skip to content

Commit

Permalink
Updated Agent typings
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikolas Howard committed Feb 19, 2024
1 parent 70699ad commit 0b9581c
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion dist/Agent.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { CompleteState } from "./State";
* A type representing an agent that a behavior tree instance would operate on.
*/
export type Agent = {
[actionName: string]: AgentFunction;
[propertyName: string]: AgentFunction | unknown;
};
export type ExitFunctionArg = {
succeeded: boolean;
Expand Down
2 changes: 1 addition & 1 deletion src/Agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { CompleteState } from "./State";
* A type representing an agent that a behavior tree instance would operate on.
*/
export type Agent = {
[actionName: string]: AgentFunction;
[propertyName: string]: AgentFunction | unknown;
};

/*
Expand Down
10 changes: 5 additions & 5 deletions test/BehaviourTree.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe("A BehaviourTree instance", () => {
describe("has a 'getState' function that returns the state of the root node", () => {
it("(MDSL)", () => {
const definition = "root { action [getActionResult] }";
const agent: Agent = { getActionResult: () => {} };
const agent = { getActionResult: () => {} };
const tree = new BehaviourTree(definition, agent);

assert.strictEqual(tree.getState(), State.READY);
Expand Down Expand Up @@ -144,7 +144,7 @@ describe("A BehaviourTree instance", () => {
describe("has a 'reset' function that resets the tree from the root node outwards to each nested node, giving each a state of READY", () => {
it("(MDSL)", () => {
const definition = "root { sequence { action [getActionResult] } }";
const agent: Agent = { getActionResult: () => State.SUCCEEDED };
const agent = { getActionResult: () => State.SUCCEEDED };
const tree = new BehaviourTree(definition, agent);

assert.strictEqual(findNode(tree, "root", "ROOT").state, State.READY);
Expand Down Expand Up @@ -177,7 +177,7 @@ describe("A BehaviourTree instance", () => {
]
}
};
const agent: Agent = { getActionResult: () => State.SUCCEEDED };
const agent = { getActionResult: () => State.SUCCEEDED };
const tree = new BehaviourTree(definition, agent);

assert.strictEqual(findNode(tree, "root", "ROOT").state, State.READY);
Expand All @@ -202,7 +202,7 @@ describe("A BehaviourTree instance", () => {
it("(MDSL)", () => {
const definition =
"root { sequence { action [getActionResult0] action [getActionResult1] action [getActionResult2] action [getActionResult3] } }";
const agent: Agent = {
const agent = {
getActionResult0: () => State.SUCCEEDED,
getActionResult1: () => State.SUCCEEDED,
getActionResult2: () => {},
Expand Down Expand Up @@ -266,7 +266,7 @@ describe("A BehaviourTree instance", () => {
]
}
};
const agent: Agent = {
const agent = {
getActionResult0: () => State.SUCCEEDED,
getActionResult1: () => State.SUCCEEDED,
getActionResult2: () => {},
Expand Down
4 changes: 2 additions & 2 deletions test/nodes/composite/Selector.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe("A Selector node", () => {
it("(MDSL)", () => {
const definition =
"root { selector { action [actionFail] action [actionRunning] action [actionSucceed] } }";
const agent: Agent = {
const agent = {
actionSucceed: () => State.SUCCEEDED,
actionRunning: () => {},
actionFail: () => State.FAILED
Expand Down Expand Up @@ -87,7 +87,7 @@ describe("A Selector node", () => {
]
}
};
const agent: Agent = {
const agent = {
actionSucceed: () => State.SUCCEEDED,
actionRunning: () => {},
actionFail: () => State.FAILED
Expand Down
8 changes: 4 additions & 4 deletions test/nodes/leaf/Action.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe("An Action node", () => {

it("an agent function", () => {
const definition = "root { action [doAction] }";
const agent: Agent = { doAction: () => State.SUCCEEDED };
const agent = { doAction: () => State.SUCCEEDED };
const tree = new BehaviourTree(definition, agent);

tree.step();
Expand All @@ -61,7 +61,7 @@ describe("An Action node", () => {
describe("and move to", () => {
it("the SUCCESS state if the function returns a value of State.SUCCEEDED", () => {
const definition = "root { action [doAction] }";
const agent: Agent = { doAction: () => State.SUCCEEDED };
const agent = { doAction: () => State.SUCCEEDED };
const tree = new BehaviourTree(definition, agent);

let node = findNode(tree, "action", "doAction");
Expand All @@ -75,7 +75,7 @@ describe("An Action node", () => {

it("the FAILED state if the function returns a value of State.FAILED", () => {
const definition = "root { action [doAction] }";
const agent: Agent = { doAction: () => State.FAILED };
const agent = { doAction: () => State.FAILED };
const tree = new BehaviourTree(definition, agent);

let node = findNode(tree, "action", "doAction");
Expand Down Expand Up @@ -106,7 +106,7 @@ describe("An Action node", () => {
const result: Promise<State.SUCCEEDED> = new Promise((resolve) => resolve(State.SUCCEEDED));

const definition = "root { action [doAction] }";
const agent: Agent = { doAction: () => result };
const agent = { doAction: () => result };
const tree = new BehaviourTree(definition, agent);

let node = findNode(tree, "action", "doAction");
Expand Down

0 comments on commit 0b9581c

Please sign in to comment.