Created
December 5, 2012 19:28
-
-
Save dudadornelles/4218733 to your computer and use it in GitHub Desktop.
Fritz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm so gonna kill you.