Exemple #1
0
  /**
   * Returns true if the given power is a member of the displayble powers group, <b>or</b> the
   * TurnState is resolved (and orders for all powers can be shown)
   */
  public static boolean isDisplayable(final Power power, final MapInfo mapInfo) {
    if (mapInfo.getTurnState().isResolved()) {
      return true;
    }

    final Power[] displayedPowers = mapInfo.getDisplayablePowers();
    for (int i = 0; i < displayedPowers.length; i++) {
      if (displayedPowers[i] == power) {
        return true;
      }
    }

    return false;
  } // isDisplayable()
Exemple #2
0
  /**
   * Given a TurnState, determines if any order exists that matches the given Hold order. Returns
   * null if no matching Hold order found.
   */
  public static Hold findMatchingHold(MapInfo mapInfo, Province src) {
    Power[] powers = mapInfo.getDisplayablePowers();
    for (int i = 0; i < powers.length; i++) {
      List<Orderable> orders = mapInfo.getTurnState().getOrders(powers[i]);
      Iterator<Orderable> iter = orders.iterator();
      while (iter.hasNext()) {
        Orderable o = iter.next();
        if (o instanceof Hold && o.getSource().isProvinceEqual(src)) {
          return (Hold) o;
        }
      }
    }

    return null;
  } // findMatchingHold()
Exemple #3
0
  /**
   * Given a TurnState, determines if any order exists that matches the given Move order. Returns
   * null if no matching Move order found.
   */
  public static Move findMatchingMove(MapInfo mapInfo, Province src, Province dest) {
    Power[] powers = mapInfo.getDisplayablePowers();
    for (int i = 0; i < powers.length; i++) {
      List<Orderable> orders = mapInfo.getTurnState().getOrders(powers[i]);
      Iterator<Orderable> iter = orders.iterator();
      while (iter.hasNext()) {
        Orderable o = iter.next();
        if (o instanceof Move) {
          Move mv = (Move) o;
          if (mv.getSource().isProvinceEqual(src) && mv.getDest().isProvinceEqual(dest)) {
            return mv;
          }
        }
      }
    }

    return null;
  } // findMatchingMove()
Exemple #4
0
  /**
   * Given a TurnState, determines if the number (if any) of . Support orders that match the given
   * Move or Hold order. (use src == dest for Hold orders)
   *
   * <p>Note that only the displayable powers are used to check the support.
   */
  public static int getMatchingSupportCount(MapInfo mapInfo, Province supSrc, Province supDest) {
    int count = 0;

    Power[] powers = mapInfo.getDisplayablePowers();
    for (int i = 0; i < powers.length; i++) {
      List<Orderable> orders = mapInfo.getTurnState().getOrders(powers[i]);
      Iterator<Orderable> iter = orders.iterator();
      while (iter.hasNext()) {
        Orderable o = iter.next();
        if (o instanceof Support) {
          Support sup = (Support) o;
          if (sup.getSupportedSrc().isProvinceEqual(supSrc)
              && sup.getSupportedDest().isProvinceEqual(supDest)) {
            count++;
          }
        }
      }
    }

    return count;
  } // findMatchingSupports()