Skip to content

Instantly share code, notes, and snippets.

@emgiezet
Created December 4, 2012 10:04
Show Gist options
  • Save emgiezet/4202357 to your computer and use it in GitHub Desktop.
Save emgiezet/4202357 to your computer and use it in GitHub Desktop.
DumbCracker
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot) {
robot.clone();
robot.turn(45);
this.offset = 1;
};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
robot.ahead(10);
robot.turn(5);
robot.rotateCannon(10);
};
Robot.prototype.onScannedRobot = function(ev) {
var robot = ev.robot;
var scanned =ev.scannedRobot;
if (robot.id == scanned.parentId || robot.parentId == scanned.id) {
return;
}
robot.stop();
for (var i=0; i<10; i++) {
robot.fire();
robot.ahead(3);
}
};
Robot.prototype.onHitByBullet = function(ev) {
var robot;
robot = ev.robot;
robot.rotateCannon(ev.bearing-robot.cannonRelativeAngle);
robot.back(35);
};
Robot.prototype.onRobotCollision = function(ev) {
var robot = ev.robot;
var collidedRobot = ev.collidedRobot;
if (robot.id == collidedRobot.parentId || robot.parentId == collidedRobot.id) {
if(collidedRobot.myFault)
{
robot.stop();
this.offset = -1 * this.offset;
robot.back(40*this.offset);
robot.turn(-45);
} else {
robot.stop();
robot.back(40);
robot.turn(45);
}
}else{
robot.stop();
robot.back(40);
for(var i; i<10; i++) {
robot.fire();
robot.rotateCannon(18);
robot.back(5);
}
}
robot.ahead(100); // trying to run away
};
Robot.prototype.onWallCollision = function(ev) {
var robot = ev.robot;
robot.stop();
robot.back(20);
robot.turn(ev.bearing);
robot.back(50);
robot.turn(90);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment