Skip to content

Instantly share code, notes, and snippets.

@jpospychala
Created December 6, 2012 09:29
Show Gist options
  • Save jpospychala/4223229 to your computer and use it in GitHub Desktop.
Save jpospychala/4223229 to your computer and use it in GitHub Desktop.
myrobot
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot) {
this.sgn = 1;
this.count = 0;
};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
robot.ahead(10);
robot.rotateCannon(-10);
//robot.back(100);
//robot.rotateCannon(360);
};
Robot.prototype.onScannedRobot = function(ev) {
var robot = ev.robot;
robot.fire();
robot.rotateCannon(robot.sgn*-10);
robot.turn(robot.sgn*10);
robot.count = (robot.count + 1) % 2;
if (robot.count == 0) {
robot.sgn *= -1;
}
};
Robot.prototype.onWallCollision = function(ev) {
var r = ev.robot;
r.rotateCannon(-30);
r.turn(30);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment