Skip to content

Instantly share code, notes, and snippets.

@meal
Created December 4, 2012 14:49
Show Gist options
  • Save meal/4204711 to your computer and use it in GitHub Desktop.
Save meal/4204711 to your computer and use it in GitHub Desktop.
notb
//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