MY ROBOTS

ABSOLUTELY EVERYTHING ABOUT YOUR ARMY OF ROBOTS
  • none
    firstBot
    created 03/17/14 138 code lines fight
    1500 SCORE
    0 KILLS
    0 SHOTS
    0 HITS
    0.00%
    AVERAGE HITS/SHOT
    SCORE OVER TIME
  • # 332
    Lama
    created 03/17/14 50 code lines fight
    1522 SCORE
    6 KILLS
    171 SHOTS
    62 HITS
    36.05%
    AVERAGE HITS/SHOT
    SCORE OVER TIME
  • none
    testik
    created 03/17/14 152 code lines fight fork
    1500 SCORE
    0 KILLS
    0 SHOTS
    0 HITS
    0.00%
    AVERAGE HITS/SHOT
    SCORE OVER TIME
    var shotVel = 400; var tankVel = 200; var history = []; function quad(a, b, c) { var sol = null; if (Math.abs(a) < 1e-6) { if (Math.abs(b) < 1e-6) { sol = Math.abs(c) < 1e-6 ? [0, 0] : null; } else { sol = [-c / b, -c / b]; } } else { var disc = b * b - 4 * a * c; if (disc >= 0) { disc = Math.sqrt(disc); a = 2 * a; sol = [(-b - disc) / a, (-b + disc) / a]; } } return sol; } function intercept(src, dst, v) { var tx = dst.x - src.x, ty = dst.y - src.y, tvx = dst.vx, tvy = dst.vy; // Get quadratic equation components var a = tvx * tvx + tvy * tvy - v * v; var b = 2 * (tvx * tx + tvy * ty); var c = tx * tx + ty * ty; // Solve quadratic var ts = quad(a, b, c); // See quad(), below // Find smallest positive solution var sol = null; if (ts) { var t0 = ts[0], t1 = ts[1]; t = Math.min(t0, t1); if (t < 0) { t = Math.max(t0, t1); } if (t > 0) { sol = { left: dst.left + dst.vleft * t, top: dst.top + dst.vtop * t }; } } return sol; } function log(value, caption){ var jsonValue = JSON.stringify(value); var logString = caption ? caption + ": " + jsonValue : jsonValue; console.log(logString); } function aquire(){ var length = history.length; if(length < 3) { return; } var s0 = history[length - 3]; var s2 = history[length - 1]; var dx2 = s2.x - s0.x; var dy2 = s2.y - s0.y; var rads = Math.atan2(dy2, dx2); log(rads * 180 / Math.PI, "angle"); var vx = Math.cos(rads) * tankVel; var vy = Math.sin(rads) * tankVel; return { x: s2.x, y: s2.y, vx: vx, vy: vy }; } function aim(robot, point) { var my = robot.position; var opp = my.y - point.y; var adj = my.x - point.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); } //FightCode can only understand your robot //if its class is called Robot var Robot = function(robot) { //if(robot.angle > 180){ // robot.turn(360 - robot.angle); //} //else { // robot.turn(-robot.angle) //} //robot.rotateCannon(90); //robot.back(500); }; function findTarget(robot){ if(history.length>0){ aim(robot, history[history.length-1]); } robot.rotateCannon(-30); } Robot.prototype.onIdle = function(ev) { var robot = ev.robot; robot.ahead(30); robot.turn(15); findTarget(robot); }; Robot.prototype.onScannedRobot = function(ev) { ev.robot.stop(); if(ev.scannedRobot.parentId == null) { history.push(ev.scannedRobot.position); var dst = aquire(); log(dst, "dst"); if(dst){ var src = ev.robot.position; var intP = intercept(src, dst, shotVel); log(intP, "intP"); if(intP){ aim(ev.robot, intP); } } } ev.robot.fire(); };
  • none
    Walls 2.3
    created 03/17/14 48 code lines fight fork
    1500 SCORE
    0 KILLS
    0 SHOTS
    0 HITS
    0.00%
    AVERAGE HITS/SHOT
    SCORE OVER TIME
    var Robot = function(robot) {}; var moveAmount = 0; var doSetup = true; var cloneId = false; Robot.prototype.onIdle = function(ev) { var robot = ev.robot; if(cloneId === false && robot.parentId !== null) { cloneId = robot.id; doSetup = true; robot.turnRight(90); } if(doSetup) { robot.clone(); moveAmount = Math.max(robot.arenaWidth,robot.arenaHeight); robot.turnLeft(robot.angle % 90); robot.turnGunRight(90); doSetup = false; } robot.ahead(moveAmount); }; Robot.prototype.onRobotCollision = function(ev) { var robot = ev.robot; var target = ev.collidedRobot; if(target.id !== cloneId && target.id !== robot.parentId) { robot.back(15); robot.turnGunRight(-95); robot.turnGunRight(95); } }; //for fight code game, this way is better :) Robot.prototype.onWallCollision = function(ev) { ev.robot.turnRight(ev.bearing + 90); }; Robot.prototype.onHitByBullet = function(ev) { if(ev.robot.id !== cloneId) ev.robot.disappear(); }; Robot.prototype.onScannedRobot = function(ev) { var robot = ev.robot; var target = ev.scannedRobot; if(target.id !== cloneId && target.id !== robot.parentId) robot.fire(); };
  • none
    Zolmeister
    created 03/17/14 58 code lines fight
    1500 SCORE
    0 KILLS
    0 SHOTS
    0 HITS
    0.00%
    AVERAGE HITS/SHOT
    SCORE OVER TIME