Skip to content

Instantly share code, notes, and snippets.

@jgaNet
Forked from dlomibao/robot.js
Created December 4, 2012 14:20

Revisions

  1. @dlomibao dlomibao revised this gist Dec 4, 2012. No changes.
  2. @dlomibao dlomibao revised this gist Dec 4, 2012. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion robot.js
    Original file line number Diff line number Diff line change
    @@ -68,5 +68,9 @@ Robot.prototype.onHitByBullet = function(ev) {
    robot.fire();
    }
    };

    Robot.prototype.onRobotCollision = function(ev) {
    var robot = ev.robot;
    robot.turn(20);
    robot.ahead(100); // trying to run away
    };

  3. @dlomibao dlomibao revised this gist Dec 4, 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
    @@ -22,7 +22,7 @@ Robot.prototype.onIdle = function(ev) {

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

  4. @dlomibao dlomibao revised this gist Dec 4, 2012. 1 changed file with 1 addition and 27 deletions.
    28 changes: 1 addition & 27 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -20,12 +20,6 @@ Robot.prototype.onIdle = function(ev) {
    robot.rotateCannon(90);
    robot = ev.robot;

    // if(Math.random()>.7){

    // robot.turn(50);

    //}

    if(.6>Math.random()){
    robot.ahead(go+clo);
    robot.turn(90);
    @@ -51,17 +45,6 @@ Robot.prototype.onScannedRobot = function(ev) {
    robot.rotateCannon(-10);
    }


    // robot.fire();

    //if(Math.random()<.5){
    //robot.rotateCannon(-25);
    //robot.fire();
    //}
    //if(Math.random()>.5){
    //robot.rotateCannon(25);
    //robot.fire();
    //}
    };
    Robot.prototype.onWallCollision= function(ev){
    var robot = ev.robot;
    @@ -72,16 +55,7 @@ Robot.prototype.onWallCollision= function(ev){
    robot.rotateCannon(90);
    robot.back(go);
    robot.rotateCannon(90);
    /* robot.back(go);
    robot.rotateCannon(90);
    robot.back(go);
    robot.rotateCannon(90);
    robot.back(go);
    robot.rotateCannon(90);
    robot.back(go);
    robot.rotateCannon(45);
    robot.back(go);
    robot.rotateCannon(45);*/

    }
    Robot.prototype.onHitByBullet = function(ev) {
    var robot = ev.robot;
  5. @dlomibao dlomibao revised this gist Dec 4, 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
    @@ -40,7 +40,7 @@ Robot.prototype.onScannedRobot = function(ev) {
    bFriendly |= ( sr.parentId !=null && sr.parentId==robot.id);

    if(bFriendly){
    robot.ahead(50);
    robot.back(50);
    }
    if(!bFriendly){
    robot.fire();
  6. @dlomibao dlomibao revised this gist Dec 4, 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.onIdle = function(ev) {

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

  7. @dlomibao dlomibao revised this gist Dec 4, 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.onIdle = function(ev) {

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

  8. @dlomibao dlomibao revised this gist Dec 4, 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.onIdle = function(ev) {

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

  9. @dlomibao dlomibao revised this gist Dec 4, 2012. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion robot.js
    Original file line number Diff line number Diff line change
    @@ -39,7 +39,9 @@ Robot.prototype.onScannedRobot = function(ev) {
    var bFriendly = ( robot.parentId !=null && robot.parentId==sr.id);
    bFriendly |= ( sr.parentId !=null && sr.parentId==robot.id);


    if(bFriendly){
    robot.ahead(50);
    }
    if(!bFriendly){
    robot.fire();
    robot.fire();
  10. @dlomibao dlomibao revised this gist Dec 4, 2012. 1 changed file with 9 additions and 3 deletions.
    12 changes: 9 additions & 3 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -12,7 +12,7 @@ var Robot = function(robot) {
    Robot.prototype.onIdle = function(ev) {
    var robot = ev.robot;
    var clo =0

    robot.clone();
    if(robot.parentId!=null){
    clo=-240;
    }
    @@ -83,8 +83,14 @@ Robot.prototype.onWallCollision= function(ev){
    }
    Robot.prototype.onHitByBullet = function(ev) {
    var robot = ev.robot;
    // Turn to wherever the bullet was fired
    robot.clone(); // so we can see who shot it
    if(robot.parentId!=null){
    robot.turn(ev.bearing);
    robot.fire();
    robot.fire();
    robot.fire();
    robot.fire();
    robot.fire();
    }
    };


  11. @dlomibao dlomibao revised this gist Dec 4, 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
    @@ -20,11 +20,11 @@ Robot.prototype.onIdle = function(ev) {
    robot.rotateCannon(90);
    robot = ev.robot;

    if(Math.random()>.7){
    // if(Math.random()>.7){

    robot.turn(50);
    // robot.turn(50);

    }
    //}

    if(.6>Math.random()){
    robot.ahead(go+clo);
  12. @dlomibao dlomibao revised this gist Dec 4, 2012. 1 changed file with 6 additions and 2 deletions.
    8 changes: 6 additions & 2 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -12,7 +12,7 @@ var Robot = function(robot) {
    Robot.prototype.onIdle = function(ev) {
    var robot = ev.robot;
    var clo =0
    robot.clone();

    if(robot.parentId!=null){
    clo=-240;
    }
    @@ -81,6 +81,10 @@ Robot.prototype.onWallCollision= function(ev){
    robot.back(go);
    robot.rotateCannon(45);*/
    }

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


  13. @dlomibao dlomibao revised this gist Dec 4, 2012. 1 changed file with 7 additions and 3 deletions.
    10 changes: 7 additions & 3 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,7 @@
    //FightCode can only understand your robot
    //if its class is called Robot
    var go=120;

    var Robot = function(robot) {

    };
    @@ -10,22 +11,25 @@ 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.rotateCannon(90);
    robot = ev.robot;

    if(Math.random()>.7){
    go=go*-1;

    robot.turn(50);

    }

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

    };

    Robot.prototype.onScannedRobot = function(ev) {
  14. @dlomibao dlomibao revised this gist Dec 4, 2012. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -14,6 +14,13 @@ Robot.prototype.onIdle = function(ev) {

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

    if(Math.random()>.7){
    go=go*-1;
    robot.turn(50);

    }

    if(.6>Math.random()){
    robot.ahead(go);
    robot.turn(-20);
  15. @dlomibao dlomibao revised this gist Dec 4, 2012. 1 changed file with 9 additions and 1 deletion.
    10 changes: 9 additions & 1 deletion robot.js
    Original file line number Diff line number Diff line change
    @@ -22,13 +22,21 @@ Robot.prototype.onIdle = function(ev) {
    };

    Robot.prototype.onScannedRobot = function(ev) {
    var robot = ev.robot;
    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.fire();
    robot.fire();
    robot.rotateCannon(-15);
    robot.fire();
    robot.fire();
    robot.rotateCannon(-10);
    }


    // robot.fire();
  16. @dlomibao dlomibao revised this gist Dec 4, 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
    @@ -29,7 +29,7 @@ Robot.prototype.onScannedRobot = function(ev) {
    robot.fire();
    robot.fire();
    robot.rotateCannon(-10);
    }


    // robot.fire();

  17. @dlomibao dlomibao revised this gist Dec 4, 2012. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion robot.js
    Original file line number Diff line number Diff line change
    @@ -23,7 +23,6 @@ Robot.prototype.onIdle = function(ev) {

    Robot.prototype.onScannedRobot = function(ev) {
    var robot = ev.robot;
    if(robot.id!=robot.parentId){
    robot.fire();
    robot.fire();
    robot.rotateCannon(-15);
  18. @dlomibao dlomibao revised this gist Dec 4, 2012. 1 changed file with 1 addition and 5 deletions.
    6 changes: 1 addition & 5 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -63,10 +63,6 @@ Robot.prototype.onWallCollision= function(ev){
    robot.back(go);
    robot.rotateCannon(45);*/
    }
    Robot.prototype.onHitByBullet = function(ev) {
    var robot = ev.robot;
    robot.turnCannon(ev.bearing); // Turn to wherever the bullet was fired

    };



  19. @dlomibao dlomibao revised this gist Dec 4, 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
    @@ -10,9 +10,8 @@ var Robot = function(robot) {

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

    robot.clone();

    robot.rotateCannon(90);
    robot = ev.robot;
    if(.6>Math.random()){
    @@ -24,12 +23,15 @@ Robot.prototype.onIdle = function(ev) {

    Robot.prototype.onScannedRobot = function(ev) {
    var robot = ev.robot;
    if(robot.id!=robot.parentId){
    robot.fire();
    robot.fire();
    robot.rotateCannon(-15);
    robot.fire();
    robot.fire();
    robot.rotateCannon(-10);
    }

    // robot.fire();

    //if(Math.random()<.5){
  20. @dlomibao dlomibao revised this gist Dec 4, 2012. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion robot.js
    Original file line number Diff line number Diff line change
    @@ -10,6 +10,8 @@ var Robot = function(robot) {

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

    robot.clone();

    robot.rotateCannon(90);
    robot = ev.robot;
    @@ -62,7 +64,7 @@ Robot.prototype.onWallCollision= function(ev){
    Robot.prototype.onHitByBullet = function(ev) {
    var robot = ev.robot;
    robot.turnCannon(ev.bearing); // Turn to wherever the bullet was fired
    robot.clone();

    };


  21. @dlomibao dlomibao revised this gist Dec 4, 2012. 1 changed file with 6 additions and 5 deletions.
    11 changes: 6 additions & 5 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -6,11 +6,7 @@ var Robot = function(robot) {

    };

    Robot.prototype.onHitByBullet = function(ev) {
    var robot = ev.robot;
    robot.turnCannon(ev.bearing); // Turn to wherever the bullet was fired
    robot.clone();
    };


    Robot.prototype.onIdle = function(ev) {
    var robot = ev.robot;
    @@ -63,5 +59,10 @@ Robot.prototype.onWallCollision= function(ev){
    robot.back(go);
    robot.rotateCannon(45);*/
    }
    Robot.prototype.onHitByBullet = function(ev) {
    var robot = ev.robot;
    robot.turnCannon(ev.bearing); // Turn to wherever the bullet was fired
    robot.clone();
    };


  22. @dlomibao dlomibao revised this gist Dec 4, 2012. 1 changed file with 3 additions and 5 deletions.
    8 changes: 3 additions & 5 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -5,14 +5,12 @@ var go=120;
    var Robot = function(robot) {

    };
    /*

    Robot.prototype.onHitByBullet = function(ev) {
    var robot = ev.robot;
    robot.turnCannon(ev.bearing); // Turn to wherever the bullet was fired
    robot.fire(); // so we can see who shot it
    robot.fire();
    robot.ahead(30);
    };*/
    robot.clone();
    };

    Robot.prototype.onIdle = function(ev) {
    var robot = ev.robot;
  23. @dlomibao dlomibao revised this gist Dec 4, 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
    @@ -5,14 +5,14 @@ var go=120;
    var Robot = function(robot) {

    };

    /*
    Robot.prototype.onHitByBullet = function(ev) {
    var robot = ev.robot;
    robot.turnCannon(ev.bearing); // Turn to wherever the bullet was fired
    robot.fire(); // so we can see who shot it
    robot.fire();
    robot.ahead(30);
    };
    };*/

    Robot.prototype.onIdle = function(ev) {
    var robot = ev.robot;
  24. @dlomibao dlomibao revised this gist Dec 4, 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
    @@ -5,14 +5,14 @@ var go=120;
    var Robot = function(robot) {

    };
    /*

    Robot.prototype.onHitByBullet = function(ev) {
    var robot = ev.robot;
    robot.turnCannon(ev.bearing); // Turn to wherever the bullet was fired
    robot.fire(); // so we can see who shot it
    robot.fire();
    robot.ahead(30);
    };*/
    };

    Robot.prototype.onIdle = function(ev) {
    var robot = ev.robot;
  25. @dlomibao dlomibao revised this gist Dec 4, 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
    @@ -5,14 +5,14 @@ var go=120;
    var Robot = function(robot) {

    };

    /*
    Robot.prototype.onHitByBullet = function(ev) {
    var robot = ev.robot;
    robot.turnCannon(ev.bearing); // Turn to wherever the bullet was fired
    robot.fire(); // so we can see who shot it
    robot.fire();
    robot.ahead(30);
    };
    };*/

    Robot.prototype.onIdle = function(ev) {
    var robot = ev.robot;
  26. @dlomibao dlomibao revised this gist Dec 4, 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
    @@ -8,7 +8,7 @@ var Robot = function(robot) {

    Robot.prototype.onHitByBullet = function(ev) {
    var robot = ev.robot;
    robot.turn(ev.bearing); // Turn to wherever the bullet was fired
    robot.turnCannon(ev.bearing); // Turn to wherever the bullet was fired
    robot.fire(); // so we can see who shot it
    robot.fire();
    robot.ahead(30);
  27. @dlomibao dlomibao revised this gist Dec 4, 2012. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion robot.js
    Original file line number Diff line number Diff line change
    @@ -9,7 +9,9 @@ var Robot = function(robot) {
    Robot.prototype.onHitByBullet = function(ev) {
    var robot = ev.robot;
    robot.turn(ev.bearing); // Turn to wherever the bullet was fired
    // so we can see who shot it
    robot.fire(); // so we can see who shot it
    robot.fire();
    robot.ahead(30);
    };

    Robot.prototype.onIdle = function(ev) {
  28. @dlomibao dlomibao revised this gist Dec 4, 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
    @@ -6,6 +6,12 @@ var Robot = function(robot) {

    };

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

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

  29. @dlomibao dlomibao revised this gist Dec 4, 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
    @@ -13,8 +13,8 @@ Robot.prototype.onIdle = function(ev) {
    robot = ev.robot;
    if(.6>Math.random()){
    robot.ahead(go);
    robot.turn(-20);
    }


    };

  30. @dlomibao dlomibao revised this gist Dec 4, 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
    @@ -10,8 +10,8 @@ Robot.prototype.onIdle = function(ev) {
    var robot = ev.robot;

    robot.rotateCannon(90);
    //robot = ev.robot;
    if(.5>Math.random()){
    robot = ev.robot;
    if(.6>Math.random()){
    robot.ahead(go);
    }