Skip to content

Instantly share code, notes, and snippets.

@rafb43
Created December 8, 2012 03:57
Show Gist options
  • Select an option

  • Save rafb43/4238525 to your computer and use it in GitHub Desktop.

Select an option

Save rafb43/4238525 to your computer and use it in GitHub Desktop.
SimpleBeatch
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot) {
};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
robot.ahead(100);
robot.turn(20);
};
Robot.prototype.onScannedRobot = function(ev) {
var robot = ev.robot;
};
Robot.prototype.onRobotCollision = function(ev) {
console.log("robot collision on ", ev.bearing);
ev.robot.stop();
turnAgainst(ev.robot, ev.bearing);
};
Robot.prototype.onWallCollision = function(ev) {
console.log("wall collision on ", ev.bearing);
ev.robot.stop();
turnAgainst(ev.robot, ev.bearing);
};
function turnAgainst(robot, bearing) {
var angle;
if (bearing == 0) angle = 45;
if (bearing < 0) angle = bearing * -1;
else angle = (bearing / 5) * -1;
robot.turn(angle);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment