This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function plan_action(model, depth, action_index, best_action, best_value) | |
assert(type(model) == "table", "Model must be a table. Got "..type(model).." instead.") | |
depth = type(depth) == "number" and depth or 1 | |
action_index = type(action_index) == "number" and action_index or 1 | |
--best_action doesn't need to be initialized; nil is a valid result. | |
best_value = type(best_value) == "number" and best_value or model:evaluate() | |
if depth > 0 then | |
local next_action = model:get_action(action_index) | |
if next_action then | |
-- The only part that isn't tail-recursive, and at least we're |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define(['underscore', 'bacon_extra', 'interface', 'mixin'], | |
function(_, Bacon, Interface, Mixin){ | |
var i_Association = new Interface({ | |
methods:["reflect", "get_data"] | |
}); | |
var One = Mixin.implement({ | |
interface: i_Association, | |
default_mixins: ["get_data", "set_data"], | |
initialize: function(params){ | |
this.set_data = Bacon.fromClosure(function(data){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define(['underscore', 'interface'], function(_, Interface){ | |
mixin_interface = new Interface({ | |
proto_methods:["mix"], | |
static_methods:["proto_mix"] | |
}); | |
var Mixin = mixin_interface.implement({ | |
fields:{ | |
default_mixins:[], | |
default_property:"mixin" | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define(['underscore'], function(_){ | |
var Interface = function () | |
{ | |
this.initialize.apply(this,arguments); | |
} | |
var default_methods = { | |
/* | |
Throws an exception if this object doesn't fit the given interface. | |
Otherwise, returns the object itself, which (unlike is_a) lets you chain | |
multiple checks together. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Bacon = require("baconjs").Bacon; | |
var Parallel = require('paralleljs'); | |
var _ = require("underscore")._; | |
_.extend(Bacon.Observable.prototype, { | |
/* | |
Gathers events in a buffer for parallel processing. | |
Obviously, this needs to be done before any parallel operations are performed. | |
- length: the maximum number of entries collected before dumping. Set <= 0 for no limit. | |
- timeOut: will dump events after this many milliseconds, regardless of how many were collected. Set <= 0 for no limit. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--[[ | |
This behavior tree code was taken from our Zelda AI project for CMPS 148 at UCSC. | |
It is for the most part unmodified, and comments are available for each function. | |
Author: Kevin Cameron (mrunderhill89) | |
]]-- | |
BT = {} | |
BT.__index = BT | |
BT.results = {success = "success" | |
,fail = "fail" |