Пример #1
0
        /// <summary>
        /// Public constructor used to create a new Tournament.
        /// </summary>
        /// <param name="competitors"></param>
        /// <param name="seedOption"></param>
        public Tournament(List<Competitor> competitors, SeedOption seedOption)
        {
            //Initialize internal members.
              _brackets = new List<Bracket>();
              _winner = null;

              //Store the constructor param data.
              Competitors = competitors;
              SeedOption = seedOption;

              //Create the bracket structure for the tournament.
              CreateBrackets();

              //Assign competitors to brackets
              AssignBrackets();

              //Add code here to automatically advance competitors with a bye for the staring level
              AdvanceByeCompetitors();
        }
Пример #2
0
        /// <summary>
        /// Advances the provided competitor to the next round in the tournament.
        /// </summary>
        /// <param name="competitor"></param>
        public void Advance(Competitor competitor)
        {
            //Make sure that the provided Competitor object belongs to this bracket
            if ((competitor != this.Competitor) && (competitor != this.Competitor2))
            {
                throw new InvalidCompetitorException(competitor);
            }

            if (ParentBracket is Bracket)
            {
                Bracket parent = (Bracket)ParentBracket;

                //Check to see if this bracket is child 1 or child 2 in the parent
                if (parent.ChildBracket == this)
                {
                    if (parent.Competitor != null)
                    {
                        throw new CompetitorAlreadyAssignedForBracketException(parent, 1);
                    }

                    parent.Competitor = competitor;
                }
                else if (parent.ChildBracket2 == this)
                {
                    if (parent.Competitor2 != null)
                    {
                        throw new CompetitorAlreadyAssignedForBracketException(parent, 2);
                    }

                    parent.Competitor2 = competitor;
                }
                else
                {
                    throw new ChildToParentBracketAssociationException(parent, this);
                }
            }
            else if (ParentBracket is Winner)
            {
                //Check to see if we're assigning a winner
                Winner parent = (Winner)ParentBracket;
                parent.Competitor = competitor;
            }
        }
Пример #3
0
        /// <summary>
        /// Creates Bracket objects for all available competitor matchups for the tournament.
        /// </summary>
        private void CreateBrackets()
        {
            //Determine the number of levels deep our tournament will be, based on
              //the number of competitors we have
              int tournamentLevelDepth = CalculateNoOfTournamentLevels();

              //Create the winner object
              _winner = new Winner(SeedOption);

              //Create the top level (finals-level) Bracket object
              int curBracketLevel = 1;
              int curBracketSequenceNo = 1;
              Bracket topLevelBracket = new Bracket(SeedOption, curBracketLevel, curBracketSequenceNo)
              {
            ParentBracket = _winner
              };

              //Assign the top-level bracket as the Winner object's child
              _winner.ChildBracket = topLevelBracket;

              //Add the top-level Bracket object to the collection
              _brackets.Add(topLevelBracket);

              //Continue creating children Bracket objects until we have created brackets to fill the
              //depth of our tournament
              while (curBracketLevel < tournamentLevelDepth)
              {
            //Reset the bracket sequence number for the child brackets that we're about
            //to create.
            curBracketSequenceNo = 1;

            //Select the current level bracket(s).
            List<Bracket> foundBrackets = GetBracketsForLevel(curBracketLevel);

            //Increment the bracket level for the children-level bracket objects we're about to create.
            curBracketLevel++;

            //For each bracket we found, add two children to each.
            foreach (Bracket bracket in foundBrackets)
            {
              //Create the first child bracket, using the current bracket as its parent.
              Bracket childBracket1 = new Bracket(SeedOption, curBracketLevel, curBracketSequenceNo++)
              {
            ParentBracket = bracket
              };
              bracket.ChildBracket = childBracket1;
              _brackets.Add(childBracket1);

              //Create the second child bracket, using the current bracket as its parent.
              Bracket childBracket2 = new Bracket(SeedOption, curBracketLevel, curBracketSequenceNo++)
              {
            ParentBracket = bracket
              };
              bracket.ChildBracket2 = childBracket2;
              _brackets.Add(childBracket2);
            }
              }
        }
Пример #4
0
 public ChildToParentBracketAssociationException(Winner parentBracket, Bracket childBracket)
     : base(string.Format("Child-to-Parent bracket association exception; Child Level: {0}, Sequence: {1}; Winner",
   childBracket.Level, childBracket.Sequence))
 {
 }
        public ControlWinner()
        {
            InitializeComponent();

              _winner = null;
        }