behaviortree
Version:
A JavaScript implementation of Behavior Trees. They are useful for implementing AIs. For Browsers and NodeJS.
28 lines (27 loc) • 1.02 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const constants_1 = require("./constants");
const Parallel_1 = __importDefault(require("./Parallel"));
/**
* The Parallel node runs all of its children in parallel and is running until the first children is
* returning a result and that result will be retuend. In a tie a FAILURE would win over a SUCCESS.
*/
class ParallelComplete extends Parallel_1.default {
constructor() {
super(...arguments);
this.nodeType = 'ParallelComplete';
}
calcResult(results) {
if (results.includes(constants_1.FAILURE)) {
return constants_1.FAILURE;
}
if (results.includes(constants_1.SUCCESS)) {
return constants_1.SUCCESS;
}
return { total: constants_1.RUNNING, state: results };
}
}
exports.default = ParallelComplete;