Skip to content

Instantly share code, notes, and snippets.

@unkn0w
Created December 5, 2012 07:05
Show Gist options
  • Save unkn0w/4213287 to your computer and use it in GitHub Desktop.
Save unkn0w/4213287 to your computer and use it in GitHub Desktop.
imlmpe
//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(1);
robot.turnGunRight(1);
};
Robot.prototype.onWallCollision = function(ev) {
var robot = ev.robot;
if(!robot.parentId) {
robot.turnRight(ev.bearing - 90);
}
else {
robot.turnRight(ev.bearing + 90);
}
};
Robot.prototype.onScannedRobot = function(ev) {
var robot = ev.robot, scannedRobot = ev.scannedRobot;
if (robot.id == scannedRobot.parentId || robot.parentId == scannedRobot.id) {
return;
}
robot.clone();
robot.fire();
//robot.turn(90);
//robot.ahead(10);
//robot.turn(-90);
robot.turnGunLeft(30);
};
Robot.prototype.onRobotCollision = function(ev) {
var robot = ev.robot, collidedRobot = ev.collidedRobot;
robot.ignore('onRobotCollision')
if (ev.bearing > -90 && ev.bearing < 90) {
robot.back(100);
}
else {
robot.ahead(100);
}
if (robot.id != collidedRobot.parentId && robot.parentId != collidedRobot.id) {
robot.turnGunRight(ev.bearing - robot.cannonRelativeAngle);
robot.turnGunLeft(ev.bearing - robot.cannonRelativeAngle);
}
robot.listen('onRobotCollision')
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment