Skip to content

Instantly share code, notes, and snippets.

@fmobus
Created December 6, 2012 11:49
Show Gist options
  • Save fmobus/4223908 to your computer and use it in GitHub Desktop.
Save fmobus/4223908 to your computer and use it in GitHub Desktop.
Le Rândom
var rand = function(upto) {
return Math.random() * upto
}
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot) {
this.enemy = {}
this.mode = 1
};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
robot.rotateCannon(this.mode * 15);
robot.ahead(this.mode * 2 + 20 * rand(2));
};
Robot.prototype.onHitByBullet = function(ev) {
var robot = ev.robot;
robot.ahead(20 * rand(2));
robot.turn(45 * rand(3));
robot.back(20 * rand(2));
this.mode *= -1
}
Robot.prototype.onWallCollision = function(ev) {
var robot = ev.robot;
robot.turn(ev.bearing)
robot.back(100);
}
Robot.prototype.onScannedRobot = function(ev) {
var robot = ev.robot;
robot.fire();
robot.fire();
robot.ahead(
40 + 30 * this.mode * rand(3)
)
var le_turn = 45 * this.mode * rand(2);
robot.turn(le_turn);
robot.rotateCannon(-le_turn);
if (this.mode == 1) {
robot.ahead(30);
robot.rotateCannon(-10);
}
else {
robot.back(30);
robot.rotateCannon(10);
}
this.mode *= -1;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment