Skip to content

Instantly share code, notes, and snippets.

@dos1
Created December 4, 2012 21:40
Show Gist options
  • Save dos1/4209024 to your computer and use it in GitHub Desktop.
Save dos1/4209024 to your computer and use it in GitHub Desktop.
dos
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot) {
};
robots = {}
angles = {}
wyczajony = {}
timeout = {}
cloned=false;
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
if (cloned==false) {
cloned=true;
robot.clone();
robot.turn(56);
}
//{ robots[robot.id]++; robot.fire();
// if (robots[robot.id]==30) {robots[robot.id]=0}}
// else {
if (wyczajony[robot.id]) {
if (wyczajony[robot.id]<0) robot.rotateCannon(-1); else robot.rotateCannon(1);
if (wyczajony[robot.id]==-1) wyczajony[robot.id]=20;
if (wyczajony[robot.id]==1) wyczajony[robot.id]=-20;
if (wyczajony[robot.id]<0) wyczajony[robot.id]++; else wyczajony[robot.id]--;
//robot.rotateCannon(-1); else robot.rotateCannon(1);
if (robots[robot.id]==0) { robot.fire(); }
} else {
robot.rotateCannon(1);
}
if (timeout[robot.id]) {
timeout[robot.id]--;
if (timeout[robot.id]==0) {
wyczajony[robot.id] = 0;
robots[robot.id]=2;
}
}
if (angles[robot.id]>0) {
robot.turn(5);
robot.rotateCannon(-5);
angles[robot.id]-=5;
} else robot.ahead(3);
if (angles[robot.id]<0) {
// robots[robot.id]=2;
// wyczajony[robot.id]=0;
angles[robot.id]=0;
}
// }
robots[robot.id]=0;
// robot.fire();
};
Robot.prototype.onWallCollision = function(ev) {
var robot = ev.robot;
robot.a = !robot.a;
// robot.turn(ev.bearing+180);
robot.clone();
angles[robot.id]=ev.bearing+180;
}
Robot.prototype.onRobotCollision = function(ev) {
var robot = ev.robot;
// robot.turn(45);
angles[robot.id]=45;
}
Robot.prototype.onScannedRobot = function(ev) {
var robot = ev.robot;
robots[robot.id]=0;
if ((robot.id == ev.scannedRobot.parentId) || (robot.parentId == ev.scannedRobot.id)) robots[robot.id]=1; else {
timeout[robot.id]=100;
wyczajony[robot.id]=20; }
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment