Example #1
0
  /**
   * Code to run every turn.
   *
   * @param rc
   */
  static void runBefore(RobotController rc) throws GameActionException {
    // -2 for build signals
    Signals.maxMessages = GameConstants.MESSAGE_SIGNALS_PER_TURN - 2;
    read = Signals.readSignals(rc);
    sent = 0;
    int turn = rc.getRoundNum();

    switch (turn - enrollment) {
      case 0:
        if (targetType != null && Signals.targetsSize > 0) {
          models.addFirst(new Target(targetType, Signals.targets[0]));
        }
        break;
      case 1:
        for (int i = 0; i < sqrt.length; ++i) sqrt[i] = Math.sqrt(i);
        break;
      case 2:
        // Sense rubble a little after construction
        // TODO: change to 3(?) to avoid overlapping with action
        senseRubble(rc);
        break;
      default:
        break;
    }

    if (canMessageSignal) {
      sendRadius = 2 * sightRadius;
      sendBoundariesLow = false;
      sendBoundariesHigh = false;
      senseParts(rc);
    }

    updateMap(rc);
    if (turn > 5) {
      robotInfos = rc.senseNearbyRobots();
      for (RobotInfo info : robotInfos) {
        addInfo(info);
      }
    }
  }