SHARE
TWEET

Untitled

a guest Jun 19th, 2019 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. async void PairSwiss(bool firstRound)
  2.         {
  3.             List<Player> players = data.activeTournament.GetPlayers();
  4.             if (firstRound)
  5.             {
  6.                 players.Sort(new SeededPlayerComparer()); //Players are sorted by overall winrate, which allows us to pair them by going down the list.
  7.             }
  8.             else
  9.             {
  10.                 players.Sort(new PlayerComparer()); //Players are sorted by point count, which allows us to pair them by going down the list.
  11.             }
  12.             for(int i = 0; i < players.Count; i++)
  13.             {
  14.                 //Skip this player if they already have an opponent
  15.                 if (!players[i].hasAnOpponent())
  16.                 {
  17.                     for (int k = 0; k < players.Count; k++)
  18.                     {
  19.                         //Check to make sure we haven't played against them and they don't already have an opponent and that i and k aren't the same person
  20.                         if (!players[i].hasPlayedAgainst(players[k].getID()) && !players[k].hasAnOpponent() && i != k)
  21.                         {
  22.                             //Huzzah a pairing is found, set the players as each other's opponents
  23.                             players[i].setOpponent(players[k].getName(), players[k].getID(), players[k]);
  24.                             players[k].setOpponent(players[i].getName(), players[i].getID(), players[i]);
  25.  
  26.                             //Reset all the match tracking stats so that nothing messes up..
  27.                             players[i].CurrentMatch = 0;
  28.                             players[k].CurrentMatch = 0;
  29.                             players[i].CompletedRound = false;
  30.                             players[k].CompletedRound = false;
  31.                             break;
  32.                         }
  33.                     }
  34.                 }
  35.                 if(!players[i].hasAnOpponent())
  36.                 {
  37.                     //If this triggers... this should be the last person in the list in the event that there is an odd number of players.. and thus they get a bye.
  38.                     //They specifically are fine to get the bye because they are either the lowest seeded if its the first round or the furthest behind in points so
  39.                     //a bye is likely to be less impactful for them and the points gained from the bye will usually ensure they don't get multiple byes in a tournament.
  40.                     players[i].CompletedRound = true;
  41.                     float numMatches = data.activeTournament.getNumMatches();
  42.                     players[i].addPoint((int)Math.Ceiling(numMatches / 2f));
  43.                     await players[i].GuildUser.SendMessageAsync("You have been selected to receive a bye this round due to" +
  44.                         " the odd number of participants playing in " + data.activeTournament.getName() + ". Consider this a nice break from the competition and keep an eye " +
  45.                         "out for the start of the next round.");
  46.                 }
  47.             }
  48.  
  49.             if (firstRound)
  50.             {
  51.                 data.activeTournament.setCurrentRound(1);
  52.             }
  53.             else
  54.             {
  55.                 data.activeTournament.startNextRound();
  56.             }
  57.         }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top