Created
December 7, 2012 23:16
-
-
Save juniorz/4237426 to your computer and use it in GitHub Desktop.
Jaba
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
//FightCode can only understand your robot | |
//if its class is called Robot | |
var Robot = function(robot) { | |
var count = 0; | |
var width = 13; // 13px | |
}; | |
Robot.prototype.turnTo = function(robot, degree) { | |
if(robot.angle != degree){ | |
robot.turn(degree - robot.angle) | |
} | |
} | |
Robot.prototype.turnUp = function(robot) { | |
this.turnTo(robot, 0); | |
} | |
Robot.prototype.turnDown = function(robot) { | |
this.turnTo(robot, 180); | |
} | |
Robot.prototype.turnRight = function(robot) { | |
this.turnTo(robot, 90); | |
} | |
Robot.prototype.turnLeft = function(robot) { | |
this.turnTo(robot, 270); | |
} | |
Robot.prototype.onIdle = function(ev) { | |
var robot = ev.robot; | |
var right = robot.arenaWidth - robot.position.x - 13; | |
var left = robot.position.x; | |
//this.turnRight(robot); | |
//robot.ahead(10); | |
//this.turnDown(robot); | |
if( right > 100 && robot.angle != 270 ){ | |
console.log('angle before TR', robot.angle); | |
this.turnRight(robot); | |
console.log('angle after TR', robot.angle); | |
robot.ahead(1); | |
} else { | |
console.log('angle before TL', robot.angle); | |
//this.turnLeft(robot); | |
//robot.ahead(1); | |
console.log('angle after TL', robot.angle); | |
} | |
//if(Math.random() * 100 > 40){ | |
//console.log('pos', left, right); | |
//} | |
//this.turnUp(robot); | |
//robot.ahead(1); | |
//this.turnRight(robot); | |
//robot.ahead(1); | |
//this.turnDown(robot); | |
//robot.ahead(10); | |
// robot.ahead(1); | |
//robot.rotateCannon(1); | |
//robot.turn(1); | |
//robot.back(1); | |
//robot.rotateCannon(360); | |
}; | |
Robot.prototype.onScannedRobot = function(ev) { | |
var robot = ev.robot; | |
var opponent = ev.scannedRobot; | |
//robot.fire(); | |
// console.log('width', robot.arenaWidth);// | |
// console.log('left', robot.position.x); | |
// console.log('right', robot.arenaWidth - robot.position.x - 13); | |
//console.log(robot.angle, opponent.angle); | |
//console.log('count', this.count); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment