Skip to content

Instantly share code, notes, and snippets.

@fontenele
Created December 7, 2012 10:38
Show Gist options
  • Save fontenele/4232409 to your computer and use it in GitHub Desktop.
Save fontenele/4232409 to your computer and use it in GitHub Desktop.
F1
// Random number from interval
function randomFromInterval(from,to) {
return Math.floor(Math.random()*(to-from+1)+from);
}
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot) {
this.i = randomFromInterval(500,1000);
};
// well, we need to do something...
// whenever our robot is idle, this method gets called.
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
var i = this.i;
robot.ahead(20);
robot.turn(40);
robot.back(30);
robot.turn(-80);
};
// yay we see another robot! time to wreak some havoc...
Robot.prototype.onScannedRobot = function(ev) {
var robot = ev.robot;
robot.fire();
};
// this method gets called whenever we hit a wall...
Robot.prototype.onWallCollision = function(ev) {
var robot = ev.robot;
robot.turn(ev.bearing + 100);
};
// this method gets called whenever we hit another robot...
Robot.prototype.onRobotCollision = function(ev) {
var robot = ev.robot;
robot.turn(20);
robot.ahead(100);
};
// ohhh... we were hit by another robot...
Robot.prototype.onHitByBullet = function(ev) {
var robot = ev.robot;
//robot.turn(90 - ev.bulletBearing);
robot.turn(ev.bearing);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment