Skip to content

Instantly share code, notes, and snippets.

@samelinux
Forked from zachiPL/robot.js
Created December 7, 2012 10:27
Show Gist options
  • Select an option

  • Save samelinux/4232357 to your computer and use it in GitHub Desktop.

Select an option

Save samelinux/4232357 to your computer and use it in GitHub Desktop.

Revisions

  1. samelinux revised this gist Dec 7, 2012. 1 changed file with 0 additions and 53 deletions.
    53 changes: 0 additions & 53 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -1,53 +0,0 @@
    var eading;
    var firesign;
    var lasthealth;
    var fired;

    var Robot = function(robot) {
    eading=1;
    firesign=1;
    lasthealth=100;
    fired=false;
    robot.rotateCannon(-90);
    };

    Robot.prototype.onIdle = function(ev) {
    if(eading==1)
    {
    ev.robot.ahead(30);
    }
    else
    {
    ev.robot.back(30);
    }
    if(ev.robot.cannonRelativeAngle==300 || ev.robot.cannonRelativeAngle==60)
    {
    if(firesign==1)
    {
    firesign=-1;
    }
    else
    {
    firesign=1;
    }
    }
    // if(!fired)
    ev.robot.rotateCannon(10*firesign);
    };

    Robot.prototype.onHitByBullet = function(ev) {
    eading=1-eading;
    };

    Robot.prototype.onScannedRobot = function(ev) {
    // ev.robot.fire();
    // ev.robot.rotateCannon(-20*firesign);
    };

    Robot.prototype.onRobotCollision = function(ev) {
    eading=1-eading;
    };

    Robot.prototype.onWallCollision = function(ev) {
    ev.robot.turn(ev.bearing - 90);
    };
  2. samelinux revised this gist Dec 7, 2012. 1 changed file with 12 additions and 1 deletion.
    13 changes: 12 additions & 1 deletion robot.js
    Original file line number Diff line number Diff line change
    @@ -20,8 +20,19 @@ Robot.prototype.onIdle = function(ev) {
    {
    ev.robot.back(30);
    }
    if(ev.robot.cannonRelativeAngle==300 || ev.robot.cannonRelativeAngle==60)
    {
    if(firesign==1)
    {
    firesign=-1;
    }
    else
    {
    firesign=1;
    }
    }
    // if(!fired)
    // ev.robot.rotateCannon(10*firesign);
    ev.robot.rotateCannon(10*firesign);
    };

    Robot.prototype.onHitByBullet = function(ev) {
  3. samelinux revised this gist Dec 7, 2012. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -20,7 +20,6 @@ Robot.prototype.onIdle = function(ev) {
    {
    ev.robot.back(30);
    }
    ev.robot.log(ev.robot.cannonRelativeAngle);
    // if(!fired)
    // ev.robot.rotateCannon(10*firesign);
    };
    @@ -39,5 +38,5 @@ Robot.prototype.onRobotCollision = function(ev) {
    };

    Robot.prototype.onWallCollision = function(ev) {
    ev.robot.turn(ev.bearing - 90);//
    ev.robot.turn(ev.bearing - 90);
    };
  4. samelinux revised this gist Dec 7, 2012. No changes.
  5. samelinux revised this gist Dec 7, 2012. 1 changed file with 6 additions and 25 deletions.
    31 changes: 6 additions & 25 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -20,43 +20,24 @@ Robot.prototype.onIdle = function(ev) {
    {
    ev.robot.back(30);
    }
    if(ev.robot.cannonRelativeAngle==60 ||
    ev.robot.cannonRelativeAngle==300)
    {
    if(firesign==1)
    firesign=-1;
    else
    firesign=1;
    }
    if(!fired)
    ev.robot.rotateCannon(10*firesign);
    ev.robot.log(ev.robot.cannonRelativeAngle);
    // if(!fired)
    // ev.robot.rotateCannon(10*firesign);
    };

    Robot.prototype.onHitByBullet = function(ev) {
    eading=1-eading;
    };

    Robot.prototype.onScannedRobot = function(ev) {
    if(lastRobotHealth>=ev.scannedRobot.life)
    {
    if(firesign==1)
    {
    firesign=-1;
    }
    else
    {
    firesign=1;
    }
    }
    ev.robot.fire();
    ev.robot.rotateCannon(-10*firesign);
    // ev.robot.fire();
    // ev.robot.rotateCannon(-20*firesign);
    };

    Robot.prototype.onRobotCollision = function(ev) {
    eading=1-eading;
    };

    Robot.prototype.onWallCollision = function(ev) {
    var robot = ev.robot;
    robot.turn(ev.bearing - 90);
    ev.robot.turn(ev.bearing - 90);//
    };
  6. samelinux revised this gist Dec 7, 2012. 1 changed file with 41 additions and 27 deletions.
    68 changes: 41 additions & 27 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -1,48 +1,62 @@

    var eading;
    var firesign;
    var lasthealth;
    var fired;

    var Robot = function(robot) {
    robot.ignore('onScannedRobot');
    eading=1;
    firesign=1;
    lasthealth=100;
    fired=false;
    robot.rotateCannon(-90);
    robot.listen('onScannedRobot');
    };

    Robot.prototype.onIdle = function(ev) {
    var robot = ev.robot;
    robot.ahead(30);

    if(eading==1)
    {
    ev.robot.ahead(30);
    }
    else
    {
    ev.robot.back(30);
    }
    if(ev.robot.cannonRelativeAngle==60 ||
    ev.robot.cannonRelativeAngle==300)
    {
    if(firesign==1)
    firesign=-1;
    else
    firesign=1;
    }
    if(!fired)
    ev.robot.rotateCannon(10*firesign);
    };

    Robot.prototype.onHitByBullet = function(ev) {
    var robot = ev.robot;
    robot.ignore('onHitByBullet');
    robot.turn(-45);
    robot.ahead(100);
    robot.listen('onHitByBullet');
    eading=1-eading;
    };

    Robot.prototype.onScannedRobot = function(ev) {
    var robot = ev.robot;
    robot.stop();
    robot.ignore('onWallCollision');
    robot.fire(3);
    robot.ahead(50);
    robot.turn(-30);
    robot.listen('onWallCollision');
    if(lastRobotHealth>=ev.scannedRobot.life)
    {
    if(firesign==1)
    {
    firesign=-1;
    }
    else
    {
    firesign=1;
    }
    }
    ev.robot.fire();
    ev.robot.rotateCannon(-10*firesign);
    };

    Robot.prototype.onRobotCollision = function(ev) {
    var robot = ev.robot;
    robot.stop();
    robot.back(10);
    robot.listen('onScannedRobot');
    robot.ignore('onWallCollision');
    robot.turn(90);
    robot.listen('onWallCollision');
    robot.listen('onScannedRobot');
    eading=1-eading;
    };

    Robot.prototype.onWallCollision = function(ev) {
    var robot = ev.robot;
    robot.turn(ev.bearing - 90);

    };
  7. Szymon Zachara revised this gist Dec 7, 2012. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -33,12 +33,12 @@ Robot.prototype.onScannedRobot = function(ev) {
    Robot.prototype.onRobotCollision = function(ev) {
    var robot = ev.robot;
    robot.stop();
    robot.back(10);

    robot.back(10);
    robot.listen('onScannedRobot');
    robot.ignore('onWallCollision');
    robot.turn(90);
    robot.listen('onWallCollision');
    robot.listen('onScannedRobot');
    robot.listen('onScannedRobot');
    };

    Robot.prototype.onWallCollision = function(ev) {
  8. Szymon Zachara revised this gist Dec 7, 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
    @@ -38,6 +38,7 @@ Robot.prototype.onRobotCollision = function(ev) {
    robot.ignore('onWallCollision');
    robot.turn(90);
    robot.listen('onWallCollision');
    robot.listen('onScannedRobot');
    };

    Robot.prototype.onWallCollision = function(ev) {
  9. Szymon Zachara revised this gist Dec 7, 2012. No changes.
  10. Szymon Zachara revised this gist Dec 7, 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
    @@ -26,7 +26,7 @@ Robot.prototype.onScannedRobot = function(ev) {
    robot.ignore('onWallCollision');
    robot.fire(3);
    robot.ahead(50);
    robot.turn(-90);
    robot.turn(-30);
    robot.listen('onWallCollision');
    };

  11. Szymon Zachara revised this gist Dec 7, 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
    @@ -26,7 +26,7 @@ Robot.prototype.onScannedRobot = function(ev) {
    robot.ignore('onWallCollision');
    robot.fire(3);
    robot.ahead(50);
    robot.turn(-35);
    robot.turn(-90);
    robot.listen('onWallCollision');
    };

  12. Szymon Zachara revised this gist Dec 6, 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
    @@ -14,8 +14,10 @@ Robot.prototype.onIdle = function(ev) {

    Robot.prototype.onHitByBullet = function(ev) {
    var robot = ev.robot;
    robot.turn(-45); // Turn to wherever the bullet was fired
    // so we can see who shot it
    robot.ignore('onHitByBullet');
    robot.turn(-45);
    robot.ahead(100);
    robot.listen('onHitByBullet');
    };

    Robot.prototype.onScannedRobot = function(ev) {
  13. Szymon Zachara revised this gist Dec 6, 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
    @@ -14,7 +14,7 @@ Robot.prototype.onIdle = function(ev) {

    Robot.prototype.onHitByBullet = function(ev) {
    var robot = ev.robot;
    robot.turn(-90); // Turn to wherever the bullet was fired
    robot.turn(-45); // Turn to wherever the bullet was fired
    // so we can see who shot it
    };

  14. Szymon Zachara revised this gist Dec 6, 2012. 1 changed file with 7 additions and 1 deletion.
    8 changes: 7 additions & 1 deletion robot.js
    Original file line number Diff line number Diff line change
    @@ -12,13 +12,19 @@ Robot.prototype.onIdle = function(ev) {

    };

    Robot.prototype.onHitByBullet = function(ev) {
    var robot = ev.robot;
    robot.turn(-90); // Turn to wherever the bullet was fired
    // so we can see who shot it
    };

    Robot.prototype.onScannedRobot = function(ev) {
    var robot = ev.robot;
    robot.stop();
    robot.ignore('onWallCollision');
    robot.fire(3);
    robot.ahead(50);
    robot.turn(-20);
    robot.turn(-35);
    robot.listen('onWallCollision');
    };

  15. Szymon Zachara revised this gist Dec 6, 2012. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,9 @@


    var Robot = function(robot) {
    robot.ignore('onScannedRobot');
    robot.rotateCannon(-90);
    robot.listen('onScannedRobot');
    };

    Robot.prototype.onIdle = function(ev) {
    @@ -12,6 +14,7 @@ Robot.prototype.onIdle = function(ev) {

    Robot.prototype.onScannedRobot = function(ev) {
    var robot = ev.robot;
    robot.stop();
    robot.ignore('onWallCollision');
    robot.fire(3);
    robot.ahead(50);
    @@ -21,6 +24,9 @@ Robot.prototype.onScannedRobot = function(ev) {

    Robot.prototype.onRobotCollision = function(ev) {
    var robot = ev.robot;
    robot.stop();
    robot.back(10);

    robot.ignore('onWallCollision');
    robot.turn(90);
    robot.listen('onWallCollision');
  16. Szymon Zachara revised this gist Dec 6, 2012. No changes.
  17. Szymon Zachara revised this gist Dec 6, 2012. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -14,8 +14,8 @@ Robot.prototype.onScannedRobot = function(ev) {
    var robot = ev.robot;
    robot.ignore('onWallCollision');
    robot.fire(3);
    robot.back(60);
    robot.turn(20);
    robot.ahead(50);
    robot.turn(-20);
    robot.listen('onWallCollision');
    };

  18. Szymon Zachara revised this gist Dec 6, 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
    @@ -21,7 +21,9 @@ Robot.prototype.onScannedRobot = function(ev) {

    Robot.prototype.onRobotCollision = function(ev) {
    var robot = ev.robot;
    robot.ignore('onWallCollision');
    robot.turn(90);
    robot.listen('onWallCollision');
    };

    Robot.prototype.onWallCollision = function(ev) {
  19. Szymon Zachara revised this gist Dec 6, 2012. 1 changed file with 4 additions and 6 deletions.
    10 changes: 4 additions & 6 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -1,24 +1,22 @@

    //FightCode can only understand your robot
    //if its class is called Robot

    var Robot = function(robot) {
    robot.rotateCannon(-90);
    };

    Robot.prototype.onIdle = function(ev) {
    var robot = ev.robot;
    robot.ahead(30);

    };

    Robot.prototype.onScannedRobot = function(ev) {
    var robot = ev.robot;
    //robot.stop();
    robot.ignore('onWallCollistion');
    robot.ignore('onWallCollision');
    robot.fire(3);
    robot.back(60);
    robot.turn(20);
    robot.listen('onWallCollistion');

    robot.listen('onWallCollision');
    };

    Robot.prototype.onRobotCollision = function(ev) {
  20. Szymon Zachara revised this gist Dec 6, 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
    @@ -13,10 +13,12 @@ Robot.prototype.onIdle = function(ev) {
    Robot.prototype.onScannedRobot = function(ev) {
    var robot = ev.robot;
    //robot.stop();

    robot.fire();
    robot.ignore('onWallCollistion');
    robot.fire(3);
    robot.back(60);
    robot.turn(20);
    robot.listen('onWallCollistion');

    };

    Robot.prototype.onRobotCollision = function(ev) {
  21. Szymon Zachara revised this gist Dec 6, 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
    @@ -15,7 +15,8 @@ Robot.prototype.onScannedRobot = function(ev) {
    //robot.stop();

    robot.fire();
    robot.back(50);
    robot.back(60);
    robot.turn(20);
    };

    Robot.prototype.onRobotCollision = function(ev) {
  22. Szymon Zachara revised this gist Dec 6, 2012. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -18,6 +18,11 @@ Robot.prototype.onScannedRobot = function(ev) {
    robot.back(50);
    };

    Robot.prototype.onRobotCollision = function(ev) {
    var robot = ev.robot;
    robot.turn(90);
    };

    Robot.prototype.onWallCollision = function(ev) {
    var robot = ev.robot;
    robot.turn(ev.bearing - 90);
  23. Szymon Zachara created this gist Dec 6, 2012.
    25 changes: 25 additions & 0 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@

    //FightCode can only understand your robot
    //if its class is called Robot
    var Robot = function(robot) {
    robot.rotateCannon(-90);
    };

    Robot.prototype.onIdle = function(ev) {
    var robot = ev.robot;
    robot.ahead(30);
    };

    Robot.prototype.onScannedRobot = function(ev) {
    var robot = ev.robot;
    //robot.stop();

    robot.fire();
    robot.back(50);
    };

    Robot.prototype.onWallCollision = function(ev) {
    var robot = ev.robot;
    robot.turn(ev.bearing - 90);

    };