// High-level AI: ------------------------------------------------------------------------------------- // /* - Character AI is implemented as a very simple rule-based system. There are 3 memory containers, containing WMEs (Working Memory Elements): - perceptions (change at every frame) - short-term memory (WMEs here have a timer that decays, when reached 0, they are forgotten) - long-term memory (WMEs here are remembered forever) - When a WME has been in short-term memory or perception for a long time, it goes to long-term - Each character defines a set of rules and initial memory elements, which determine its behavior. */ HighLevelAI.prototype = new Behavior(); function HighLevelAI() { this.freezeThreshold = 50*60; // activation needed to freeze into long-term memory (50*60 is one minute worth of activation) this.shortTermMemory = []; this.longTermMemory = []; this.rules = []; this.actions = []; this.lastTimeExecuted = 0; this.generateSaveData = function(objects, data) { // behaviors: data.rules = []; for(var i = 0;i=this.freezeThreshold) toFreeze.push(wme); } for(var i = 0;i highestPriority) { highestPriorityAction = tmp.action; highestPriority = tmp.priority; // console.log("Highest priority action: " + highestPriorityAction); } } // clean-up: this.actions = []; return highestPriorityAction; } this.getWME = function(type) { var bestwme = null; var bestActivation = 0; for(var i = 0;ibestActivation) { bestwme = wme; bestActivation = wme.activation; } } } for(var i = 0;ibestActivation) { bestwme = wme; bestActivation = wme.activation; } } } return bestwme; } this.getWME2 = function(type,param) { var bestwme = null; var bestActivation = 0; for(var i = 0;ibestActivation) { bestwme = wme; bestActivation = wme.activation; } } } for(var i = 0;ibestActivation) { bestwme = wme; bestActivation = wme.activation; } } } return bestwme; } this.getAllWMEs = function(type) { var wmes = []; for(var i = 0;i