Beispiel #1
0
        public IList <IList <Match> > GetMatchesPerRound(IList <Match> allMatches)
        {
            var matchesPerRound = new List <IList <Match> >();
            var matches         = new List <Match>();
            var round           = -1;

            foreach (var match in allMatches.OrderBy(x => x.Name))
            {
                var matchRound = EliminationRoundNames.GetRound(match.Name);
                if (matchRound != -1 && matchRound != round)
                {
                    if (matches.Any())
                    {
                        matchesPerRound.Add(matches.OrderBy(x => EliminationRoundNames.GetMatchNumber(x.Name, round)).ToList());
                        matches = new List <Match>();
                    }
                    round = matchRound;
                }
                matches.Add(match);
            }
            if (matches.Any())
            {
                matchesPerRound.Add(matches.OrderBy(x => EliminationRoundNames.GetMatchNumber(x.Name, round)).ToList());
            }
            return(matchesPerRound);
        }
Beispiel #2
0
        public int?GetRank(Person rankingPerson, IList <Match> matches)
        {
            int?rank = null;

            foreach (var match in matches)
            {
                if (match.FighterRed != rankingPerson && match.FighterBlue != rankingPerson)
                {
                    continue;
                }
                var  round = EliminationRoundNames.GetRound(match.Name);
                bool win;
                if (match.Result == MatchResult.WinBlue || match.Result == MatchResult.DisqualificationRed ||
                    match.Result == MatchResult.ForfeitRed)
                {
                    win = match.FighterBlue == rankingPerson;
                }
                else if (match.Result == MatchResult.WinRed || match.Result == MatchResult.DisqualificationBlue ||
                         match.Result == MatchResult.ForfeitBlue)
                {
                    win = match.FighterRed == rankingPerson;
                }
                else
                {
                    continue;
                }
                if (round == 0)
                {
                    if (match.Name.Trim() == EliminationRoundNames.GetMatchName(round, 2).Trim())
                    {
                        rank = win ? 3 : 4;
                    }
                    else
                    {
                        rank = win ? 1 : 2;
                    }
                }
                else if (win)
                {
                    if (rank == null || rank > 1 << round)
                    {
                        rank = 1 << round;
                    }
                }
                else if (round != 1)
                {
                    if (rank == null || rank > (1 << round) + 1)
                    {
                        rank = (1 << round) + 1;
                    }
                }
            }
            return(rank);
        }
Beispiel #3
0
        public IList <Match> UpdateMatchesAfterFinishedMatch(Match match, IList <Match> matches)
        {
            var    updatedMatches = new List <Match>();
            Person winner         = null;
            Person loser          = null;

            if (match.Result == MatchResult.WinBlue || match.Result == MatchResult.DisqualificationRed ||
                match.Result == MatchResult.ForfeitRed)
            {
                winner = match.FighterBlue;
                if (match.Result == MatchResult.WinBlue)
                {
                    loser = match.FighterRed;
                }
            }
            else if (match.Result == MatchResult.WinRed || match.Result == MatchResult.DisqualificationBlue ||
                     match.Result == MatchResult.ForfeitBlue)
            {
                winner = match.FighterRed;
                if (match.Result == MatchResult.WinRed)
                {
                    loser = match.FighterBlue;
                }
            }

            var round = EliminationRoundNames.GetRound(match.Name);

            if (round > 0 && winner != null)
            {
                var matchNumber     = EliminationRoundNames.GetMatchNumber(match.Name, round);
                var nextRound       = round - 1;
                var nextMatchNumber = ((matchNumber - 1) >> 1) + 1;
                var nextMatchName   = EliminationRoundNames.GetMatchName(nextRound, nextMatchNumber).Trim();
                var nextMatch       = matches.SingleOrDefault(x => x.Name.Trim() == nextMatchName);
                if (nextMatch != null)
                {
                    if (matchNumber % 2 == 1)
                    {
                        nextMatch.FighterBlue = winner;
                    }
                    else
                    {
                        nextMatch.FighterRed = winner;
                    }
                    updatedMatches.Add(nextMatch);
                }

                if (round == 1 && loser != null)
                {
                    nextMatchName = EliminationRoundNames.GetMatchName(0, 2).Trim();
                    nextMatch     = matches.SingleOrDefault(x => x.Name.Trim() == nextMatchName);
                    if (nextMatch != null)
                    {
                        if (matchNumber % 2 == 1)
                        {
                            nextMatch.FighterBlue = loser;
                        }
                        else
                        {
                            nextMatch.FighterRed = loser;
                        }
                        updatedMatches.Add(nextMatch);
                    }
                }
            }
            return(updatedMatches);
        }