Skip to content

Instantly share code, notes, and snippets.

@juniorz
Created December 5, 2012 16:35
Show Gist options
  • Save juniorz/4217204 to your computer and use it in GitHub Desktop.
Save juniorz/4217204 to your computer and use it in GitHub Desktop.
Kingnaldo
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot) {
robot.clone();
if(robot.parentId){
robot.turn(90);
robot.ahead(50);
}
};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
if(robot.parentId){
robot.turn(5);
robot.rotateCannon(5);
} else {
robot.turn(-9);
robot.rotateCannon(5);
}
robot.ahead(5);
robot.rotateCannon(5);
//robot.rotateCannon(90);
//robot.ahead(100);
if(robot.parentId){
robot.turn(-15);
} else {
robot.turn(15);
}
robot.rotateCannon(5);
};
Robot.prototype.onScannedRobot = function(ev) {
var robot = ev.robot;
var opponent = ev.scannedRobot;
var isFriend = (opponent.id == robot.parentId || opponent.parentId == robot.id);
console.log('isFriend', isFriend);
var attack = function(){
if (opponent.life > 0.6 * robot.life){
robot.ahead(1);
robot.turn(3);
}
robot.fire();
}
/*
{
robot: {
// Same as onIdle
},
scannedRobot: {
id, // Id from the robot
position: {
x, // X position from the other robot relative to the board
},
angle, // Angle from the other robot
cannonAngle, // Cannon angle relative to the other robot
life, // Percentage of life from the other robot
parentId // If this is a clone, the clone's parent id.
// null otherwise
}
}
*/
//Am I a clone?
if(robot.parentId){
if(isFriend){
robot.turn(5);
robot.ahead(30);
} else {
attack()
}
} else {
if( isFriend ){
robot.turn(15);
robot.ahead(10);
} else {
attack();
}
}
};
Robot.prototype.onHitByBullet = function(ev) {
var robot = ev.robot;
robot.turn(5);
robot.ahead(80);
robot.turn(ev.bearing);
robot.fire();
};
Robot.prototype.onRobotCollision = function(ev) {
var robot = ev.robot;
robot.turn(20);
robot.ahead(100); // trying to run away
};
Robot.prototype.onWallCollision = function(ev) {
var robot = ev.robot;
robot.turn(ev.bearing); // turn enought to be in a straight
// angle with the wall.
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment