Beispiel #1
0
  /**
   * This method finds the adjacent opponent states of a country
   *
   * @param countryID The ID of the country which we want to find its neighboring states
   * @return List of neighbouring states
   */
  public ArrayList<State> getAdjacentOpponentStates(int countryID) {
    ArrayList<State> ownStates = new ArrayList<State>();
    ArrayList<State> opponentStates = new ArrayList<State>();
    ownStates = getStatesByCountryID(countryID);

    for (State myState : ownStates) {
      // Checking if the source state is our state
      for (Link tempLink : this.myLinkList) {
        if (tempLink.getSourceState().getStateID() == myState.getStateID())
          // Check if adjacent state is an opponent state
          if (tempLink.getDestintionState().getCountryID() != countryID)
            opponentStates.add(tempLink.getDestintionState());
      }
      // Checking if the destination state is our state
      for (Link tempLink : this.myLinkList) {
        if (tempLink.getDestintionState().getStateID() == myState.getStateID())
          // Check if adjacent state is an opponent state
          if (tempLink.getSourceState().getCountryID() != countryID)
            opponentStates.add(tempLink.getSourceState());
      }
    }

    // Creating a hashset to remove duplicate states
    HashSet stateHashSet = new HashSet(opponentStates);
    opponentStates.clear();
    opponentStates = new ArrayList(stateHashSet);

    return opponentStates;
  }
Beispiel #2
0
  /**
   * This method finds the adjacent states of a specific state
   *
   * @param myState The state which we want to find its neighbors
   * @param mode 0 for all adjacent states, 1 for all own adjacent states, 2 for all opponent
   *     adjacent states
   * @return List of adjacent states of our state
   */
  public ArrayList<State> getAdjacentStatesOfState(State myState, byte mode) {
    ArrayList<State> stateList = new ArrayList<State>();

    for (Link tempLink : this.getMyLinkList()) {
      // Checking destination state of the links
      if (tempLink.getSourceState().getStateID() == myState.getStateID()) {
        for (State tempState : this.getMyStateList()) {
          if (tempState.getStateID() == tempLink.getDestintionState().getStateID()) {
            if (mode == 0) {
              // stateList.add(tempLink.getDestintionState());
              stateList.add(tempState);
              break;
            } else if (mode == 1) {
              if (tempState.getCountryID() == tempLink.getSourceState().getCountryID()) {
                // stateList.add(tempLink.getDestintionState());
                stateList.add(tempState);
                break;
              }
            } else if (mode == 2) {
              if (tempState.getCountryID() != tempLink.getSourceState().getCountryID()) {
                // stateList.add(tempLink.getDestintionState());
                stateList.add(tempState);
                break;
              }
            }
          }
        }
      }
      // Checking source state of the links
      if (tempLink.getDestintionState().getStateID() == myState.getStateID()) {
        for (State tempState : this.getMyStateList()) {
          if (tempState.getStateID() == tempLink.getSourceState().getStateID()) {
            if (mode == 0) {
              // stateList.add(tempLink.getSourceState());
              stateList.add(tempState);
              break;
            } else if (mode == 1) {
              if (tempState.getCountryID() == tempLink.getDestintionState().getCountryID()) {
                // stateList.add(tempLink.getSourceState());
                stateList.add(tempState);
                break;
              }
            } else if (mode == 2) {
              if (tempState.getCountryID() != tempLink.getDestintionState().getCountryID()) {
                // stateList.add(tempLink.getSourceState());
                stateList.add(tempState);
                break;
              }
            }
          }
        }
      }
    }
    return stateList;
  }
Beispiel #3
0
  /**
   * This method will authenticate the map, whether its an acceptable map or not.
   *
   * @return A string which indicates the map problems (null string for no problem)
   */
  public String validateMap() {

    // boolean verifyMap = true;
    String result = "";

    // Check if a state is isolated
    for (State tempState : myStateList) {
      Boolean isolated = true;
      for (Link tempLink : myLinkList) {
        if (tempLink.getSourceState().getStateID() == tempState.getStateID()
            || tempLink.getDestintionState().getStateID() == tempState.getStateID()) {
          isolated = false;
          break;
        }
      }
      if (isolated) result += "<br>" + tempState.getStateName() + " is an isolated state.";
    }

    // Check if there are more than one country
    if (myCountryList.size() <= 1) result += "<br>" + "The map has less than two countries.";

    // Check if each country has exactly one capital
    for (Country tempCountry : myCountryList) {
      int capitalCount = 0;
      for (State tempState : myStateList) {
        if (tempState.getCountryID() == tempCountry.getCountryID() && tempState.getIsCapital())
          capitalCount++;
      }
      if (capitalCount == 0)
        result += "<br>" + tempCountry.getCountryName() + " doesn't have any capital.";
      else if (capitalCount > 1)
        result += "<br>" + tempCountry.getCountryName() + " has more than one capital.";
    }
    return result;
  }