Created
December 4, 2012 21:32
-
-
Save Tzrlk/4208939 to your computer and use it in GitHub Desktop.
Reaver
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
var robots = { | |
mine: {}, | |
theirs: {} | |
}; | |
var routines = { | |
searching: function(robot) { | |
robot.turn(1); | |
robot.rotateCannon(1); | |
}, | |
hunting: function(robot) { | |
robot.clone(); | |
routines.hunting = routines.afterClone; | |
}, | |
afterClone: function(robot) { | |
robot.back(1); | |
} | |
}; | |
var onIdle = routines.searching; | |
// Determines whether a sighted bot is | |
// an enemy to be tracked and shot at. | |
function isEnemy(robot) { | |
if (robots.mine[robot.id]) { | |
return false; | |
} | |
if (robots.mine[robot.parentId]) { | |
robots.mine[robot.id] = robot; | |
return false; | |
} | |
robots.theirs[robot.id] = robot; | |
return true; | |
} | |
function onRobotCollision(robot, bearing, collidedRobot, myFault) { | |
var otherbot = determineBot(collidedRobot); | |
if (otherbot.indexOf('enemy') >= 0) { | |
robot.fire(); | |
} | |
} | |
function onWallCollision(robot, bearing) { | |
// | |
} | |
function onScannedRobot(robot, scannedRobot) { | |
if (isEnemy(scannedRobot)) { | |
onIdle = routines.hunting; | |
} | |
} | |
function onHitByBullet(robot, bulletBearing) { | |
robot.turn(bulletBearing); | |
} | |
//FightCode can only understand your robot | |
//if its class is called Robot | |
function Robot(robot) { | |
robots.mine[robot.id] = robot; | |
}; | |
Robot.prototype.onIdle = function(ev) { | |
onIdle(ev.robot); | |
}; | |
// this method gets called whenever we hit another robot... | |
Robot.prototype.onRobotCollision = function(ev) { | |
onRobotCollision(ev.robot, ev.bearing, ev.collidedRobot, ev.myFault); | |
}; | |
// this method gets called whenever we hit a wall... | |
Robot.prototype.onWallCollision = function(ev) { | |
onWallCollision(ev.robot, ev.bearing); | |
}; | |
Robot.prototype.onScannedRobot = function(ev) { | |
onScannedRobot(ev.robot, ev.scannedRobot); | |
}; | |
// ohhh... we were hit by another robot... | |
Robot.prototype.onHitByBullet = function(ev) { | |
onHitByBullet(ev.robot, ev.bulletBearing); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment