Skip to content

Instantly share code, notes, and snippets.

@markusrt
Created December 5, 2012 22:37
Show Gist options
  • Save markusrt/4220139 to your computer and use it in GitHub Desktop.
Save markusrt/4220139 to your computer and use it in GitHub Desktop.
TOBOR I
//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;
robot.ahead(10);
robot.rotateCannon(10);
};
Robot.prototype.onScannedRobot = function(ev) {
var robot = ev.robot;
robot.fire();
for (var i=1; i<3; i++) {
robot.rotateCannon(-i*2);
robot.fire();
robot.rotateCannon(i*2);
robot.fire();
}
robot.rotateCannon(20);
robot.rotateCannon(-20);
};
Robot.prototype.onWallCollision = function(ev) {
var robot = ev.robot;
robot.turn(ev.bearing + 120);
robot.rotateCannon(robot.cannonRelativeAngle);
};
Robot.prototype.onRobotCollision = function(ev) {
var robot = ev.robot;
var collided = ev.collidedRobot;
robot.rotateCannon((90 - robot.cannonRelativeAngle) + collided.cannonAngle);
};
Robot.prototype.onHitByBullet = function(ev) {
var robot = ev.robot;
robot.turn(37)
robot.ahead(100);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment