Skip to content

Instantly share code, notes, and snippets.

View mrunderhill89's full-sized avatar

Kevin Cameron mrunderhill89

  • Santa Cruz, California
View GitHub Profile
@mrunderhill89
mrunderhill89 / recursive_goap.lua
Last active September 5, 2016 23:59
Goal-oriented Action Planning is an AI technique used to let computer-controlled actors make realistic decisions when placed in a specific environment.
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
@mrunderhill89
mrunderhill89 / associations.js
Created March 13, 2015 06:58
Simple auto-updating connectors between two objects. Compatible with mixin.js and interface.js
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){
@mrunderhill89
mrunderhill89 / mixin.js
Created March 10, 2015 00:50
An implementation of mixin to go along with my Interface class.
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"
},
@mrunderhill89
mrunderhill89 / interface.js
Created March 10, 2015 00:49
Yet another implementation of an interface in Javascript.
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.
@mrunderhill89
mrunderhill89 / bacon_parallel.js
Last active August 29, 2015 14:16
A simple experiment in parallelizing Bacon.js using Parallel.js. I haven't thoroughly debugged it yet, but it works most of the time.
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.
@mrunderhill89
mrunderhill89 / BehaviorTree.lua
Created April 18, 2014 17:13
Behavior Tree implementation in Lua.
--[[
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"