goap sample
This commit is contained in:
Vendored
+11
@@ -262,6 +262,17 @@ declare module es {
|
|||||||
findActionIndex(action: Action): number;
|
findActionIndex(action: Action): number;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
declare module es {
|
||||||
|
abstract class Agent {
|
||||||
|
actions: Action[];
|
||||||
|
_planner: ActionPlanner;
|
||||||
|
constructor();
|
||||||
|
plan(debugPlan?: boolean): boolean;
|
||||||
|
hasActionPlan(): boolean;
|
||||||
|
abstract getWorldState(): WorldState;
|
||||||
|
abstract getGoalState(): WorldState;
|
||||||
|
}
|
||||||
|
}
|
||||||
declare module es {
|
declare module es {
|
||||||
class WorldState implements IEquatable<WorldState> {
|
class WorldState implements IEquatable<WorldState> {
|
||||||
values: number;
|
values: number;
|
||||||
|
|||||||
@@ -1289,6 +1289,36 @@ var es;
|
|||||||
es.ActionPlanner = ActionPlanner;
|
es.ActionPlanner = ActionPlanner;
|
||||||
})(es || (es = {}));
|
})(es || (es = {}));
|
||||||
var es;
|
var es;
|
||||||
|
(function (es) {
|
||||||
|
var Agent = (function () {
|
||||||
|
function Agent() {
|
||||||
|
this._planner = new es.ActionPlanner();
|
||||||
|
}
|
||||||
|
Agent.prototype.plan = function (debugPlan) {
|
||||||
|
if (debugPlan === void 0) { debugPlan = false; }
|
||||||
|
var nodes = null;
|
||||||
|
if (debugPlan)
|
||||||
|
nodes = [];
|
||||||
|
this.actions = this._planner.plan(this.getWorldState(), this.getGoalState(), nodes);
|
||||||
|
if (nodes != null && nodes.length > 0) {
|
||||||
|
console.log("---- ActionPlanner plan ----");
|
||||||
|
console.log("plan cost = " + nodes[nodes.length - 1].costSoFar);
|
||||||
|
console.log(" start" + "\t" + this.getWorldState().describe(this._planner));
|
||||||
|
for (var i = 0; i < nodes.length; i++) {
|
||||||
|
console.log(i + ": " + nodes[i].action.name + "\t" + nodes[i].worldState.describe(this._planner));
|
||||||
|
es.Pool.free(nodes[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this.hasActionPlan();
|
||||||
|
};
|
||||||
|
Agent.prototype.hasActionPlan = function () {
|
||||||
|
return this.actions != null && this.actions.length > 0;
|
||||||
|
};
|
||||||
|
return Agent;
|
||||||
|
}());
|
||||||
|
es.Agent = Agent;
|
||||||
|
})(es || (es = {}));
|
||||||
|
var es;
|
||||||
(function (es) {
|
(function (es) {
|
||||||
var WorldState = (function () {
|
var WorldState = (function () {
|
||||||
function WorldState(planner, values, dontcare) {
|
function WorldState(planner, values, dontcare) {
|
||||||
|
|||||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
+4
-2
@@ -17,7 +17,7 @@
|
|||||||
"bin-debug/SampleHelpers/SampleScene.js",
|
"bin-debug/SampleHelpers/SampleScene.js",
|
||||||
"bin-debug/Scenes/NinjaAdventure/ProjectileHitDetector.js",
|
"bin-debug/Scenes/NinjaAdventure/ProjectileHitDetector.js",
|
||||||
"bin-debug/UI/loading/LoadingView.js",
|
"bin-debug/UI/loading/LoadingView.js",
|
||||||
"bin-debug/Scenes/NinjaAdventure/CameraBounds.js",
|
"bin-debug/Scenes/LineCasting/LineCastingScene.js",
|
||||||
"bin-debug/Fgui/loading/loadingBinder.js",
|
"bin-debug/Fgui/loading/loadingBinder.js",
|
||||||
"bin-debug/Fgui/loading/UI_View_loading.js",
|
"bin-debug/Fgui/loading/UI_View_loading.js",
|
||||||
"bin-debug/Fgui/sc/scBinder.js",
|
"bin-debug/Fgui/sc/scBinder.js",
|
||||||
@@ -27,9 +27,11 @@
|
|||||||
"bin-debug/Platform.js",
|
"bin-debug/Platform.js",
|
||||||
"bin-debug/Scenes/AnimatedTiles/AnimatedTilesScene.js",
|
"bin-debug/Scenes/AnimatedTiles/AnimatedTilesScene.js",
|
||||||
"bin-debug/Scenes/EmptyScene/BasicScene.js",
|
"bin-debug/Scenes/EmptyScene/BasicScene.js",
|
||||||
|
"bin-debug/Scenes/GOAP/GoapScene.js",
|
||||||
|
"bin-debug/Scenes/GOAP/QuickAgent.js",
|
||||||
"bin-debug/Scenes/LineCasting/LineCaster.js",
|
"bin-debug/Scenes/LineCasting/LineCaster.js",
|
||||||
"bin-debug/Scenes/LineCasting/LineCastingScene.js",
|
|
||||||
"bin-debug/Main.js",
|
"bin-debug/Main.js",
|
||||||
|
"bin-debug/Scenes/NinjaAdventure/CameraBounds.js",
|
||||||
"bin-debug/Scenes/NinjaAdventure/FireballProjectileController.js",
|
"bin-debug/Scenes/NinjaAdventure/FireballProjectileController.js",
|
||||||
"bin-debug/Scenes/NinjaAdventure/Ninja.js",
|
"bin-debug/Scenes/NinjaAdventure/Ninja.js",
|
||||||
"bin-debug/Scenes/NinjaAdventure/NinjaAdventureScene.js",
|
"bin-debug/Scenes/NinjaAdventure/NinjaAdventureScene.js",
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
module samples {
|
||||||
|
export class GoapScene extends SampleScene {
|
||||||
|
public initialize(): void {
|
||||||
|
super.initialize();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
module samples {
|
||||||
|
export class QuickAgent extends es.Agent {
|
||||||
|
private planner: es.ActionPlanner;
|
||||||
|
constructor(){
|
||||||
|
super();
|
||||||
|
this.planner = new es.ActionPlanner();
|
||||||
|
|
||||||
|
let action = new es.Action("scout");
|
||||||
|
action.setPrecondition("armedwithgun", true);
|
||||||
|
action.setPostcondition("enemyvisible", true);
|
||||||
|
this.planner.addAction(action);
|
||||||
|
}
|
||||||
|
|
||||||
|
public getWorldState(): es.WorldState {
|
||||||
|
let state = es.WorldState.create(this.planner);
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
public getGoalState(): es.WorldState {
|
||||||
|
return es.WorldState.create(this.planner);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@ module sc {
|
|||||||
new SceneData("Tiled Tiles", samples.AnimatedTilesScene),
|
new SceneData("Tiled Tiles", samples.AnimatedTilesScene),
|
||||||
new SceneData("Linecasting", samples.LineCastingScene),
|
new SceneData("Linecasting", samples.LineCastingScene),
|
||||||
new SceneData("Ninja Adventure", samples.NinjaAdventureScene),
|
new SceneData("Ninja Adventure", samples.NinjaAdventureScene),
|
||||||
|
new SceneData("GOAP", samples.GoapScene),
|
||||||
];
|
];
|
||||||
|
|
||||||
private _transitionList: TransitionData[] = [
|
private _transitionList: TransitionData[] = [
|
||||||
|
|||||||
Reference in New Issue
Block a user