コード例 #1
0
 private static void moveSomewhere() throws GameActionException {
   while (!defendQueue.isEmpty()) {
     int next = defendQueue.element();
     if (teamMemberNeedsHelp[next] > 0 && rc.getRoundNum() - teamMemberNeedsHelp[next] < 200) {
       if (rc.isCoreReady()) {
         Nav.goTo(teamLocations[next]);
       }
       return;
     }
     defendQueue.remove();
   }
   if (!moveQueue.isEmpty()) {
     MapLocation next = moveQueue.element();
     if (rc.isCoreReady()) {
       Nav.goTo(next);
     }
     if (rc.canSense(next) && rc.senseRobotAtLocation(next) == null) {
       moveQueue.remove();
     }
     return;
   }
   if (rc.isCoreReady()) {
     Nav.goTo(personalHQ);
     return;
   }
 }
コード例 #2
0
  private static void action() throws GameActionException {
    processSignals();
    switch (strategy) {
      case -1:
        int channel = Radio.getTuneCommand();
        if (channel == 30) {
          strategy = Radio.getStrategyAssignment();
        }
        break;
      default:
        break;
    }
    if (rc.getType() == RobotType.TURRET) {
      RobotInfo[] visibleEnemyArray = rc.senseHostileRobots(rc.getLocation(), 1000000);
      ArrayList<MapLocation> enemyArrayList = new ArrayList<MapLocation>();
      while (!Radio.enemySignal.isEmpty()) {
        enemyArrayList.add(Radio.enemySignal.remove().location);
      }
      for (RobotInfo enemyRI : visibleEnemyArray) {
        enemyArrayList.add(enemyRI.location);
      }

      IdAndMapLocation scoutInstruction = Radio.getTurretAttack();
      while (scoutInstruction != null) {
        enemyArrayList.add(scoutInstruction.location);
        scoutInstruction = Radio.getTurretAttack();
      }

      MapLocation[] enemyArray = new MapLocation[enemyArrayList.size()];

      for (int i = 0; i < enemyArrayList.size(); i++) {
        enemyArray[i] = enemyArrayList.get(i);
      }

      if (enemyArray.length > 0) {
        if (rc.isWeaponReady()) {
          // look for adjacent enemies to attack
          for (MapLocation oneEnemy : enemyArray) {
            if (rc.canAttackLocation(oneEnemy)) {
              rc.setIndicatorString(0, "trying to attack");
              rc.attackLocation(oneEnemy);
              break;
            }
          }
        }
        // could not find any enemies adjacent to attack
        // try to move toward them
        if (rc.isCoreReady()) {
          MapLocation goal = enemyArray[0];
          Direction toEnemy = rc.getLocation().directionTo(goal);
          if (strategy == 1) {
            rc.pack();
          }
        }
      } else { // there are no enemies nearby
        // check to see if we are in the way of friends
        // we are obstructing them
        if (rc.isCoreReady()) {
          RobotInfo[] nearbyFriends = rc.senseNearbyRobots(2, rc.getTeam());
          if (nearbyFriends.length > 3) {
            Direction away = randomDirection();
            if (strategy == 1) {
              rc.pack();
            }
          }
        }
      }
    } else {
      RobotInfo[] visibleEnemyArray = rc.senseHostileRobots(rc.getLocation(), 1000000);
      ArrayList<MapLocation> enemyArrayList = new ArrayList<MapLocation>();
      while (!Radio.enemySignal.isEmpty()) {
        enemyArrayList.add(Radio.enemySignal.remove().location);
      }
      for (RobotInfo enemyRI : visibleEnemyArray) {
        enemyArrayList.add(enemyRI.location);
      }
      MapLocation[] enemyArray = new MapLocation[enemyArrayList.size()];

      for (int i = 0; i < enemyArrayList.size(); i++) {
        enemyArray[i] = enemyArrayList.get(i);
      }

      if (enemyArray.length > 0) {
        rc.unpack();
        // could not find any enemies adjacent to attack
        // try to move toward them
        if (rc.isCoreReady()) {
          MapLocation goal = enemyArray[0];
          Nav.goTo(goal);
        }
      } else {
        if (strategy == 1) {
          moveSomewhere();
        }
      }
    }
  }