Skip to content

Instantly share code, notes, and snippets.

@dchaplinsky
Last active January 2, 2016 07:39
Show Gist options
  • Select an option

  • Save dchaplinsky/8271714 to your computer and use it in GitHub Desktop.

Select an option

Save dchaplinsky/8271714 to your computer and use it in GitHub Desktop.
/*
* Do it.
*
*/
var current_direction = "top";
var alongside = "";
var flip = {
"top": "bottom",
"bottom": "top",
"left": "right",
"right": "left",
};
var order = {
"bottom": "left",
"left": "top",
"top": "right",
"right": "bottom"
};
walls = {
"left": false,
"right": false,
"top": false,
"bottom": false
}
var stop = function(self) {
self.thrusters.top(false);
self.thrusters.left(false);
self.thrusters.bottom(false);
self.thrusters.right(false);
}
this.on("all", function(){
var args = [].slice.call(arguments, 0),
match = args[0].match(/sensor\:(.+)$/);
if (match && match[1]) {
walls[match[1]] = args[1];
console.log(JSON.stringify(walls));
if (walls[current_direction]) {
alongside_wall = current_direction;
current_direction = order[current_direction]
} else if (!walls[alongside_wall]) {
current_direction = alongside_wall;
alongside_wall = flip[order[alongside_wall]];
}
stop(this);
console.log(alongside_wall);
this.thrusters[flip[current_direction]](true);
}
});
this.on("start", function() {
stop(this);
this.thrusters[flip[current_direction]](true);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment