├── README.md └── gunther.js /README.md: -------------------------------------------------------------------------------- 1 | # README 2 | 3 | This is the code for my tank bots competing at 4 | [FightCode](http://fightcodegame.com). 5 | 6 | ## License 7 | 8 | Distributed under terms of the MIT license. 9 | -------------------------------------------------------------------------------- /gunther.js: -------------------------------------------------------------------------------- 1 | 2 | var MIN_LIFE_ACHTUNG = 65; 3 | var FIRE_ROUND = 5; 4 | var ROBOT_ID = null; 5 | 6 | 7 | var Robot = function(r) { 8 | ROBOT_ID = r.id; 9 | this.max_advance = Math.min(r.arenaWidth, r.arenaHeight) / 3; 10 | this.gone_ahead = 0; 11 | this.rlsign = 1; 12 | }; 13 | 14 | Robot.prototype.advance = function(r, amount) { 15 | if (this.gone_ahead >= this.max_advance) { 16 | this.gone_ahead = 0; 17 | r.turn(40); 18 | } 19 | this.gone_ahead += amount; 20 | r.ahead(amount); 21 | }; 22 | 23 | 24 | Robot.prototype.onIdle = function(ev) { 25 | var r = ev.robot; 26 | 27 | if (r.life <= MIN_LIFE_ACHTUNG) { 28 | if (r.availableClones > 0) { 29 | r.clone(); 30 | } 31 | if (r.availableDisappears > 0) { 32 | r.disappear(); 33 | } 34 | } 35 | 36 | r.turn((this.x % 3 - 1) * 30); 37 | this.advance(r, this.max_advance / 2); 38 | this.rlsign = -this.rlsign; 39 | r.rotateCannon(this.rlsign * 360); 40 | }; 41 | 42 | Robot.prototype.onRobotCollision = function(ev) { 43 | var r = ev.robot; 44 | 45 | r.stop(); 46 | 47 | // Try to turn the turret to the other robot and fire, if it's an enemy 48 | if (ev.collidedRobot.id != r.parentId && ev.collidedRobot.id != ROBOT_ID) { 49 | r.rotateCannon(ev.collidedRobot.bearing); 50 | } 51 | 52 | if (ev.collidedRobot.cannonAngle < 0) { 53 | this.turnLeft(90); 54 | } else { 55 | this.turnRight(90); 56 | } 57 | this.advance(r, this.max_advance / 2); 58 | }; 59 | 60 | 61 | Robot.prototype.onWallCollision = function(ev) { 62 | var r = ev.robot; 63 | r.stop(); 64 | r.back(this.max_advance / 5); 65 | r.turn(90 + ev.bearing); 66 | }; 67 | 68 | 69 | Robot.prototype.onHitByBullet = function(ev) { 70 | var r = ev.robot; 71 | r.stop(); 72 | r.rotateCannon(ev.bearing); 73 | r.back(this.max_advance / 5); 74 | }; 75 | 76 | 77 | Robot.prototype.onScannedRobot = function(ev) { 78 | var r = ev.robot; 79 | if (ev.scannedRobot.id != r.parentId && ev.scannedRobot.id != ROBOT_ID) { 80 | r.stop(); 81 | var n = 5; 82 | while (n--) r.fire(); 83 | } 84 | }; 85 | 86 | --------------------------------------------------------------------------------