Created
December 3, 2012 16:45
-
-
Save druttka/4196205 to your computer and use it in GitHub Desktop.
CodeFist
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 target = null; | |
var intelAge = 0; | |
function log1(value, caption) | |
{ | |
if(caption) | |
console.log(caption + ": " + JSON.stringify(value)); | |
else | |
console.log(JSON.stringify(value)); | |
return value; | |
} | |
function log(){} | |
var pointAt = function(robot, enemy) | |
{ | |
var my = robot.position; | |
var opp = my.y - enemy.y; | |
var adj = my.x - enemy.x; | |
var angle = Math.atan2(opp, adj) * 180 / Math.PI; | |
if(angle < 0) angle += 360; | |
var myAngle = robot.cannonAbsoluteAngle; | |
var diff = angle - myAngle; | |
if(diff > 180) diff -= 360; | |
if(diff < -180) diff += 360; | |
robot.rotateCannon(diff); | |
} | |
Robot.prototype.onIdle = function(ev) { | |
var robot = ev.robot; | |
intelAge += 1; | |
if(intelAge > 3) | |
{ | |
target = null; | |
} | |
if(!target) | |
{ | |
robot.rotateCannon(-30); | |
} | |
else | |
{ | |
pointAt(ev.robot, target); | |
robot.fire(); | |
robot.fire(); | |
robot.fire(); | |
} | |
robot.turn(-13); | |
robot.ahead(23); | |
}; | |
Robot.prototype.onScannedRobot = function(ev) { | |
target = ev.scannedRobot.position; | |
intelAge = 0; | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment