Skip to content

Instantly share code, notes, and snippets.

@kjaku
Forked from Isinlor/robot.js
Created December 7, 2012 20:13
Show Gist options
  • Select an option

  • Save kjaku/4236158 to your computer and use it in GitHub Desktop.

Select an option

Save kjaku/4236158 to your computer and use it in GitHub Desktop.

Revisions

  1. @Isinlor Isinlor revised this gist Dec 7, 2012. No changes.
  2. @Isinlor Isinlor 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
    @@ -63,6 +63,7 @@ Robot.prototype.onScannedRobot = function(ev) {
    return;
    }
    if(count > 5){
    count = 0;
    robot.log('5 miss');
    if (robot.parentId) {
    robot.turnGunRight(7);
  3. @Isinlor Isinlor revised this gist Dec 7, 2012. 1 changed file with 3 additions and 4 deletions.
    7 changes: 3 additions & 4 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@
    * shooting when you are next to wall and in front of enemy
    */
    var count = 0;
    var savedEnemyLife;
    var savedEnemyLife = 0;
    var turnDirections = 1;
    var Robot = function(robot){
    robot.clone();
    @@ -71,13 +71,12 @@ Robot.prototype.onScannedRobot = function(ev) {
    }
    }
    robot.fire();
    if(savedEnemyLife == scannedRobot.life || scannedRobot.life == 100){
    savedEnemyLife = scannedRobot.life;
    if(savedEnemyLife == scannedRobot.life){
    count +=1;
    } else {
    savedEnemyLife = scannedRobot.life;
    count = 0;
    }
    savedEnemyLife = scannedRobot.life;
    if (robot.parentId) {
    robot.turnGunLeft(30);
    } else {
  4. @Isinlor Isinlor 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
    @@ -5,7 +5,7 @@
    * TODO; RobotCollision - it sucks
    * shooting when you are next to wall and in front of enemy
    */
    var count;
    var count = 0;
    var savedEnemyLife;
    var turnDirections = 1;
    var Robot = function(robot){
  5. @Isinlor Isinlor 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
    @@ -63,6 +63,7 @@ Robot.prototype.onScannedRobot = function(ev) {
    return;
    }
    if(count > 5){
    robot.log('5 miss');
    if (robot.parentId) {
    robot.turnGunRight(7);
    } else {
  6. @Isinlor Isinlor revised this gist Dec 7, 2012. No changes.
  7. @Isinlor Isinlor revised this gist Dec 7, 2012. No changes.
  8. @Isinlor Isinlor revised this gist Dec 7, 2012. No changes.
  9. @Isinlor Isinlor revised this gist Dec 7, 2012. No changes.
  10. @Isinlor Isinlor revised this gist Dec 7, 2012. No changes.
  11. @Isinlor Isinlor revised this gist Dec 7, 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
    @@ -1,3 +1,10 @@
    /*
    * It would be great if you fork & upgrade
    * created by; Zolmeister
    * edited by: Isinlor
    * TODO; RobotCollision - it sucks
    * shooting when you are next to wall and in front of enemy
    */
    var count;
    var savedEnemyLife;
    var turnDirections = 1;
  12. @Isinlor Isinlor 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
    @@ -44,7 +44,7 @@ Robot.prototype.onRobotCollision = function(ev) {
    Robot.prototype.onHitByBullet = function(ev) {
    var robot;
    robot = ev.robot;
    robot.ahead(100-robot.life);
    robot.ahead(120-robot.life);
    // robot.turn(45 - ev.bulletBearing);
    // robot.ahead(-50);
    // robot.turn(45 - ev.bulletBearing);
  13. @Isinlor Isinlor revised this gist Dec 7, 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
    @@ -70,5 +70,9 @@ Robot.prototype.onScannedRobot = function(ev) {
    savedEnemyLife = scannedRobot.life;
    count = 0;
    }
    robot.turnGunRight(30);
    if (robot.parentId) {
    robot.turnGunLeft(30);
    } else {
    robot.turnGunRight(30);
    }
    };
  14. @Isinlor Isinlor revised this gist Dec 7, 2012. 1 changed file with 5 additions and 10 deletions.
    15 changes: 5 additions & 10 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -27,13 +27,8 @@ Robot.prototype.onWallCollision = function(ev) {
    };
    Robot.prototype.onRobotCollision = function(ev) {
    var robot = ev.robot, collidedRobot = ev.collidedRobot;
    //robot.ignore('onRobotCollision');
    console.log(robot.id + ' lol1 ' + collidedRobot.parentId);
    if (robot.id == collidedRobot.parentId || robot.parentId == collidedRobot.id) {
    turnDirections = turnDirections * -1;
    console.log(robot.id + ' lol2 ' + collidedRobot.parentId);
    }
    /*if (ev.bearing > -90 && ev.bearing < 90) {
    robot.ignore('onRobotCollision');
    if (ev.bearing > -90 && ev.bearing < 90) {
    robot.back(100);
    }
    else {
    @@ -43,8 +38,8 @@ Robot.prototype.onRobotCollision = function(ev) {
    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.listen('onRobotCollision')
    };
    Robot.prototype.onHitByBullet = function(ev) {
    var robot;
    @@ -67,7 +62,7 @@ Robot.prototype.onScannedRobot = function(ev) {
    robot.turnGunLeft(7);
    }
    }
    //robot.fire();
    robot.fire();
    if(savedEnemyLife == scannedRobot.life || scannedRobot.life == 100){
    savedEnemyLife = scannedRobot.life;
    count +=1;
  15. @Isinlor Isinlor revised this gist Dec 7, 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
    @@ -28,9 +28,10 @@ Robot.prototype.onWallCollision = function(ev) {
    Robot.prototype.onRobotCollision = function(ev) {
    var robot = ev.robot, collidedRobot = ev.collidedRobot;
    //robot.ignore('onRobotCollision');
    console.log(robot.id + ' lol ' + collidedRobot.parentId);
    console.log(robot.id + ' lol1 ' + collidedRobot.parentId);
    if (robot.id == collidedRobot.parentId || robot.parentId == collidedRobot.id) {
    turnDirections = turnDirections * -1;
    console.log(robot.id + ' lol2 ' + collidedRobot.parentId);
    }
    /*if (ev.bearing > -90 && ev.bearing < 90) {
    robot.back(100);
  16. @Isinlor Isinlor 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
    @@ -1,4 +1,4 @@
    var count; //
    var count;
    var savedEnemyLife;
    var turnDirections = 1;
    var Robot = function(robot){
    @@ -28,9 +28,9 @@ Robot.prototype.onWallCollision = function(ev) {
    Robot.prototype.onRobotCollision = function(ev) {
    var robot = ev.robot, collidedRobot = ev.collidedRobot;
    //robot.ignore('onRobotCollision');
    if (robot.id == collidedRobot.parentId && robot.parentId == collidedRobot.id) {
    console.log(robot.id + ' lol ' + collidedRobot.parentId);
    if (robot.id == collidedRobot.parentId || robot.parentId == collidedRobot.id) {
    turnDirections = turnDirections * -1;
    console.log(robot.id + ' lol ' + collidedRobot.parentId);
    }
    /*if (ev.bearing > -90 && ev.bearing < 90) {
    robot.back(100);
  17. @Isinlor Isinlor 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
    @@ -28,7 +28,7 @@ Robot.prototype.onWallCollision = function(ev) {
    Robot.prototype.onRobotCollision = function(ev) {
    var robot = ev.robot, collidedRobot = ev.collidedRobot;
    //robot.ignore('onRobotCollision');
    if (robot.id == collidedRobot.id) {
    if (robot.id == collidedRobot.parentId && robot.parentId == collidedRobot.id) {
    turnDirections = turnDirections * -1;
    console.log(robot.id + ' lol ' + collidedRobot.parentId);
    }
  18. @Isinlor Isinlor 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
    @@ -28,7 +28,7 @@ Robot.prototype.onWallCollision = function(ev) {
    Robot.prototype.onRobotCollision = function(ev) {
    var robot = ev.robot, collidedRobot = ev.collidedRobot;
    //robot.ignore('onRobotCollision');
    if (robot.id == collidedRobot.parentId) {
    if (robot.id == collidedRobot.id) {
    turnDirections = turnDirections * -1;
    console.log(robot.id + ' lol ' + collidedRobot.parentId);
    }
  19. @Isinlor Isinlor revised this gist Dec 7, 2012. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -8,12 +8,12 @@ var Robot = function(robot){
    Robot.prototype.onIdle = function(ev) {
    var robot = ev.robot;
    if (robot.parentId) {
    robot.ahead(1);
    robot.turnGunRight(1);
    robot.ahead(1*turnDirections);
    robot.turnGunRight(1*turnDirections);
    }
    else {
    robot.ahead(-1);
    robot.turnGunLeft(1);
    robot.ahead(-1*turnDirections);
    robot.turnGunLeft(1*turnDirections);
    }
    };
    Robot.prototype.onWallCollision = function(ev) {
  20. @Isinlor Isinlor 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
    @@ -30,7 +30,7 @@ Robot.prototype.onRobotCollision = function(ev) {
    //robot.ignore('onRobotCollision');
    if (robot.id == collidedRobot.parentId) {
    turnDirections = turnDirections * -1;
    console.log(robot.id + 'lol' + collidedRobot.parentId);
    console.log(robot.id + ' lol ' + collidedRobot.parentId);
    }
    /*if (ev.bearing > -90 && ev.bearing < 90) {
    robot.back(100);
  21. @Isinlor Isinlor revised this gist Dec 7, 2012. 1 changed file with 7 additions and 8 deletions.
    15 changes: 7 additions & 8 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -7,14 +7,13 @@ var Robot = function(robot){
    };
    Robot.prototype.onIdle = function(ev) {
    var robot = ev.robot;
    console.log(turnDirections);
    if (robot.parentId) {
    robot.ahead(1*turnDirections);
    robot.turnGunRight(1*turnDirections);
    robot.ahead(1);
    robot.turnGunRight(1);
    }
    else {
    robot.ahead(-1*turnDirections);
    robot.turnGunLeft(1*turnDirections);
    robot.ahead(-1);
    robot.turnGunLeft(1);
    }
    };
    Robot.prototype.onWallCollision = function(ev) {
    @@ -29,10 +28,10 @@ Robot.prototype.onWallCollision = function(ev) {
    Robot.prototype.onRobotCollision = function(ev) {
    var robot = ev.robot, collidedRobot = ev.collidedRobot;
    //robot.ignore('onRobotCollision');
    console.log('lol');
    if (robot.id == collidedRobot.parentId || robot.parentId == collidedRobot.id) {
    if (robot.id == collidedRobot.parentId) {
    turnDirections = turnDirections * -1;
    }//
    console.log(robot.id + 'lol' + collidedRobot.parentId);
    }
    /*if (ev.bearing > -90 && ev.bearing < 90) {
    robot.back(100);
    }
  22. @Isinlor Isinlor 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
    @@ -7,6 +7,7 @@ var Robot = function(robot){
    };
    Robot.prototype.onIdle = function(ev) {
    var robot = ev.robot;
    console.log(turnDirections);
    if (robot.parentId) {
    robot.ahead(1*turnDirections);
    robot.turnGunRight(1*turnDirections);
  23. @Isinlor Isinlor revised this gist Dec 7, 2012. 1 changed file with 15 additions and 10 deletions.
    25 changes: 15 additions & 10 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -1,18 +1,19 @@
    var count;
    var count; //
    var savedEnemyLife;
    var turnDirections = 1;
    var Robot = function(robot){
    robot.clone();
    robot.turnLeft(robot.angle % 90);
    };
    Robot.prototype.onIdle = function(ev) {
    var robot = ev.robot;
    if (robot.parentId) {
    robot.ahead(1);
    robot.turnGunRight(1);
    robot.ahead(1*turnDirections);
    robot.turnGunRight(1*turnDirections);
    }
    else {
    robot.ahead(-1);
    robot.turnGunLeft(1);
    robot.ahead(-1*turnDirections);
    robot.turnGunLeft(1*turnDirections);
    }
    };
    Robot.prototype.onWallCollision = function(ev) {
    @@ -26,8 +27,12 @@ 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.ignore('onRobotCollision');
    console.log('lol');
    if (robot.id == collidedRobot.parentId || robot.parentId == collidedRobot.id) {
    turnDirections = turnDirections * -1;
    }//
    /*if (ev.bearing > -90 && ev.bearing < 90) {
    robot.back(100);
    }
    else {
    @@ -37,8 +42,8 @@ Robot.prototype.onRobotCollision = function(ev) {
    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.listen('onRobotCollision')
    };
    Robot.prototype.onHitByBullet = function(ev) {
    var robot;
    @@ -61,7 +66,7 @@ Robot.prototype.onScannedRobot = function(ev) {
    robot.turnGunLeft(7);
    }
    }
    robot.fire();
    //robot.fire();
    if(savedEnemyLife == scannedRobot.life || scannedRobot.life == 100){
    savedEnemyLife = scannedRobot.life;
    count +=1;
  24. @Isinlor Isinlor revised this gist Dec 7, 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
    @@ -43,10 +43,11 @@ Robot.prototype.onRobotCollision = function(ev) {
    Robot.prototype.onHitByBullet = function(ev) {
    var robot;
    robot = ev.robot;
    robot.turn(45 - ev.bulletBearing);
    robot.ahead(-50);
    robot.turn(45 - ev.bulletBearing);
    robot.back(90);
    robot.ahead(100-robot.life);
    // 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;
    @@ -68,5 +69,5 @@ Robot.prototype.onScannedRobot = function(ev) {
    savedEnemyLife = scannedRobot.life;
    count = 0;
    }
    robot.turnGunRight(32);
    robot.turnGunRight(30);
    };
  25. @Isinlor Isinlor 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
    @@ -42,7 +42,6 @@ Robot.prototype.onRobotCollision = function(ev) {
    };
    Robot.prototype.onHitByBullet = function(ev) {
    var robot;
    robot.clone()
    robot = ev.robot;
    robot.turn(45 - ev.bulletBearing);
    robot.ahead(-50);
    @@ -54,7 +53,7 @@ Robot.prototype.onScannedRobot = function(ev) {
    if (robot.id == scannedRobot.parentId || robot.parentId == scannedRobot.id) {
    return;
    }
    if(count > 20){
    if(count > 5){
    if (robot.parentId) {
    robot.turnGunRight(7);
    } else {
  26. @Isinlor Isinlor revised this gist Dec 6, 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
    @@ -55,7 +55,6 @@ Robot.prototype.onScannedRobot = function(ev) {
    return;
    }
    if(count > 20){
    console.log('adjust');
    if (robot.parentId) {
    robot.turnGunRight(7);
    } else {
  27. @Isinlor Isinlor revised this gist Dec 6, 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
    @@ -55,6 +55,7 @@ Robot.prototype.onScannedRobot = function(ev) {
    return;
    }
    if(count > 20){
    console.log('adjust');
    if (robot.parentId) {
    robot.turnGunRight(7);
    } else {
  28. @Isinlor Isinlor 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
    @@ -56,9 +56,9 @@ Robot.prototype.onScannedRobot = function(ev) {
    }
    if(count > 20){
    if (robot.parentId) {
    robot.turnGunRight(10);
    robot.turnGunRight(7);
    } else {
    robot.turnGunLeft(10);
    robot.turnGunLeft(7);
    }
    }
    robot.fire();
  29. @Isinlor Isinlor revised this gist Dec 6, 2012. 1 changed file with 16 additions and 0 deletions.
    16 changes: 16 additions & 0 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    var count;
    var savedEnemyLife;
    var Robot = function(robot){
    robot.clone();
    robot.turnLeft(robot.angle % 90);
    @@ -52,6 +54,20 @@ Robot.prototype.onScannedRobot = function(ev) {
    if (robot.id == scannedRobot.parentId || robot.parentId == scannedRobot.id) {
    return;
    }
    if(count > 20){
    if (robot.parentId) {
    robot.turnGunRight(10);
    } else {
    robot.turnGunLeft(10);
    }
    }
    robot.fire();
    if(savedEnemyLife == scannedRobot.life || scannedRobot.life == 100){
    savedEnemyLife = scannedRobot.life;
    count +=1;
    } else {
    savedEnemyLife = scannedRobot.life;
    count = 0;
    }
    robot.turnGunRight(32);
    };
  30. @Isinlor Isinlor 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
    @@ -53,5 +53,5 @@ Robot.prototype.onScannedRobot = function(ev) {
    return;
    }
    robot.fire();
    robot.turnGunRight(30);
    robot.turnGunRight(32);
    };