Skip to content

Instantly share code, notes, and snippets.

@dchaplinsky
Created January 5, 2014 16:59
Show Gist options
  • Select an option

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

Select an option

Save dchaplinsky/8270732 to your computer and use it in GitHub Desktop.
guess what
/*
* Open all three doors to exit.
*
* The answer is 5.
*/
var stop = function(self) {
self.thrusters.top(false);
self.thrusters.left(false);
self.thrusters.bottom(false);
self.thrusters.right(false);
}
this.on("start", function() {
this.thrusters.left(true);
this.radar.angle(0);
this.radar.ping();
});
this.on("radar:hit", function(angle, distance) {
console.log(distance);
if (angle == 0) {
if (Math.abs(distance - 370) < 10) {
stop(this);
this.thrusters.bottom(true);
} else if (Math.abs(distance - 170) < 10) {
stop(this);
this.thrusters.top(true);
this.radar.angle(90);
this.radar.ping();
} else {
this.radar.ping();
}
} else if (angle == 90) {
if (Math.abs(distance - 270) < 10) {
this.thrusters.right(true);
} else {
this.radar.ping();
}
}
});
this.on("sensor:top", function(foo) {
if (foo) {
stop(this);
this.thrusters.left(true);
} else {
this.radar.ping();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment