Skip to content

Instantly share code, notes, and snippets.

@heynemann
Created November 28, 2012 16:35
Show Gist options
  • Select an option

  • Save heynemann/4162401 to your computer and use it in GitHub Desktop.

Select an option

Save heynemann/4162401 to your computer and use it in GitHub Desktop.

Revisions

  1. heynemann revised this gist Dec 14, 2012. 1 changed file with 10 additions and 2 deletions.
    12 changes: 10 additions & 2 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -26,11 +26,19 @@ Robot.prototype.onIdle = function(ev) {
    var deltaX = Math.abs(robot.position.x - foundRobotPosition.x);
    var deltaY = Math.abs(robot.position.y - foundRobotPosition.y);
    var angle = Math.atan(deltaY / deltaX);
    console.log(angle);
    angle = angle * (180/Math.PI);
    foundByClone = false;
    foundByParent = false;
    robot.turn(angle);

    for (var i=0; i < this.options.shootIterations; i++) {
    robot.fire();
    robot.ahead(10);
    robot.rotateCannon(-1);
    }
    }
    robot.rotateCannon(1);

    robot.turn(1);
    robot.ahead(1);
    };

  2. heynemann revised this gist Dec 14, 2012. 1 changed file with 29 additions and 9 deletions.
    38 changes: 29 additions & 9 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -1,26 +1,49 @@
    var foundRobotPosition = {x:0, y:0},
    foundByParent=false,
    foundByClone=false;

    //FightCode can only understand your robot
    //if its class is called Robot
    var Robot = function(robot){
    //robot.ignore('onRobotCollision');
    robot.clone();
    this.options = {
    direction: 1,
    aheadWhileTurning: 3,
    shootIterations: 5,
    distanceToWalkBackOnHit: 100,
    distanceToWalkBackOnHit: 10,
    hasCloned: false
    };
    };

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

    if (
    (foundByClone && robot.parentId == null)
    ||
    (foundByParent && robot.parentId != null)
    ){
    var deltaX = Math.abs(robot.position.x - foundRobotPosition.x);
    var deltaY = Math.abs(robot.position.y - foundRobotPosition.y);
    var angle = Math.atan(deltaY / deltaX);
    console.log(angle);
    foundByClone = false;
    foundByParent = false;
    }
    robot.rotateCannon(1);
    robot.ahead(1);
    };

    Robot.prototype.onScannedRobot = function(ev) {
    ev.robot.stop();
    /* var robot = ev.robot, scanned = ev.scannedRobot;
    var robot = ev.robot, scanned = ev.scannedRobot;

    foundRobotPosition = scanned.position;
    if (robot.parentId == null) {
    foundByParent = true;
    } else {
    foundByClone = true;
    }

    if (scanned.parentId != null ||
    robot.parentId == scanned.id ||
    robot.id == scanned.parentId){
    @@ -33,7 +56,6 @@ Robot.prototype.onScannedRobot = function(ev) {
    robot.ahead(10);
    robot.rotateCannon(-1);
    }
    */
    };

    Robot.prototype.onWallCollision = function(ev) {
    @@ -42,8 +64,6 @@ Robot.prototype.onWallCollision = function(ev) {
    };

    Robot.prototype.onRobotCollision = function(ev) {
    //ev.robot.turn(ev.bearing);
    //ev.robot.back(this.options.distanceToWalkBackOnHit);
    };

    Robot.prototype.onHitByBullet = function(ev) {
  3. heynemann revised this gist Dec 5, 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
    @@ -18,6 +18,7 @@ Robot.prototype.onIdle = function(ev) {
    };

    Robot.prototype.onScannedRobot = function(ev) {
    ev.robot.stop();
    /* var robot = ev.robot, scanned = ev.scannedRobot;
    if (scanned.parentId != null ||
    @@ -36,6 +37,7 @@ Robot.prototype.onScannedRobot = function(ev) {
    };

    Robot.prototype.onWallCollision = function(ev) {
    ev.robot.turn(180);
    ev.robot.back(this.options.distanceToWalkBackOnHit);
    };

  4. heynemann revised this gist Dec 5, 2012. No changes.
  5. heynemann revised this gist Dec 5, 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
    @@ -13,6 +13,7 @@ var Robot = function(robot){

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

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

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

    if (!this.options.hasCloned) {
    robot.clone();
    this.options.hasCloned = true;
    }
    robot.ahead(this.options.aheadWhileTurning);
    robot.rotateCannon(1);
    robot.fire();
    };

    Robot.prototype.onScannedRobot = function(ev) {
    var robot = ev.robot, scanned = ev.scannedRobot;
    /* var robot = ev.robot, scanned = ev.scannedRobot;
    if (scanned.parentId != null ||
    robot.parentId == scanned.id ||
    @@ -34,18 +28,19 @@ Robot.prototype.onScannedRobot = function(ev) {
    for (var i=0; i < this.options.shootIterations; i++) {
    robot.fire();
    robot.ahead(1);
    robot.ahead(10);
    robot.rotateCannon(-1);
    }
    */
    };

    Robot.prototype.onWallCollision = function(ev) {
    ev.robot.back(this.options.distanceToWalkBackOnHit);
    };

    Robot.prototype.onRobotCollision = function(ev) {
    ev.robot.turn(ev.bearing);
    ev.robot.back(this.options.distanceToWalkBackOnHit);
    //ev.robot.turn(ev.bearing);
    //ev.robot.back(this.options.distanceToWalkBackOnHit);
    };

    Robot.prototype.onHitByBullet = function(ev) {
  7. heynemann revised this gist Dec 5, 2012. 1 changed file with 4 additions and 5 deletions.
    9 changes: 4 additions & 5 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -4,9 +4,9 @@ var Robot = function(robot){
    //robot.ignore('onRobotCollision');
    this.options = {
    direction: 1,
    aheadWhileTurning: 1,
    shootIterations: 10,
    distanceToWalkBackOnHit: 50,
    aheadWhileTurning: 3,
    shootIterations: 5,
    distanceToWalkBackOnHit: 100,
    hasCloned: false
    };
    };
    @@ -18,8 +18,8 @@ Robot.prototype.onIdle = function(ev) {
    robot.clone();
    this.options.hasCloned = true;
    }
    robot.turn(this.options.direction);
    robot.ahead(this.options.aheadWhileTurning);
    robot.rotateCannon(1);
    };

    Robot.prototype.onScannedRobot = function(ev) {
    @@ -32,7 +32,6 @@ Robot.prototype.onScannedRobot = function(ev) {
    }
    //this.options.direction = (scanned.angle > 180) ? 1 : -1;

    robot.rotateCannon(-5);
    for (var i=0; i < this.options.shootIterations; i++) {
    robot.fire();
    robot.ahead(1);
  8. heynemann revised this gist Dec 5, 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
    @@ -32,9 +32,10 @@ Robot.prototype.onScannedRobot = function(ev) {
    }
    //this.options.direction = (scanned.angle > 180) ? 1 : -1;

    robot.rotateCannon(-20);
    robot.rotateCannon(-5);
    for (var i=0; i < this.options.shootIterations; i++) {
    robot.fire();
    robot.ahead(1);
    robot.rotateCannon(-1);
    }
    };
  9. heynemann revised this gist Dec 5, 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
    @@ -35,8 +35,7 @@ Robot.prototype.onScannedRobot = function(ev) {
    robot.rotateCannon(-20);
    for (var i=0; i < this.options.shootIterations; i++) {
    robot.fire();
    robot.back(10);
    robot.rotateCannon(1);
    robot.rotateCannon(-1);
    }
    };

  10. heynemann revised this gist Dec 5, 2012. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@ var Robot = function(robot){
    this.options = {
    direction: 1,
    aheadWhileTurning: 1,
    shootIterations: 4,
    shootIterations: 10,
    distanceToWalkBackOnHit: 50,
    hasCloned: false
    };
    @@ -32,10 +32,11 @@ Robot.prototype.onScannedRobot = function(ev) {
    }
    //this.options.direction = (scanned.angle > 180) ? 1 : -1;

    robot.rotateCannon(-20);
    for (var i=0; i < this.options.shootIterations; i++) {
    robot.fire();
    robot.turn(-10);
    robot.back(10);
    robot.rotateCannon(1);
    }
    };

  11. heynemann 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
    @@ -5,7 +5,7 @@ var Robot = function(robot){
    this.options = {
    direction: 1,
    aheadWhileTurning: 1,
    shootIterations: 2,
    shootIterations: 4,
    distanceToWalkBackOnHit: 50,
    hasCloned: false
    };
  12. heynemann 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
    @@ -32,7 +32,7 @@ Robot.prototype.onScannedRobot = function(ev) {
    }
    //this.options.direction = (scanned.angle > 180) ? 1 : -1;

    for (var i=0; i<this.options.shootIterations; i++) {
    for (var i=0; i < this.options.shootIterations; i++) {
    robot.fire();
    robot.turn(-10);
    robot.back(10);
  13. heynemann 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
    @@ -32,7 +32,7 @@ Robot.prototype.onScannedRobot = function(ev) {
    }
    //this.options.direction = (scanned.angle > 180) ? 1 : -1;

    for (var i=0; i < this.options.shootIterations; i++) {
    for (var i=0; i<this.options.shootIterations; i++) {
    robot.fire();
    robot.turn(-10);
    robot.back(10);
  14. heynemann 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
    @@ -32,7 +32,7 @@ Robot.prototype.onScannedRobot = function(ev) {
    }
    //this.options.direction = (scanned.angle > 180) ? 1 : -1;

    for (var i=0; i <= this.options.shootIterations; i++) {
    for (var i=0; i < this.options.shootIterations; i++) {
    robot.fire();
    robot.turn(-10);
    robot.back(10);
  15. heynemann revised this gist Dec 5, 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
    @@ -32,10 +32,10 @@ Robot.prototype.onScannedRobot = function(ev) {
    }
    //this.options.direction = (scanned.angle > 180) ? 1 : -1;

    robot.rotateCannon(10);
    for (var i=0; i<this.options.shootIterations; i++) {
    for (var i=0; i <= this.options.shootIterations; i++) {
    robot.fire();
    robot.ahead(10);
    robot.turn(-10);
    robot.back(10);
    }
    };

  16. heynemann revised this gist Dec 5, 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
    @@ -32,10 +32,10 @@ Robot.prototype.onScannedRobot = function(ev) {
    }
    //this.options.direction = (scanned.angle > 180) ? 1 : -1;

    robot.rotateCannon(10);
    for (var i=0; i<this.options.shootIterations; i++) {
    robot.fire();
    robot.turn(-10);
    robot.back(10);
    robot.ahead(10);
    }
    };

  17. heynemann revised this gist Dec 5, 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,7 +5,7 @@ var Robot = function(robot){
    this.options = {
    direction: 1,
    aheadWhileTurning: 1,
    shootIterations: 10,
    shootIterations: 2,
    distanceToWalkBackOnHit: 50,
    hasCloned: false
    };
    @@ -34,8 +34,8 @@ Robot.prototype.onScannedRobot = function(ev) {

    for (var i=0; i<this.options.shootIterations; i++) {
    robot.fire();
    robot.turn(10);
    robot.turn(-10);
    robot.back(10);
    }
    };

  18. heynemann revised this gist Dec 5, 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
    @@ -5,7 +5,7 @@ var Robot = function(robot){
    this.options = {
    direction: 1,
    aheadWhileTurning: 1,
    shootIterations: 100,
    shootIterations: 10,
    distanceToWalkBackOnHit: 50,
    hasCloned: false
    };
    @@ -35,7 +35,6 @@ Robot.prototype.onScannedRobot = function(ev) {
    for (var i=0; i<this.options.shootIterations; i++) {
    robot.fire();
    robot.turn(10);
    robot.ahead(20);
    robot.turn(-10);
    }
    };
  19. heynemann 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
    @@ -34,6 +34,9 @@ Robot.prototype.onScannedRobot = function(ev) {

    for (var i=0; i<this.options.shootIterations; i++) {
    robot.fire();
    robot.turn(10);
    robot.ahead(20);
    robot.turn(-10);
    }
    };

  20. heynemann revised this gist Dec 4, 2012. No changes.
  21. heynemann revised this gist Dec 4, 2012. No changes.
  22. heynemann revised this gist Dec 4, 2012. 1 changed file with 1 addition and 4 deletions.
    5 changes: 1 addition & 4 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@ var Robot = function(robot){
    this.options = {
    direction: 1,
    aheadWhileTurning: 1,
    shootIterations: 5,
    shootIterations: 100,
    distanceToWalkBackOnHit: 50,
    hasCloned: false
    };
    @@ -34,9 +34,6 @@ Robot.prototype.onScannedRobot = function(ev) {

    for (var i=0; i<this.options.shootIterations; i++) {
    robot.fire();
    robot.rotateCannon(2);
    robot.ahead(3);
    robot.rotateCannon(-2);
    }
    };

  23. heynemann revised this gist Dec 4, 2012. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@ var Robot = function(robot){
    direction: 1,
    aheadWhileTurning: 1,
    shootIterations: 5,
    distanceToWalkBackOnHit: 100,
    distanceToWalkBackOnHit: 50,
    hasCloned: false
    };
    };
    @@ -45,9 +45,10 @@ Robot.prototype.onWallCollision = function(ev) {
    };

    Robot.prototype.onRobotCollision = function(ev) {
    ev.robot.turn(ev.bearing);
    ev.robot.back(this.options.distanceToWalkBackOnHit);
    };

    Robot.prototype.onHitByBullet = function(ev) {
    ev.robot.rotateCannon(ev.bearing);
    ev.robot.turn(ev.bearing);
    };
  24. heynemann 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
    @@ -6,7 +6,7 @@ var Robot = function(robot){
    direction: 1,
    aheadWhileTurning: 1,
    shootIterations: 5,
    distanceToWalkBackOnHit: 50,
    distanceToWalkBackOnHit: 100,
    hasCloned: false
    };
    };
    @@ -45,10 +45,9 @@ Robot.prototype.onWallCollision = function(ev) {
    };

    Robot.prototype.onRobotCollision = function(ev) {
    ev.robot.turn(ev.bearing);
    ev.robot.back(this.options.distanceToWalkBackOnHit);
    };

    Robot.prototype.onHitByBullet = function(ev) {
    ev.robot.turn(ev.bearing);
    ev.robot.rotateCannon(ev.bearing);
    };
  25. heynemann revised this gist Dec 4, 2012. 1 changed file with 13 additions and 3 deletions.
    16 changes: 13 additions & 3 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -1,25 +1,35 @@

    //FightCode can only understand your robot
    //if its class is called Robot
    var Robot = function(robot){
    //robot.ignore('onRobotCollision');
    this.options = {
    direction: 1,
    aheadWhileTurning: 4,
    aheadWhileTurning: 1,
    shootIterations: 5,
    distanceToWalkBackOnHit: 100
    distanceToWalkBackOnHit: 50,
    hasCloned: false
    };
    };

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

    if (!this.options.hasCloned) {
    robot.clone();
    this.options.hasCloned = true;
    }
    robot.turn(this.options.direction);
    robot.ahead(this.options.aheadWhileTurning);
    };

    Robot.prototype.onScannedRobot = function(ev) {
    var robot = ev.robot, scanned = ev.scannedRobot;

    if (scanned.parentId != null ||
    robot.parentId == scanned.id ||
    robot.id == scanned.parentId){
    return;
    }
    //this.options.direction = (scanned.angle > 180) ? 1 : -1;

    for (var i=0; i<this.options.shootIterations; i++) {
  26. heynemann revised this gist Dec 4, 2012. 1 changed file with 9 additions and 7 deletions.
    16 changes: 9 additions & 7 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -4,37 +4,39 @@
    var Robot = function(robot){
    //robot.ignore('onRobotCollision');
    this.options = {
    direction: 1
    direction: 1,
    aheadWhileTurning: 4,
    shootIterations: 5,
    distanceToWalkBackOnHit: 100
    };
    };

    Robot.prototype.onIdle = function(ev) {
    var robot = ev.robot;
    robot.turn(this.options.direction);
    robot.ahead(1);
    robot.ahead(this.options.aheadWhileTurning);
    };

    Robot.prototype.onScannedRobot = function(ev) {
    var robot = ev.robot, scanned = ev.scannedRobot;

    //this.options.direction = (scanned.angle > 180) ? 1 : -1;

    for (var i=0; i<5; i++) {
    for (var i=0; i<this.options.shootIterations; i++) {
    robot.fire();
    robot.rotateCannon(2);
    robot.ahead(5);
    robot.ahead(3);
    robot.rotateCannon(-2);
    }
    };

    Robot.prototype.onWallCollision = function(ev) {
    ev.robot.back(50);
    ev.robot.turn(1);
    ev.robot.back(this.options.distanceToWalkBackOnHit);
    };

    Robot.prototype.onRobotCollision = function(ev) {
    ev.robot.turn(ev.bearing);
    ev.robot.back(20);
    ev.robot.back(this.options.distanceToWalkBackOnHit);
    };

    Robot.prototype.onHitByBullet = function(ev) {
  27. heynemann revised this gist Dec 4, 2012. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -17,8 +17,8 @@ Robot.prototype.onIdle = function(ev) {
    Robot.prototype.onScannedRobot = function(ev) {
    var robot = ev.robot, scanned = ev.scannedRobot;

    this.options.direction = (scanned.angle > 180) ? 1 : -1;
    //this.options.direction = (scanned.angle > 180) ? 1 : -1;

    for (var i=0; i<5; i++) {
    robot.fire();
    robot.rotateCannon(2);
    @@ -28,7 +28,8 @@ Robot.prototype.onScannedRobot = function(ev) {
    };

    Robot.prototype.onWallCollision = function(ev) {
    ev.robot.turn(10);
    ev.robot.back(50);
    ev.robot.turn(1);
    };

    Robot.prototype.onRobotCollision = function(ev) {
  28. heynemann revised this gist Dec 4, 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
    @@ -11,6 +11,7 @@ var Robot = function(robot){
    Robot.prototype.onIdle = function(ev) {
    var robot = ev.robot;
    robot.turn(this.options.direction);
    robot.ahead(1);
    };

    Robot.prototype.onScannedRobot = function(ev) {
  29. heynemann 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
    @@ -20,7 +20,9 @@ Robot.prototype.onScannedRobot = function(ev) {

    for (var i=0; i<5; i++) {
    robot.fire();
    robot.ahead(15);
    robot.rotateCannon(2);
    robot.ahead(5);
    robot.rotateCannon(-2);
    }
    };

  30. heynemann revised this gist Dec 3, 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
    @@ -16,7 +16,7 @@ Robot.prototype.onIdle = function(ev) {
    Robot.prototype.onScannedRobot = function(ev) {
    var robot = ev.robot, scanned = ev.scannedRobot;

    this.options.direction = (scanned.angle > 180) ? -1 : 1;
    this.options.direction = (scanned.angle > 180) ? 1 : -1;

    for (var i=0; i<5; i++) {
    robot.fire();