Esempio n. 1
0
  @Override
  public Set<Player> getAllPlayers() {
    Set<Player> players = new TreeSet<Player>();

    for (IAPlayer xp : getAllIAPlayers()) {
      players.add(xp.getPlayer());
    }

    return players;
  }
Esempio n. 2
0
  @Override
  public List<Player> getPlayers() {
    List<Player> players = new ArrayList<Player>();

    for (IAPlayer xp : getIAPlayers()) {
      players.add(xp.getPlayer());
    }

    return players;
  }
Esempio n. 3
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;
  }
Esempio n. 4
0
  @Override
  public void dropPlayer(Player p) {

    IAPlayer xPlayer = null;

    for (IAPlayer xp : getIAPlayers()) {
      if (xp.getPlayer() == p) {
        xPlayer = xp;
        break;
      }
    }

    if (xPlayer != null) {
      getIAPlayers().remove(xPlayer);
    }

    resetRankingTable();
  }
Esempio n. 5
0
  @Override
  public StringBuilder appendXML(StringBuilder sb) {

    String playerString = "";
    String seperator = "";
    for (IAPlayer p : players) {
      playerString += seperator + p.getPlayer().getSaveId();
      seperator = ",";
    }

    XMLUtils.appendObject(sb, "PLAYERS", playerString);

    XMLUtils.appendList(sb, "ROUNDS", "ROUND", getAllRounds());

    XMLUtils.appendObject(sb, "NAME", name);
    XMLUtils.appendObject(sb, "MODULE", Modules.IA.getName());

    return sb;
  }
Esempio n. 6
0
  @Override
  public void generateRound(int roundNumber) {

    // if trying to skip a round...stop it
    if (roundNumber > rounds.size() + 1) {
      throw new IllegalArgumentException();
    }

    cancelRound(roundNumber);

    List<IAMatch> matches;
    if (roundNumber == 1) {

      matches = new ArrayList<IAMatch>();
      List<IAPlayer> tempList = new ArrayList<>();
      tempList.addAll(getIAPlayers());

      List<IAPlayer> firstRoundByePlayers = new ArrayList<>();
      for (IAPlayer p : tempList) {
        if (p.isFirstRoundBye()) {
          firstRoundByePlayers.add(p);
        }
      }
      tempList.removeAll(firstRoundByePlayers);

      if (seedingEnum == InitialSeedingEnum.IN_ORDER) {

        while (tempList.isEmpty() == false) {
          IAPlayer player1 = tempList.get(0);
          IAPlayer player2 = null;
          tempList.remove(0);
          if (tempList.isEmpty() == false) {
            player2 = tempList.get(0);
            tempList.remove(0);
          }

          IAMatch match = new IAMatch(player1, player2);
          matches.add(match);
        }

      } else if (seedingEnum == InitialSeedingEnum.RANDOM) {
        Collections.shuffle(tempList);

        while (tempList.isEmpty() == false) {
          IAPlayer player1 = tempList.get(0);
          IAPlayer player2 = tempList.get(tempList.size() - 1);
          tempList.remove(player1);
          if (player1 == player2) {
            player2 = null;
          } else {
            tempList.remove(player2);
          }

          IAMatch match = new IAMatch(player1, player2);
          matches.add(match);
        }
      } else if (seedingEnum == InitialSeedingEnum.BY_GROUP) {
        Map<String, List<IAPlayer>> playerMap = new HashMap<String, List<IAPlayer>>();

        // Add players to map
        for (IAPlayer p : tempList) {
          List<IAPlayer> playerList = playerMap.get(p.getPlayer().getGroupName());

          if (playerList == null) {
            playerList = new ArrayList<>();
            String groupName =
                p.getPlayer().getGroupName() == null ? "" : p.getPlayer().getGroupName();
            playerMap.put(groupName, playerList);
          }

          playerList.add(p);
        }

        // Shuffle up the lists
        List<String> seedValues = new ArrayList<>(playerMap.keySet());
        Collections.shuffle(seedValues);

        // Shuffle each group list
        for (List<IAPlayer> list : playerMap.values()) {
          Collections.shuffle(list);
        }

        // /////////////
        // Add new algorythm here
        // /////////////

        IAPlayer p1 = null;
        IAPlayer p2 = null;
        while (seedValues.isEmpty() == false) {
          int i = 0;
          while (i < seedValues.size()) {
            if (p1 == null) {
              p1 = playerMap.get(seedValues.get(i)).get(0);
            } else {
              p2 = playerMap.get(seedValues.get(i)).get(0);
              matches.add(new IAMatch(p1, p2));
              p1 = null;
              p2 = null;
            }

            playerMap.get(seedValues.get(i)).remove(0);

            if (playerMap.get(seedValues.get(i)).isEmpty()) {
              seedValues.remove(i);
            } else {
              i++;
            }
          }

          Collections.shuffle(seedValues);
        }
        if (p1 != null) {
          matches.add(new IAMatch(p1, null));
        }
      }

      for (IAPlayer p : firstRoundByePlayers) {
        matches.add(new IAMatch(p, null));
      }

    } else {

      matches = getMatches(getIAPlayers());
    }
    IARound r = new IARound(matches, this, roundNumber);
    rounds.add(r);
    if (roundNumber == 1
        && startAsSingleElimination
        && (matches.size() == 1
            || matches.size() == 2
            || matches.size() == 4
            || matches.size() == 8
            || matches.size() == 16
            || matches.size() == 32)) {
      r.setSingleElimination(true);
      getTournamentGUI()
          .getRoundTabbedPane()
          .addSingleEliminationTab(r.getMatches().size() * 2, r.getPanel());
    } else {
      getTournamentGUI().getRoundTabbedPane().addSwissTab(roundNumber, r.getPanel());
    }

    getTournamentGUI().getRankingTable().setPlayers(getAllIAPlayers());
  }