Skip to content

Instantly share code, notes, and snippets.

@dudadornelles
Created December 5, 2012 19:28
Show Gist options
  • Save dudadornelles/4218733 to your computer and use it in GitHub Desktop.
Save dudadornelles/4218733 to your computer and use it in GitHub Desktop.
Fritz
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot) {
};
function randomMove(robot) {
var move = (Math.random()*10).toFixed() > 5 ?
"ahead" : "back";
robot.turn(90);
robot[move](100);
}
function shot(robot) {
robot.fire();
move = i % 1 == 0 ? "ahead" : "back";
robot[move](30);
robot.rotateCanon(30);
robot.rotateCanon(-30);
}
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
if (robot.availableClones > 0)
robot.clone();
while(true)
robot.rotateCannon(360);
};
Robot.prototype.onScannedRobot = function(ev) {
var robot = ev.robot;
if (robot.parentId == null) {
if (ev.scannedRobot.parentId != robot.id) {
shot(robot);
randomMove(robot);
}
} else {
if (robot.parentId != ev.scannedRobot.id) {
shot(robot);
randomMove(robot);
}
}
};
Robot.prototype.onWallCollision = function (ev) {
ev.robot.turn(180);
ev.robot.ahead(100);
}
@juanibiapina
Copy link

I'm so gonna kill you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment