Exemplo n.º 1
0
  @Override
  public boolean generateNextRound() {
    if (getLatestRound().isComplete() == false) {
      JOptionPane.showMessageDialog(
          Main.getInstance(),
          "Current round is not complete. Please complete all matches before continuing");
      return false;
    }

    if (getLatestRound().isValid() == false) {
      JOptionPane.showMessageDialog(
          Main.getInstance(),
          "At least one tournamnt result is not correct. Check if points are backwards or a result should be a modified win or tie.");
      return false;
    }

    if (getLatestRound().isSingleElimination()) {
      if (getLatestRound().getMatches().size() == 1) {
        JOptionPane.showMessageDialog(
            Main.getInstance(), "Final tournament complete. No more rounds will be generated.");
        return false;
      }
      generateSingleEliminationMatches(getLatestRound().getMatches().size());
    } else {
      generateRound(getAllRounds().size() + 1);
    }
    return true;
  }
Exemplo n.º 2
0
  private List<IAMatch> getMatches(List<IAPlayer> userList) {
    List<IAMatch> matches = new ArrayList<IAMatch>();

    List<IAPlayer> tempList = new ArrayList<IAPlayer>();
    tempList.addAll(userList);
    Collections.sort(tempList, new IAComparator(this, IAComparator.pairingCompare));

    IAMatch byeMatch = null;
    // Setup the bye match if necessary
    // The player to get the bye is the lowest ranked player who has not had
    // a bye yet or who has the fewest byes
    if (tempList.size() % 2 == 1) {
      IAPlayer byeUser = null;
      int byUserCounter = 1;
      int minByes = 0;
      try {
        while (byeUser == null
            || byeUser.getByes(this) > minByes
            || (byeUser.getMatches(this) != null
                && byeUser.getMatches(this).get(byeUser.getMatches(this).size() - 1).isBye())) {
          if (byUserCounter > tempList.size()) {
            minByes++;
            byUserCounter = 1;
          }
          byeUser = tempList.get(tempList.size() - byUserCounter);

          byUserCounter++;
        }
      } catch (ArrayIndexOutOfBoundsException e) {
        byeUser = tempList.get(tempList.size() - 1);
      }
      byeMatch = new IAMatch(byeUser, null);
      tempList.remove(byeUser);
    }

    matches = new IARandomMatchGeneration(this, tempList).generateMatches();

    if (IAMatch.hasDuplicate(matches)) {
      JOptionPane.showMessageDialog(
          Main.getInstance(),
          "Unable to resolve duplicate matches. Please review for best course of action.");
    }

    // Add the bye match at the end
    if (byeMatch != null) {
      matches.add(byeMatch);
    }

    return matches;
  }