Skip to content

Instantly share code, notes, and snippets.

@djcornell

djcornell/robot.js

Created Dec 8, 2012
Embed
What would you like to do?
BoogerBot
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot) {
};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
if (robot.availableClones > 0) {
robot.clone();
}
robot.ahead(30);
robot.rotateCannon(45);
};
Robot.prototype.onScannedRobot = function(ev) {
var robot = ev.robot;
if (ev.scannedRobot.parentId == robot.id) {
robot.log("not shooting clone: me: " + robot.id + " him: " + ev.scannedRobot.id);
return;
}
if (ev.scannedRobot.id == robot.parentId) {
robot.log("not shooting clone: me: " + robot.id + " him: " + ev.scannedRobot.id);
return;
}
robot.log("me: " + robot.id + " him: " + ev.scannedRobot.parentId);
robot.fire();
robot.rotateCannon(-25);
robot.back(4);
};
Robot.prototype.onWallCollision = function(ev) {
var robot = ev.robot;
robot.back(20);
robot.turn(ev.bearing - 90);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment