示例#1
0
  // Launch a missile if there is an enemy in sight.
  // We ignore other missiles
  private static void doLaunch() {
    int count = rc.getMissileCount();
    if (count > 0 && Clock.getRoundNum() % 2 == 0) {
      MapLocation launchFrom; // We can launch 1 tile towards the enemy
      MapLocation explodeAt; // We can explode adjacent to the enemy (1 tile towards us)
      int missileRange = 30;
      RobotInfo[] enemies = rc.senseNearbyRobots(49, enemyTeam);
      MapLocation target = null;
      for (RobotInfo r : enemies) {
        if (r.type != RobotType.MISSILE) { // Ignore missiles
          launchFrom = myLoc.add(myLoc.directionTo(r.location));
          explodeAt = r.location.add(r.location.directionTo(myLoc));
          if (launchFrom.distanceSquaredTo(explodeAt) <= missileRange) {
            target = r.location;
            break;
          }
        }
      }
      if (target == null) { // Check for towers
        for (MapLocation t : threats.enemyTowers) {
          launchFrom = myLoc.add(myLoc.directionTo(t));
          explodeAt = t.add(t.directionTo(myLoc));
          if (launchFrom.distanceSquaredTo(explodeAt) <= missileRange) {
            target = t;
            break;
          }
        }

        if (target == null) { // Check for HQ
          MapLocation ehq = threats.enemyHQ;
          launchFrom = myLoc.add(myLoc.directionTo(ehq));
          explodeAt = ehq.add(ehq.directionTo(myLoc));
          if (launchFrom.distanceSquaredTo(explodeAt) <= missileRange) target = ehq;
        }
      }
      if (target != null) {
        try {
          Direction d = myLoc.directionTo(target);

          if (rc.canLaunch(d)) {
            rc.launchMissile(d);
          }
        } catch (GameActionException e) {
          System.out.println("Launch exception");
          e.printStackTrace();
        }
      }
    }
  }
示例#2
0
  // If our tile is threatened we should retreat unless the enemy is quicker than us
  // If the enemy can advance and fire before we can move away we might as well stand and fight
  private static boolean shouldRetreat() {
    if (myType == RobotType.LAUNCHER && rc.getMissileCount() == 0) return true;

    return threats.isThreatened(myLoc) || threats.inMissileRange();
  }