Skip to content

Instantly share code, notes, and snippets.

@ografael
Created December 6, 2012 00:00
Show Gist options
  • Select an option

  • Save ografael/4220696 to your computer and use it in GitHub Desktop.

Select an option

Save ografael/4220696 to your computer and use it in GitHub Desktop.

Revisions

  1. Zolmeister revised this gist Dec 5, 2012. 1 changed file with 46 additions and 170 deletions.
    216 changes: 46 additions & 170 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -1,180 +1,56 @@
    //clone
    //search field efficiently for enemy (main, ignore any clones)
    //on found:
    //fire at them
    //clone moves 300 units away from bot
    //turn parallel to them
    //move forward/backward (if wall hit then switch)
    //continuously track enemy position
    //if lose position (not found within next firing position), go back to finding algo
    //calculate enemy trajectory
    //when can fire another round, fire using calculated trajectory

    //on hit other robot, rotate 90 deg, go forward 100, then search for enemy again
    //on hit wall, flip movement direction

    var Robot = function(robot) {
    robot.clone();
    this.robo = {
    moveDir : 1,
    tracking : false,
    ticker : 0
    }
    this.clo = {
    moveDir : -1,
    tracking : false,
    ticker : 0
    }
    var Robot = function(robot){
    robot.turnLeft(robot.angle % 90);
    };
    Robot.prototype.onIdle = function(ev) {
    var robot = ev.robot;
    c = robot.parentId != undefined ? 'clo' : 'robo'
    o = c == 'robo' ? 'clo' : 'robo'
    this[c].x = robot.position.x
    this[c].y = robot.position.x
    this[c].gunCoolDownTime = robot.gunCoolDownTime
    this[c].angle = robot.angle
    this[c].cannonAngle = robot.cannonAbsoluteAngle
    /*if (this[o].tracking && !this[c].tracking) {
    this[c].tracking = true
    this[c].searching = false
    var tar = this[o].target
    this[c].target = tar
    var p1 = this[c]
    var p2 = tar
    c12 = p1.x * p2.x + p1.y * p2.y
    s12 = p1.x * p2.y - p1.y * p2.x
    a12 = Math.atan2(s12, c12)
    if (a12 > 180)
    robot.rotateCannon((a12 - 180) * -1)
    else
    robot.rotateCannon(a12)
    }*/
    if(this[o].target && !this[c].target){
    this[c].target=this[o].target
    }
    if (!this[c].searching && !this[c].tracking && !this[c].target) {
    //this[c].searching = true
    if (c == 'robo') {
    if (this[c].y > robot.arenaHeight + 200 / 2) {//on top half, so turn down
    if (this[c].angle < 90 || this[c].angle > 270) {
    robot.rotateCannon(360)
    } else
    robot.rotateCannon(-360)
    } else if (this[c].y < robot.arenaHeight + 200 / 2 - 200) {//on bottom half so turn up
    if (this[c].angle < 90 || this[c].angle > 270) {
    robot.rotateCannon(-360)
    } else
    robot.rotateCannon(360)
    } else if (this[c].x > robot.arenaWidth / 2) {//on right half, so start turning left
    if (this[c].angle < 180) {
    robot.rotateCannon(-360)
    } else
    robot.rotateCannon(360)
    } else {//on left half, so start turning right
    if (this[c].angle < 180) {
    robot.rotateCannon(360)
    } else
    robot.rotateCannon(-360)
    }
    } else {
    if (this[c].x > robot.arenaWidth / 2 + 200) {//on right half, so start turning left
    if (this[c].angle < 180) {
    robot.rotateCannon(-360)
    } else
    robot.rotateCannon(360)
    } else if (this[c].x < robot.arenaWidth / 2 - 200) {//on left half, so start turning right
    if (this[c].angle < 180) {
    robot.rotateCannon(360)
    } else
    robot.rotateCannon(-360)
    } else if (this[c].y > robot.arenaHeight / 2) {//on top half, so turn down
    if (this[c].angle < 90 || this[c].angle > 270) {
    robot.rotateCannon(360)
    } else
    robot.rotateCannon(-360)
    } else {//on bottom half so turn up
    if (this[c].angle < 90 || this[c].angle > 270) {
    robot.rotateCannon(-360)
    } else
    robot.rotateCannon(360)
    }
    }

    } else {
    if (this[c].target && this[c].gunCoolDownTime == 0) {
    //get my angle, and the position of the target
    var p1 = this[c]
    var p2 = this[c].target
    c12 = p1.x * p2.x + p1.y * p2.y
    s12 = p1.x * p2.y - p1.y * p2.x
    a12 = Math.atan2(s12, c12)*180/Math.PI

    robot.rotateCannon((a12)*(Math.abs(a12-this[c].angle)>180?-10:1))
    //console.log(a12-this[c].angle)
    //turn cannon to face target
    }
    this[c].ticker += 1
    if (this[c].ticker > 1000) {
    this[c].searching = false
    this[c].tracking = false
    this[c].ticker=0
    this[c].target = undefined
    }
    }
    /*if(this[c].tracking){
    //console.log("tracking")
    this[c].trackCount+=1
    if(this[c].trackCount>1000){
    console.log("tracking voer")
    this[c].tracking=false
    this[c].searching=true
    }
    if(this[c].gunCoolDownTime==0){
    //robot.rotateCannon(this[c].moveDir*360)
    }
    robot.ahead(10*this[c].moveDir)
    }*/
    var robot = ev.robot;
    if (robot.parentId) {
    robot.ahead(1);
    robot.turnGunRight(1);
    }
    else {
    robot.ahead(-1);
    robot.turnGunLeft(1);
    }
    };
    Robot.prototype.onWallCollision = function(ev) {
    var robot = ev.robot;
    c = robot.parentId != undefined ? 'clo' : 'robo'
    console.log("HIT WALL")
    this[c].moveDir *= -1
    robot.ahead(1000 * this[c].moveDir)
    var robot = ev.robot;
    if(!robot.parentId) {
    robot.turnRight(ev.bearing - 90);
    }
    else {
    robot.turnRight(ev.bearing + 90);
    }
    };
    Robot.prototype.onRobotCollision = function(ev) {
    var robot = ev.robot, collidedRobot = ev.collidedRobot;
    c = robot.parentId != undefined ? 'clo' : 'robo'
    this[c].moveDir *= -1
    robot.ahead(1000 * this[c].moveDir)
    var robot = ev.robot, collidedRobot = ev.collidedRobot;
    robot.ignore('onRobotCollision')
    if (ev.bearing > -90 && ev.bearing < 90) {
    robot.back(100);
    }
    else {
    robot.ahead(100);
    }

    if (robot.id != collidedRobot.parentId && robot.parentId != collidedRobot.id) {
    robot.turnGunRight(ev.bearing - robot.cannonRelativeAngle);
    robot.turnGunLeft(ev.bearing - robot.cannonRelativeAngle);
    }
    robot.listen('onRobotCollision')
    };
    Robot.prototype.onHitByBullet = function(ev) {
    var robot;
    robot.clone()
    robot = ev.robot;
    robot.turn(45 - ev.bulletBearing);
    robot.ahead(-50);
    robot.turn(45 - ev.bulletBearing);
    robot.back(90);
    };
    Robot.prototype.onScannedRobot = function(ev) {
    var robot = ev.robot, scannedRobot = ev.scannedRobot;
    if (robot.id == scannedRobot.parentId || robot.parentId == scannedRobot.id) {
    return;
    }
    if (scannedRobot.parentId) {//found a clone
    return
    }
    c = robot.parentId != undefined ? 'clo' : 'robo'
    if (!this[c].tracking) {
    robot.stop()
    robot.fire();
    //robot.turn(scannedRobot.angle-180)
    } else {
    robot.fire();
    }
    robot.ahead(30 * this[c].moveDir)
    this[c].tracking = false
    this[c].trackCount = 0
    this[c].ticker = 0
    this[c].searching = false
    this[c].target = {
    x : scannedRobot.position.x,
    y : scannedRobot.position.y
    }
    };
    var robot = ev.robot, scannedRobot = ev.scannedRobot;
    if (robot.id == scannedRobot.parentId || robot.parentId == scannedRobot.id) {
    return;
    }
    robot.fire();
    robot.turnGunRight(30);
    };
  2. Zolmeister revised this gist Dec 5, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion robot.js
    Original file line number Diff line number Diff line change
    @@ -54,7 +54,7 @@ Robot.prototype.onIdle = function(ev) {
    this[c].target=this[o].target
    }
    if (!this[c].searching && !this[c].tracking && !this[c].target) {
    this[c].searching = true
    //this[c].searching = true
    if (c == 'robo') {
    if (this[c].y > robot.arenaHeight + 200 / 2) {//on top half, so turn down
    if (this[c].angle < 90 || this[c].angle > 270) {
  3. Zolmeister revised this gist Dec 5, 2012. 1 changed file with 5 additions and 3 deletions.
    8 changes: 5 additions & 3 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -108,9 +108,10 @@ Robot.prototype.onIdle = function(ev) {
    var p2 = this[c].target
    c12 = p1.x * p2.x + p1.y * p2.y
    s12 = p1.x * p2.y - p1.y * p2.x
    a12 = Math.atan2(s12, c12)
    robot.rotateCannon(a12 - this[c].angle)
    console.log("rotate to target")
    a12 = Math.atan2(s12, c12)*180/Math.PI

    robot.rotateCannon((a12)*(Math.abs(a12-this[c].angle)>180?-10:1))
    //console.log(a12-this[c].angle)
    //turn cannon to face target
    }
    this[c].ticker += 1
    @@ -139,6 +140,7 @@ Robot.prototype.onIdle = function(ev) {
    Robot.prototype.onWallCollision = function(ev) {
    var robot = ev.robot;
    c = robot.parentId != undefined ? 'clo' : 'robo'
    console.log("HIT WALL")
    this[c].moveDir *= -1
    robot.ahead(1000 * this[c].moveDir)
    };
  4. Zolmeister revised this gist Dec 5, 2012. 1 changed file with 168 additions and 48 deletions.
    216 changes: 168 additions & 48 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -1,58 +1,178 @@
    var Robot = function(robot){
    robot.turnLeft(robot.angle % 90);
    //robot.turnGunRight(90);
    robot.clone();
    this.direction = 1;
    //clone
    //search field efficiently for enemy (main, ignore any clones)
    //on found:
    //fire at them
    //clone moves 300 units away from bot
    //turn parallel to them
    //move forward/backward (if wall hit then switch)
    //continuously track enemy position
    //if lose position (not found within next firing position), go back to finding algo
    //calculate enemy trajectory
    //when can fire another round, fire using calculated trajectory

    //on hit other robot, rotate 90 deg, go forward 100, then search for enemy again
    //on hit wall, flip movement direction

    var Robot = function(robot) {
    robot.clone();
    this.robo = {
    moveDir : 1,
    tracking : false,
    ticker : 0
    }
    this.clo = {
    moveDir : -1,
    tracking : false,
    ticker : 0
    }
    };
    Robot.prototype.onIdle = function(ev) {
    var robot = ev.robot;
    if (!robot.parentId) {
    robot.ahead(1);
    //if (robot.cannonRelativeAngle > 270 || robot.cannonRelativeAngle < 90) {
    // this.direction *= -1;
    //}
    //robot.turnGunRight(this.direction);
    //robot.turnGunRight(180);
    //robot.turnGunRight(-180);
    }
    else{
    robot.ahead(1);
    robot.turnGunRight(1);
    }

    var robot = ev.robot;
    c = robot.parentId != undefined ? 'clo' : 'robo'
    o = c == 'robo' ? 'clo' : 'robo'
    this[c].x = robot.position.x
    this[c].y = robot.position.x
    this[c].gunCoolDownTime = robot.gunCoolDownTime
    this[c].angle = robot.angle
    this[c].cannonAngle = robot.cannonAbsoluteAngle
    /*if (this[o].tracking && !this[c].tracking) {
    this[c].tracking = true
    this[c].searching = false
    var tar = this[o].target
    this[c].target = tar
    var p1 = this[c]
    var p2 = tar
    c12 = p1.x * p2.x + p1.y * p2.y
    s12 = p1.x * p2.y - p1.y * p2.x
    a12 = Math.atan2(s12, c12)
    if (a12 > 180)
    robot.rotateCannon((a12 - 180) * -1)
    else
    robot.rotateCannon(a12)
    }*/
    if(this[o].target && !this[c].target){
    this[c].target=this[o].target
    }
    if (!this[c].searching && !this[c].tracking && !this[c].target) {
    this[c].searching = true
    if (c == 'robo') {
    if (this[c].y > robot.arenaHeight + 200 / 2) {//on top half, so turn down
    if (this[c].angle < 90 || this[c].angle > 270) {
    robot.rotateCannon(360)
    } else
    robot.rotateCannon(-360)
    } else if (this[c].y < robot.arenaHeight + 200 / 2 - 200) {//on bottom half so turn up
    if (this[c].angle < 90 || this[c].angle > 270) {
    robot.rotateCannon(-360)
    } else
    robot.rotateCannon(360)
    } else if (this[c].x > robot.arenaWidth / 2) {//on right half, so start turning left
    if (this[c].angle < 180) {
    robot.rotateCannon(-360)
    } else
    robot.rotateCannon(360)
    } else {//on left half, so start turning right
    if (this[c].angle < 180) {
    robot.rotateCannon(360)
    } else
    robot.rotateCannon(-360)
    }
    } else {
    if (this[c].x > robot.arenaWidth / 2 + 200) {//on right half, so start turning left
    if (this[c].angle < 180) {
    robot.rotateCannon(-360)
    } else
    robot.rotateCannon(360)
    } else if (this[c].x < robot.arenaWidth / 2 - 200) {//on left half, so start turning right
    if (this[c].angle < 180) {
    robot.rotateCannon(360)
    } else
    robot.rotateCannon(-360)
    } else if (this[c].y > robot.arenaHeight / 2) {//on top half, so turn down
    if (this[c].angle < 90 || this[c].angle > 270) {
    robot.rotateCannon(360)
    } else
    robot.rotateCannon(-360)
    } else {//on bottom half so turn up
    if (this[c].angle < 90 || this[c].angle > 270) {
    robot.rotateCannon(-360)
    } else
    robot.rotateCannon(360)
    }
    }

    } else {
    if (this[c].target && this[c].gunCoolDownTime == 0) {
    //get my angle, and the position of the target
    var p1 = this[c]
    var p2 = this[c].target
    c12 = p1.x * p2.x + p1.y * p2.y
    s12 = p1.x * p2.y - p1.y * p2.x
    a12 = Math.atan2(s12, c12)
    robot.rotateCannon(a12 - this[c].angle)
    console.log("rotate to target")
    //turn cannon to face target
    }
    this[c].ticker += 1
    if (this[c].ticker > 1000) {
    this[c].searching = false
    this[c].tracking = false
    this[c].ticker=0
    this[c].target = undefined
    }
    }
    /*if(this[c].tracking){
    //console.log("tracking")
    this[c].trackCount+=1
    if(this[c].trackCount>1000){
    console.log("tracking voer")
    this[c].tracking=false
    this[c].searching=true
    }
    if(this[c].gunCoolDownTime==0){
    //robot.rotateCannon(this[c].moveDir*360)
    }
    robot.ahead(10*this[c].moveDir)
    }*/
    };
    Robot.prototype.onWallCollision = function(ev) {
    var robot = ev.robot;
    if(!robot.parentId)
    robot.turnRight(ev.bearing - 90);
    else
    robot.turnRight(ev.bearing + 90);
    var robot = ev.robot;
    c = robot.parentId != undefined ? 'clo' : 'robo'
    this[c].moveDir *= -1
    robot.ahead(1000 * this[c].moveDir)
    };
    Robot.prototype.onRobotCollision = function(ev) {
    var robot = ev.robot, collidedRobot = ev.collidedRobot;
    robot.ignore('onRobotCollision')
    if (ev.bearing > -90 && ev.bearing < 90) {
    robot.back(100);
    } else {
    robot.ahead(100);
    }

    if (robot.id != collidedRobot.parentId && robot.parentId != collidedRobot.id) {
    robot.turnGunRight(ev.bearing - robot.cannonRelativeAngle);
    robot.turnGunLeft(ev.bearing - robot.cannonRelativeAngle);
    }
    robot.listen('onRobotCollision')
    var robot = ev.robot, collidedRobot = ev.collidedRobot;
    c = robot.parentId != undefined ? 'clo' : 'robo'
    this[c].moveDir *= -1
    robot.ahead(1000 * this[c].moveDir)
    };
    Robot.prototype.onHitByBullet = function(ev) {

    };
    Robot.prototype.onScannedRobot = function(ev) {
    var robot = ev.robot, scannedRobot = ev.scannedRobot;
    if (robot.id == scannedRobot.parentId || robot.parentId == scannedRobot.id) {
    return;
    }
    robot.fire();
    if(robot.parentId)
    robot.turnGunLeft(30);
    //robot.log('firing');
    };
    var robot = ev.robot, scannedRobot = ev.scannedRobot;
    if (robot.id == scannedRobot.parentId || robot.parentId == scannedRobot.id) {
    return;
    }
    if (scannedRobot.parentId) {//found a clone
    return
    }
    c = robot.parentId != undefined ? 'clo' : 'robo'
    if (!this[c].tracking) {
    robot.stop()
    robot.fire();
    //robot.turn(scannedRobot.angle-180)
    } else {
    robot.fire();
    }
    robot.ahead(30 * this[c].moveDir)
    this[c].tracking = false
    this[c].trackCount = 0
    this[c].ticker = 0
    this[c].searching = false
    this[c].target = {
    x : scannedRobot.position.x,
    y : scannedRobot.position.y
    }
    };
  5. Zolmeister revised this gist Dec 5, 2012. 1 changed file with 45 additions and 63 deletions.
    108 changes: 45 additions & 63 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -1,76 +1,58 @@

    //FightCode can only understand your robot
    //if its class is called Robot
    var go=120;

    var Robot = function(robot) {

    var Robot = function(robot){
    robot.turnLeft(robot.angle % 90);
    //robot.turnGunRight(90);
    robot.clone();
    this.direction = 1;
    };


    Robot.prototype.onIdle = function(ev) {
    var robot = ev.robot;
    var clo =0
    robot.clone();
    if(robot.parentId!=null){

    clo=-240;
    if (!robot.parentId) {
    robot.ahead(1);
    //if (robot.cannonRelativeAngle > 270 || robot.cannonRelativeAngle < 90) {
    // this.direction *= -1;
    //}
    //robot.turnGunRight(this.direction);
    //robot.turnGunRight(180);
    //robot.turnGunRight(-180);
    }
    else{
    robot.ahead(1);
    robot.turnGunRight(1);
    }
    robot.id=2

    robot.rotateCannon(90);
    robot = ev.robot;

    if(.6>Math.random()){
    robot.ahead(go+clo);
    robot.turn(95);
    }
    };

    Robot.prototype.onScannedRobot = function(ev) {
    var sr = ev.scannedRobot;
    Robot.prototype.onWallCollision = function(ev) {
    var robot = ev.robot;

    var bFriendly = ( robot.parentId !=null && robot.parentId==sr.id);
    bFriendly |= ( sr.parentId !=null && sr.parentId==robot.id);

    if(bFriendly){
    robot.back(50);
    }
    if(!bFriendly){
    robot.fire();
    robot.fire();
    robot.rotateCannon(-15);
    robot.fire();
    robot.fire();
    robot.rotateCannon(-10);
    if(!robot.parentId)
    robot.turnRight(ev.bearing - 90);
    else
    robot.turnRight(ev.bearing + 90);
    };
    Robot.prototype.onRobotCollision = function(ev) {
    var robot = ev.robot, collidedRobot = ev.collidedRobot;
    robot.ignore('onRobotCollision')
    if (ev.bearing > -90 && ev.bearing < 90) {
    robot.back(100);
    } else {
    robot.ahead(100);
    }

    if (robot.id != collidedRobot.parentId && robot.parentId != collidedRobot.id) {
    robot.turnGunRight(ev.bearing - robot.cannonRelativeAngle);
    robot.turnGunLeft(ev.bearing - robot.cannonRelativeAngle);
    }
    robot.listen('onRobotCollision')
    };
    Robot.prototype.onWallCollision= function(ev){
    var robot = ev.robot;

    go=go*-1;

    robot.back(go);
    robot.rotateCannon(90);
    robot.back(go);
    robot.rotateCannon(90);

    }
    Robot.prototype.onHitByBullet = function(ev) {
    var robot = ev.robot;
    if(robot.parentId!=null){
    robot.turn(ev.bearing);
    robot.fire();
    robot.fire();
    robot.fire();
    robot.fire();
    robot.fire();
    }

    };
    Robot.prototype.onRobotCollision = function(ev) {
    var robot = ev.robot;
    robot.turn(20);
    robot.ahead(100); // trying to run away
    Robot.prototype.onScannedRobot = function(ev) {
    var robot = ev.robot, scannedRobot = ev.scannedRobot;
    if (robot.id == scannedRobot.parentId || robot.parentId == scannedRobot.id) {
    return;
    }
    robot.fire();
    if(robot.parentId)
    robot.turnGunLeft(30);
    //robot.log('firing');
    };
  6. Zolmeister revised this gist Dec 4, 2012. No changes.
  7. Zolmeister revised this gist Dec 4, 2012. No changes.
  8. Zolmeister revised this gist Dec 4, 2012. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion robot.js
    Original file line number Diff line number Diff line change
    @@ -8,14 +8,15 @@ var Robot = function(robot) {
    };



    Robot.prototype.onIdle = function(ev) {
    var robot = ev.robot;
    var clo =0
    robot.clone();
    if(robot.parentId!=null){

    clo=-240;
    }
    robot.id=2

    robot.rotateCannon(90);
    robot = ev.robot;
  9. Zolmeister revised this gist Dec 4, 2012. 1 changed file with 57 additions and 31 deletions.
    88 changes: 57 additions & 31 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -1,49 +1,75 @@

    //FightCode can only understand your robot
    //if its class is called Robot
    var Robot = function(robot) {
    var go=120;

    var Robot = function(robot) {

    };



    Robot.prototype.onIdle = function(ev) {
    var robot = ev.robot;
    robot.clone();
    robot.ahead(100);
    robot.rotateCannon(360);
    robot.back(100);
    robot.rotateCannon(360);
    var clo =0
    robot.clone();
    if(robot.parentId!=null){
    clo=-240;
    }

    robot.rotateCannon(90);
    robot = ev.robot;

    if(.6>Math.random()){
    robot.ahead(go+clo);
    robot.turn(95);
    }
    };

    Robot.prototype.onScannedRobot = function(ev) {
    var robot = ev.robot;
    var scanned =ev.scannedRobot;
    if(scanned.id !== robot.parentId && scanned.parentId !== robot.id) {
    var sr = ev.scannedRobot;
    var robot = ev.robot;

    var bFriendly = ( robot.parentId !=null && robot.parentId==sr.id);
    bFriendly |= ( sr.parentId !=null && sr.parentId==robot.id);

    if(bFriendly){
    robot.back(50);
    }
    if(!bFriendly){
    robot.fire();
    robot.fire();
    robot.rotateCannon(-3);
    robot.rotateCannon(-30);
    }else{
    robot.ahead(30);
    }


    robot.rotateCannon(-15);
    robot.fire();
    robot.fire();
    robot.rotateCannon(-10);
    }

    };
    Robot.prototype.onWallCollision= function(ev){
    var robot = ev.robot;

    go=go*-1;

    robot.back(go);
    robot.rotateCannon(90);
    robot.back(go);
    robot.rotateCannon(90);

    }
    Robot.prototype.onHitByBullet = function(ev) {
    var robot;
    robot = ev.robot;
    robot.turn(90 - ev.bulletBearing);
    robot.ahead(-50);
    robot.turn(60 - ev.bulletBearing);
    robot.back(90);
    var robot = ev.robot;
    if(robot.parentId!=null){
    robot.turn(ev.bearing);
    robot.fire();
    robot.fire();
    robot.fire();
    robot.fire();
    robot.fire();
    }
    };

    Robot.prototype.onRobotCollision = function(ev) {
    var robot = ev.robot;
    robot.ahead(robot.position+5);
    robot.ahead(robot.position-15);

    // trying to run away
    };



    robot.turn(20);
    robot.ahead(100); // trying to run away
    };
  10. Zolmeister revised this gist Dec 4, 2012. 1 changed file with 2 additions and 6 deletions.
    8 changes: 2 additions & 6 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -8,13 +8,9 @@ var Robot = function(robot) {
    Robot.prototype.onIdle = function(ev) {
    var robot = ev.robot;
    robot.clone();
    robot.ahead(10);
    if(robot.parentId)
    robot.back(100);
    robot.ahead(100);
    robot.rotateCannon(360);
    robot.back(10);
    if(robot.parentId)
    robot.ahead(300);
    robot.back(100);
    robot.rotateCannon(360);

    };
  11. Zolmeister revised this gist Dec 4, 2012. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -13,6 +13,8 @@ Robot.prototype.onIdle = function(ev) {
    robot.back(100);
    robot.rotateCannon(360);
    robot.back(10);
    if(robot.parentId)
    robot.ahead(300);
    robot.rotateCannon(360);

    };
  12. Zolmeister revised this gist Dec 4, 2012. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -9,9 +9,12 @@ Robot.prototype.onIdle = function(ev) {
    var robot = ev.robot;
    robot.clone();
    robot.ahead(10);
    if(robot.parentId)
    robot.back(100);
    robot.rotateCannon(360);
    robot.back(10);
    robot.rotateCannon(360);

    };

    Robot.prototype.onScannedRobot = function(ev) {
  13. Zolmeister revised this gist Dec 4, 2012. 1 changed file with 2 additions and 3 deletions.
    5 changes: 2 additions & 3 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -8,11 +8,10 @@ var Robot = function(robot) {
    Robot.prototype.onIdle = function(ev) {
    var robot = ev.robot;
    robot.clone();
    robot.ahead(100);
    robot.ahead(10);
    robot.rotateCannon(360);
    robot.back(100);
    robot.back(10);
    robot.rotateCannon(360);

    };

    Robot.prototype.onScannedRobot = function(ev) {
  14. Zolmeister revised this gist Dec 4, 2012. 1 changed file with 41 additions and 50 deletions.
    91 changes: 41 additions & 50 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -1,58 +1,49 @@
    var Robot = function(robot){
    robot.turnLeft(robot.angle % 90);
    //robot.turnGunRight(90);
    robot.clone();
    this.direction = 1;

    //FightCode can only understand your robot
    //if its class is called Robot
    var Robot = function(robot) {

    };

    Robot.prototype.onIdle = function(ev) {
    var robot = ev.robot;
    if (!robot.parentId) {
    robot.ahead(1);
    //if (robot.cannonRelativeAngle > 270 || robot.cannonRelativeAngle < 90) {
    // this.direction *= -1;
    //}
    //robot.turnGunRight(this.direction);
    //robot.turnGunRight(180);
    //robot.turnGunRight(-180);
    }
    else{
    robot.ahead(1);
    robot.turnGunRight(1);
    }

    };
    Robot.prototype.onWallCollision = function(ev) {
    var robot = ev.robot;
    if(!robot.parentId)
    robot.turnRight(ev.bearing - 90);
    else
    robot.turnRight(ev.bearing + 90);
    };
    Robot.prototype.onRobotCollision = function(ev) {
    var robot = ev.robot, collidedRobot = ev.collidedRobot;
    robot.ignore('onRobotCollision')
    if (ev.bearing > -90 && ev.bearing < 90) {
    robot.back(100);
    } else {
    robot.clone();
    robot.ahead(100);
    }
    robot.rotateCannon(360);
    robot.back(100);
    robot.rotateCannon(360);

    if (robot.id != collidedRobot.parentId && robot.parentId != collidedRobot.id) {
    robot.turnGunRight(ev.bearing - robot.cannonRelativeAngle);
    robot.turnGunLeft(ev.bearing - robot.cannonRelativeAngle);
    }
    robot.listen('onRobotCollision')
    };
    Robot.prototype.onHitByBullet = function(ev) {

    };
    Robot.prototype.onScannedRobot = function(ev) {
    var robot = ev.robot, scannedRobot = ev.scannedRobot;
    if (robot.id == scannedRobot.parentId || robot.parentId == scannedRobot.id) {
    return;
    }
    robot.fire();
    if(robot.parentId)
    robot.turnGunLeft(30);
    //robot.log('firing');
    };
    var robot = ev.robot;
    var scanned =ev.scannedRobot;
    if(scanned.id !== robot.parentId && scanned.parentId !== robot.id) {
    robot.fire();
    robot.rotateCannon(-3);
    robot.rotateCannon(-30);
    }else{
    robot.ahead(30);
    }


    };
    Robot.prototype.onHitByBullet = function(ev) {
    var robot;
    robot = ev.robot;
    robot.turn(90 - ev.bulletBearing);
    robot.ahead(-50);
    robot.turn(60 - ev.bulletBearing);
    robot.back(90);
    };

    Robot.prototype.onRobotCollision = function(ev) {
    var robot = ev.robot;
    robot.ahead(robot.position+5);
    robot.ahead(robot.position-15);

    // trying to run away
    };



  15. Zolmeister revised this gist Dec 4, 2012. No changes.
  16. Zolmeister revised this gist Dec 4, 2012. No changes.
  17. Zolmeister revised this gist Dec 4, 2012. 1 changed file with 8 additions and 2 deletions.
    10 changes: 8 additions & 2 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -6,15 +6,19 @@ var Robot = function(robot){
    };
    Robot.prototype.onIdle = function(ev) {
    var robot = ev.robot;
    robot.ahead(1);
    if (robot.parentId) {
    if (!robot.parentId) {
    robot.ahead(1);
    //if (robot.cannonRelativeAngle > 270 || robot.cannonRelativeAngle < 90) {
    // this.direction *= -1;
    //}
    //robot.turnGunRight(this.direction);
    //robot.turnGunRight(180);
    //robot.turnGunRight(-180);
    }
    else{
    robot.ahead(1);
    robot.turnGunRight(1);
    }

    };
    Robot.prototype.onWallCollision = function(ev) {
    @@ -48,5 +52,7 @@ Robot.prototype.onScannedRobot = function(ev) {
    return;
    }
    robot.fire();
    if(robot.parentId)
    robot.turnGunLeft(30);
    //robot.log('firing');
    };
  18. Zolmeister revised this gist Dec 2, 2012. No changes.
  19. Zolmeister revised this gist Dec 2, 2012. 1 changed file with 47 additions and 31 deletions.
    78 changes: 47 additions & 31 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -1,36 +1,52 @@
    var Robot = function(robot) {
    this.dir=1;
    this.once=false
    var Robot = function(robot){
    robot.turnLeft(robot.angle % 90);
    //robot.turnGunRight(90);
    robot.clone();
    this.direction = 1;
    };
    Robot.prototype.onIdle = function(ev) {
    var robot = ev.robot;
    if(!robot.parentId)
    robot.rotateCannon(-1*this.dir);
    else{
    robot.rotateCannon(-1);
    }
    if(robot.parentId && !this.once){
    this.once=true;
    robot.back(100);
    }
    robot.clone();
    var robot = ev.robot;
    robot.ahead(1);
    if (robot.parentId) {
    //if (robot.cannonRelativeAngle > 270 || robot.cannonRelativeAngle < 90) {
    // this.direction *= -1;
    //}
    //robot.turnGunRight(this.direction);
    //robot.turnGunRight(180);
    //robot.turnGunRight(-180);
    }

    };
    Robot.prototype.onScannedRobot = function(ev) {
    var robot = ev.robot;
    var srobo = ev.scannedRobot;
    var id1 = robot.parentId || robot.id;
    var id2 = srobo.parentId || srobo.id;
    if(id1!=id2){

    if(!robot.parentId){
    robot.stop();
    robot.fire();
    robot.rotateCannon(-30*this.dir);
    this.dir*=-1;
    }
    else{
    robot.rotateCannon(15);
    robot.fire(5);
    }
    Robot.prototype.onWallCollision = function(ev) {
    var robot = ev.robot;
    if(!robot.parentId)
    robot.turnRight(ev.bearing - 90);
    else
    robot.turnRight(ev.bearing + 90);
    };
    Robot.prototype.onRobotCollision = function(ev) {
    var robot = ev.robot, collidedRobot = ev.collidedRobot;
    robot.ignore('onRobotCollision')
    if (ev.bearing > -90 && ev.bearing < 90) {
    robot.back(100);
    } else {
    robot.ahead(100);
    }

    if (robot.id != collidedRobot.parentId && robot.parentId != collidedRobot.id) {
    robot.turnGunRight(ev.bearing - robot.cannonRelativeAngle);
    robot.turnGunLeft(ev.bearing - robot.cannonRelativeAngle);
    }
    robot.listen('onRobotCollision')
    };
    Robot.prototype.onHitByBullet = function(ev) {

    };
    Robot.prototype.onScannedRobot = function(ev) {
    var robot = ev.robot, scannedRobot = ev.scannedRobot;
    if (robot.id == scannedRobot.parentId || robot.parentId == scannedRobot.id) {
    return;
    }
    robot.fire();
    //robot.log('firing');
    };
  20. Zolmeister revised this gist Dec 2, 2012. 1 changed file with 31 additions and 47 deletions.
    78 changes: 31 additions & 47 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -1,52 +1,36 @@
    var Robot = function(robot){
    robot.turnLeft(robot.angle % 90);
    //robot.turnGunRight(90);
    robot.clone();
    this.direction = 1;
    var Robot = function(robot) {
    this.dir=1;
    this.once=false
    };
    Robot.prototype.onIdle = function(ev) {
    var robot = ev.robot;
    robot.ahead(1);
    if (robot.parentId) {
    //if (robot.cannonRelativeAngle > 270 || robot.cannonRelativeAngle < 90) {
    // this.direction *= -1;
    //}
    //robot.turnGunRight(this.direction);
    //robot.turnGunRight(180);
    //robot.turnGunRight(-180);
    }

    var robot = ev.robot;
    if(!robot.parentId)
    robot.rotateCannon(-1*this.dir);
    else{
    robot.rotateCannon(-1);
    }
    if(robot.parentId && !this.once){
    this.once=true;
    robot.back(100);
    }
    robot.clone();
    };
    Robot.prototype.onWallCollision = function(ev) {
    var robot = ev.robot;
    if(!robot.parentId)
    robot.turnRight(ev.bearing - 90);
    else
    robot.turnRight(ev.bearing + 90);
    };
    Robot.prototype.onRobotCollision = function(ev) {
    var robot = ev.robot, collidedRobot = ev.collidedRobot;
    robot.ignore('onRobotCollision')
    if (ev.bearing > -90 && ev.bearing < 90) {
    robot.back(100);
    } else {
    robot.ahead(100);
    }

    if (robot.id != collidedRobot.parentId && robot.parentId != collidedRobot.id) {
    robot.turnGunRight(ev.bearing - robot.cannonRelativeAngle);
    robot.turnGunLeft(ev.bearing - robot.cannonRelativeAngle);
    }
    robot.listen('onRobotCollision')
    };
    Robot.prototype.onHitByBullet = function(ev) {

    };
    Robot.prototype.onScannedRobot = function(ev) {
    var robot = ev.robot, scannedRobot = ev.scannedRobot;
    if (robot.id == scannedRobot.parentId || robot.parentId == scannedRobot.id) {
    return;
    Robot.prototype.onScannedRobot = function(ev) {
    var robot = ev.robot;
    var srobo = ev.scannedRobot;
    var id1 = robot.parentId || robot.id;
    var id2 = srobo.parentId || srobo.id;
    if(id1!=id2){

    if(!robot.parentId){
    robot.stop();
    robot.fire();
    robot.rotateCannon(-30*this.dir);
    this.dir*=-1;
    }
    else{
    robot.rotateCannon(15);
    robot.fire(5);
    }
    }
    robot.fire();
    //robot.log('firing');
    };
  21. Zolmeister revised this gist Dec 2, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion robot.js
    Original file line number Diff line number Diff line change
    @@ -28,7 +28,7 @@ Robot.prototype.onRobotCollision = function(ev) {
    var robot = ev.robot, collidedRobot = ev.collidedRobot;
    robot.ignore('onRobotCollision')
    if (ev.bearing > -90 && ev.bearing < 90) {
    //robot.back(100);
    robot.back(100);
    } else {
    robot.ahead(100);
    }
  22. Zolmeister revised this gist Dec 2, 2012. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion robot.js
    Original file line number Diff line number Diff line change
    @@ -19,13 +19,16 @@ Robot.prototype.onIdle = function(ev) {
    };
    Robot.prototype.onWallCollision = function(ev) {
    var robot = ev.robot;
    if(!robot.parentId)
    robot.turnRight(ev.bearing - 90);
    else
    robot.turnRight(ev.bearing + 90);
    };
    Robot.prototype.onRobotCollision = function(ev) {
    var robot = ev.robot, collidedRobot = ev.collidedRobot;
    robot.ignore('onRobotCollision')
    if (ev.bearing > -90 && ev.bearing < 90) {
    robot.back(100);
    //robot.back(100);
    } else {
    robot.ahead(100);
    }
  23. Zolmeister revised this gist Dec 2, 2012. 1 changed file with 5 additions and 6 deletions.
    11 changes: 5 additions & 6 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -1,17 +1,17 @@
    var Robot = function(robot){
    robot.turnLeft(robot.angle % 90);
    robot.turnGunRight(90);
    //robot.turnGunRight(90);
    robot.clone();
    this.direction = 1;
    };
    Robot.prototype.onIdle = function(ev) {
    var robot = ev.robot;
    robot.ahead(1);
    if (robot.parentId) {
    if (robot.cannonRelativeAngle > 270 || robot.cannonRelativeAngle < 90) {
    this.direction *= -1;
    }
    robot.turnGunRight(this.direction);
    //if (robot.cannonRelativeAngle > 270 || robot.cannonRelativeAngle < 90) {
    // this.direction *= -1;
    //}
    //robot.turnGunRight(this.direction);
    //robot.turnGunRight(180);
    //robot.turnGunRight(-180);
    }
    @@ -20,7 +20,6 @@ Robot.prototype.onIdle = function(ev) {
    Robot.prototype.onWallCollision = function(ev) {
    var robot = ev.robot;
    robot.turnRight(ev.bearing + 90);

    };
    Robot.prototype.onRobotCollision = function(ev) {
    var robot = ev.robot, collidedRobot = ev.collidedRobot;
  24. @cezarsa cezarsa revised this gist Dec 2, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion robot.js
    Original file line number Diff line number Diff line change
    @@ -46,5 +46,5 @@ Robot.prototype.onScannedRobot = function(ev) {
    return;
    }
    robot.fire();
    robot.log('firing');
    //robot.log('firing');
    };
  25. @cezarsa cezarsa revised this gist Dec 2, 2012. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -46,4 +46,5 @@ Robot.prototype.onScannedRobot = function(ev) {
    return;
    }
    robot.fire();
    robot.log('firing');
    };
  26. @cezarsa cezarsa revised this gist Nov 30, 2012. 1 changed file with 8 additions and 1 deletion.
    9 changes: 8 additions & 1 deletion robot.js
    Original file line number Diff line number Diff line change
    @@ -2,13 +2,20 @@ var Robot = function(robot){
    robot.turnLeft(robot.angle % 90);
    robot.turnGunRight(90);
    robot.clone();
    this.direction = 1;
    };
    Robot.prototype.onIdle = function(ev) {
    var robot = ev.robot;
    robot.ahead(1);
    if (robot.parentId) {
    robot.turnGunRight(1)
    if (robot.cannonRelativeAngle > 270 || robot.cannonRelativeAngle < 90) {
    this.direction *= -1;
    }
    robot.turnGunRight(this.direction);
    //robot.turnGunRight(180);
    //robot.turnGunRight(-180);
    }

    };
    Robot.prototype.onWallCollision = function(ev) {
    var robot = ev.robot;
  27. @cezarsa cezarsa revised this gist Nov 30, 2012. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,10 @@ var Robot = function(robot){
    };
    Robot.prototype.onIdle = function(ev) {
    var robot = ev.robot;
    robot.ahead(1);
    robot.ahead(1);
    if (robot.parentId) {
    robot.turnGunRight(1)
    }
    };
    Robot.prototype.onWallCollision = function(ev) {
    var robot = ev.robot;
    @@ -14,7 +17,6 @@ Robot.prototype.onWallCollision = function(ev) {
    };
    Robot.prototype.onRobotCollision = function(ev) {
    var robot = ev.robot, collidedRobot = ev.collidedRobot;

    robot.ignore('onRobotCollision')
    if (ev.bearing > -90 && ev.bearing < 90) {
    robot.back(100);
  28. @cezarsa cezarsa revised this gist Nov 29, 2012. No changes.
  29. @cezarsa cezarsa revised this gist Nov 29, 2012. No changes.
  30. @cezarsa cezarsa revised this gist Nov 29, 2012. No changes.