Azymoove Help

run() and scan()

How your robot's code runs: your own loop, one turn per scan().

A robot is a class that extends Robot. The game calls run() only once, when the battle starts: the loop is yours. Inside it, scan() ends the turn (there are 30 per second) and returns the state with everything the robot knows at that moment.

class MyRobot extends Robot {
  run() {
    while (true) {
      const state = this.scan();
      if (state.scanned.length > 0) {
        const enemy = state.scanned[0];
        this.turn(enemy.bearing);
        this.fire(1);
      } else {
        this.turnRadar(1);
      }
    }
  }
}

Commands ask, the turn does

Commands (move, turn, turnRadar, fire…) ask for an action. It happens when the turn ends, at scan(). A command holds until it’s replaced: if you ask for move(10), the robot keeps moving what’s left over the next turns.

Some commands wait until they’re done and only return when the action is over, passing the turns by themselves:

  • walk(distance): moves and waits to arrive.
  • rotate(angle): turns the body and waits until it’s done.
  • walkTo(x, z): navigates to the point and waits to arrive (or give up).
  • wait(n): lets n turns go by.

Use turn + scan() when you want to react every turn, and rotate when you want to finish turning before you shoot.

Angles

Angles are in radians; positive values turn counterclockwise. The enemies the radar sees come with the angle ready for aiming: this.turn(enemy.bearing) points the gun at them, because the gun is on the arm and shoots where the body points.

Watch out

  • A turn that takes more than 1 second until the next scan() disqualifies the robot (for example, an endless loop with no scan()).
  • To skip the rest of a turn, use continue (Ruby: next). return ends run(), and the robot stands still for the rest of the battle.