Created
December 4, 2012 14:49
-
-
Save meal/4204711 to your computer and use it in GitHub Desktop.
notb
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 friends = {}, id; | |
var Robot = function(robot) { | |
id = robot.id; | |
// friends is the set all friendly robots | |
friends[id] = id; | |
clone = robot.clone(); | |
}; | |
Robot.prototype.onIdle = function(ev) { | |
var robot = ev.robot; | |
if (robot.parentId == id) friends[robot.id] = robot.id; | |
robot.turn(60); | |
robot.ahead(50); | |
robot.turn(180); | |
}; | |
Robot.prototype.onScannedRobot = function(ev) { | |
var robot = ev.robot; | |
robot.stop(); | |
robot.rotateCannon(3); | |
// if not friendly | |
if (!(ev.scannedRobot.id in friends)) { | |
robot.fire(); | |
robot.log(robot); | |
robot.ahead(100); | |
robot.turn(22); | |
robot.turn(-25); | |
} | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment