Ejemplo n.º 1
0
        public void RoundPair(List <Match> piPreviousMatches, List <Player> piPlayers, int piOffset = 0)
        {
            List <Player> players;

            if (piOffset == 0)
            {
                players = PairingUtility.GetPlayersOrdered(piPreviousMatches, piPlayers);
            }
            else
            {
                players = PairingUtility.GetPlayersSortedSpecifiedFirst(piPlayers, piPlayers[piOffset]);
            }

            Dictionary <int, List <Player> > playersByPoints = GetPlayersGroupedByPoints(players);

            PairUpLowPlayers(playersByPoints);

            List <Player> playersDownpaired = new List <Player>();

            foreach (var point in playersByPoints.Keys)
            {
                foreach (var player in playersDownpaired)
                {
                    playersByPoints[point].Add(player);
                }

                playersDownpaired.Clear();

                players = PairingUtility.GetPlayersOrdered(piPreviousMatches, playersByPoints[point]);

                InnerPairing(piPreviousMatches, players, playersDownpaired);
            }
        }
Ejemplo n.º 2
0
        private void RedoPairing(List <Match> matchesToUndo, List <Match> previousMatches, List <Player> players, List <Player> playersDownpaired, int indexOfPlayerToPairUp)
        {
            playersDownpaired.Clear();
            foreach (var newMatch in matchesToUndo)
            {
                Matches.Remove(newMatch);
            }

            InnerPairing(previousMatches, PairingUtility.GetPlayersSortedSpecifiedFirst(players, players[indexOfPlayerToPairUp]), playersDownpaired);
        }
Ejemplo n.º 3
0
        public IEnumerable <Player> GetFinalStandings()
        {
            var players = PairingUtility.GetPlayersOrdered(ivAllMatches, ivPlayers.ToList());

            for (int i = 0; i < players.Count; i++)
            {
                players[i].Rank = i + 1;
            }

            return(players);
        }
Ejemplo n.º 4
0
        public IEnumerable <Player> GetTemporaryStandings()
        {
            var matches = new List <Match>();

            matches.AddRange(ivAllMatches);
            matches.AddRange(ivRounds.Last().Matches);

            var players = PairingUtility.GetPlayersOrdered(matches, ivPlayers.ToList());

            for (int i = 0; i < players.Count; i++)
            {
                players[i].Rank = i + 1;
            }

            return(players);
        }
Ejemplo n.º 5
0
        private void InnerPairing(List <Match> piPreviousMatches, List <Player> players, List <Player> playersDownpaired)
        {
            var newMatches   = new List <Match>();
            var playersAdded = new List <string>();

            if (players.Count >= 2)
            {
                for (int i = 0; i < players.Count; i++)
                {
                    if (PlayerHasMatch(players[i]))
                    {
                        continue;
                    }

                    if (i + 1 == players.Count)
                    {
                        playersDownpaired.AddRange(players);
                        break;
                    }

                    bool  addMatch       = true;
                    int   opponentOffset = 1;
                    Match match          = new Match(players[i], players[i + opponentOffset]);

                    while (!PairingUtility.IsMatchValid(piPreviousMatches, match) || PlayerHasMatch(players[i + opponentOffset]))
                    {
                        opponentOffset++;
                        if (i + opponentOffset >= players.Count)
                        {
                            foreach (var player in players.Where(playr => !playersAdded.Contains(playr.Id)))
                            {
                                playersDownpaired.Add(player);
                            }
                            if (newMatches.Any())
                            {
                                RedoPairing(newMatches, piPreviousMatches, players, playersDownpaired, i);
                                return;
                            }
                            addMatch = false;
                            break;
                        }
                        match = new Match(players[i], players[i + opponentOffset]);
                    }

                    if (addMatch)
                    {
                        playersAdded.Add(players[i].Id);
                        playersAdded.Add(players[i + opponentOffset].Id);
                        Matches.Add(match);
                        newMatches.Add(match);

                        if (i + 1 == players.Count)
                        {
                            foreach (var player in players.Where(playr => !playersAdded.Contains(playr.Id)))
                            {
                                playersDownpaired.Add(player);
                            }
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }
            else
            {
                playersDownpaired.AddRange(players);
            }
        }