Exemple #1
0
        public static IEnumerable <TournamentBracket> GetTournamentBrackets(this TournamentBracket bracket)
        {
            // Validate parameters.
            if (bracket == null)
            {
                throw new ArgumentNullException(nameof(bracket));
            }

            // The implementation.
            IEnumerable <TournamentBracket> Implementation()
            {
                // The stack of brackets.
                var stack = new Stack <TournamentBracket>(EnumerableExtensions.From(bracket));

                // While there are items on the stack.
                while (stack.Count > 0)
                {
                    // Pop the item.
                    TournamentBracket popped = stack.Pop();

                    // Yield.
                    yield return(popped);

                    // Add the groups to the stack.
                    foreach (TournamentBracket group in popped.Groups)
                    {
                        // Add.
                        stack.Push(group);
                    }
                }
            }

            // Return the implementation.
            return(Implementation());
        }
Exemple #2
0
        private static string GetSingleStageType(this TournamentBracket bracket)
        {
            // Validate parameters.
            if (bracket == null)
            {
                throw new ArgumentNullException(nameof(bracket));
            }

            // Return distinct stage types.
            return(bracket
                   .Rounds
                   .Select(r => r.StageType)
                   .Distinct()
                   .Single());
        }
        public static bool IsMultiStageTournament(this TournamentBracket root)
        {
            // Validate parameters.
            if (root == null)
            {
                throw new ArgumentNullException(nameof(root));
            }

            // If there are multiple levels.
            if (root.Groups.Count > 0)
            {
                return(true);
            }


            // Are any of the matches group stage matches?
            return(root
                   .GetTournamentBrackets()
                   .SelectMany(b => b.GetTournamentBracketMatches())
                   .Any(m => m.IsGroupMatch));
        }
Exemple #4
0
 public static bool IsTournament(this TournamentBracket bracket) =>
 bracket.GetSingleStageType() == StageType.Tournament;
Exemple #5
0
 public static bool IsGroupStage(this TournamentBracket bracket) =>
 bracket.GetSingleStageType() == StageType.GroupStage;
Exemple #6
0
        public static IEnumerable <TournamentBracketMatch> GetTournamentBracketMatches(this TournamentBracket bracket)
        {
            // Validate parameters.
            if (bracket == null)
            {
                throw new ArgumentNullException(nameof(bracket));
            }

            // Get the third place match, as well as the matches by round.
            return(EnumerableExtensions.From(bracket.ThirdPlaceMatch)
                   .Concat(bracket.MatchesByRound.SelectMany(r => r.Value))
                   .Where(m => m != null));
        }