Пример #1
0
  public static RobotInfo[] getRobotsCloserToUs(
      RobotInfo[] robots, RobotInfo[] nearbyFriendlies, RobotInfo[] nearbyEnemies) {
    int length = robots.length;
    int index[] = new int[length];
    for (int i = 0; i < length; i++) {
      index[i] = -1;
    }

    int count = 0;
    for (int i = 0; i < length; i++) {
      int ourDistance = RobotUtil.getShortestDistance(robots[i], nearbyFriendlies);
      int theirDistance = RobotUtil.getShortestDistance(robots[i], nearbyEnemies);
      if (ourDistance <= theirDistance) {
        index[i] = count++;
      }
    }

    RobotInfo[] closerToUs = new RobotInfo[count];
    for (int i = 0; i < length; i++) {
      if (index[i] == -1) {
        continue;
      }

      closerToUs[index[i]] = robots[i];
    }

    return closerToUs;
  }
Пример #2
0
  public static RobotInfo[] removeRobots(RobotInfo[] robots, RobotData[] robotsToRemove) {
    int removeCount = 0;
    int robotCount = robots.length;
    for (int i = 0; i < robotCount; i++) {
      if (RobotUtil.robotInCollection(robots[i], robotsToRemove)) {
        removeCount++;
      }
    }

    int newCount = robotCount - removeCount;
    RobotInfo[] trimmed = new RobotInfo[newCount];
    int index = 0;
    for (int i = 0; i < robotCount; i++) {
      if (!RobotUtil.robotInCollection(robots[i], robotsToRemove)) {
        trimmed[index++] = robots[i];
      }
    }

    return trimmed;
  }
Пример #3
0
  public static int countCanAttack(
      RobotInfo[] nearbyFriendlies, BoundedQueue<RobotInfo> enemiesCanAttackMe) {
    int canAttack = 0;
    for (int i = 0; i < nearbyFriendlies.length; i++) {
      if (RobotUtil.canAttackAny(nearbyFriendlies[i], enemiesCanAttackMe)) {
        canAttack++;
      }
    }

    return canAttack;
  }
Пример #4
0
  public static RobotInfo getHighestPriorityEnemyUnit(RobotInfo[] enemies) {
    int highestPriority = -1;
    int enemyCount = enemies.length;
    RobotInfo highestRobot = null;
    for (int i = 0; i < enemyCount; i++) {
      int currentPriority = RobotUtil.getPriority(enemies[i].type);
      if (currentPriority > highestPriority) {
        highestPriority = currentPriority;
        highestRobot = enemies[i];
      }
    }

    return highestRobot;
  }