Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Pairing= 2 player objects
- getPlayerPlayedAgainst = a check if the player played against the opponent, as they can only play 1x against each other.
- public List<Pairing> getPairingsNextRoundSwiss() {
- // check templist met original list en dan remove templist en start over
- mPairingsRound = new ArrayList<Pairing>();
- Collections.sort(mPlayerList, new ScoreComparator());// sort highest
- // score
- List<Player> tempList = new ArrayList<>(mPlayerList);
- List<Player> removedList = new ArrayList<>();
- for (int i = 0; i <= tempList.size() - 1;) {
- if (!tempList.get(i).getPlayerPlayedAgainst(mPlayerList.get(i))
- && !tempList.get(i).equals(mPlayerList.get(i))
- && removedList != null
- && !removedList.contains(mPlayerList.get(i))) {
- mPairingsRound.add(new Pairing(tempList.get(i), mPlayerList
- .get(i)));
- tempList.remove(i);
- removedList.add(mPlayerList.get(i));
- } else {
- for (int j = 0; j <= mPlayerList.size() - 1; j++) {
- if (!tempList.get(i).getPlayerPlayedAgainst(
- mPlayerList.get(j))
- && !tempList.get(i).equals(mPlayerList.get(j))
- && removedList != null
- && !removedList.contains(mPlayerList.get(j))) {
- mPairingsRound.add(new Pairing(tempList.get(i),
- mPlayerList.get(j)));
- tempList.remove(i);
- removedList.add(mPlayerList.get(i));
- break;
- }
- }
- }
- }
- return mPairingsRound;
- }
Advertisement
Add Comment
Please, Sign In to add comment