Azymoove Help

Example robot

The editor's starting robot, complete, in every language.

This is the code every new robot starts with. It locks the radar on the enemy, aims by turning the body, strafes to dodge, recharges when energy runs low and runs from the arena’s edge. Use it as a starting point and change one thing at a time, testing after each change.

// Locks the radar on the enemy, aims by turning the body and strafes to dodge.
class Tracker extends Robot {
  // The body decides how the robot moves (see Documentation → Bodies and parts):
  // legs strafe, wheels race, treads endure, spiders grip the edge.

  // Parts: weapon, armor, head and torso. Budget: 12 points.

  constructor() {
    super({body: "forca", parts: {"weapon": "railgun", "head": "pesquisador.head"}});
    this.side = 1;
  }

  /** @param {State} state */
  run() {
    while (true) {
      const state = this.scan();
      const me = state.me;
      if (me.charging || me.energy < 20) { this.recharge(); continue; }
      const target = state.scanned[0];

      // Get away from the lava before anything else.
      if (me.distanceToEdge < 8) {
        this.turn(me.centerBearing);
        this.move(Math.abs(me.centerBearing) < 0.4 ? 5 : 0);
        continue;
      }

      if (target) {
        this.turnRadar(target.radarBearing * 2);
        // The gun is on the arm: aiming means turning the body.
        this.turn(target.bearing);
        if (Math.abs(target.bearing) < 0.05 && me.gunHeat === 0) {
          this.fire(target.distance < 15 ? 3 : 1.5);
        }
        // Strafes without losing the aim; switches sides when hit.
        if (state.events.some((e) => e.type === "hitByBullet")) this.side = -this.side;
        this.strafe(this.side * 4);
        if (target.distance < 4.8) this.punch();
      } else {
        this.turnRadar(1);
        this.turn(0.05);
        this.move(3);
      }
    }
  }
}