Skip to content

Instantly share code, notes, and snippets.

@maligree
Created December 4, 2012 18:32
Show Gist options
  • Select an option

  • Save maligree/4207246 to your computer and use it in GitHub Desktop.

Select an option

Save maligree/4207246 to your computer and use it in GitHub Desktop.
MALLORY
//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.turn(90);
robot.ahead(140);
} else {
robot.ahead(35);
}
robot.turn(35);
robot.rotateCannon(360);
};
Robot.prototype.onScannedRobot = function(ev) {
var robot = ev.robot;
if (ev.scannedRobot.id != robot.parentId) {
robot.stop();
robot.fire();
}
};
Robot.prototype.onWallCollision = function(ev) {
var robot = ev.robot;
robot.back(50);
robot.turn(100);
robot.ahead(20);
}
Robot.prototype.onHitByBullet = function(ev) {
var robot = ev.robot;
if (robot.life < 70) {
robot.clone();
}
if (Math.random() >= 0.5) {
robot.turn(30);
} else {
robot.turn(-30);
}
if (Math.random() >= 0.5) {
robot.ahead(50);
} else {
robot.back(50);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment