コード例 #1
0
        /// <summary>
        /// Assigns competitors to brackets according to the stored seed option.
        /// </summary>
        private void AssignBrackets()
        {
            //Get the bottom bracket level for the tournemnt
            int bottomLevel = CalculateNoOfTournamentLevels();

            if (SeedOption == SeedOption.Seeded)
            {
                //Sort our competitor collection to ensure that they're sorted ascending by seed
                //before we begin bracket assignment
                Competitors.Sort();
            }
            else
            {
                //We're randomizing the competitors. Create a list to hold our randomized result.
                List <Competitor> randomizedCompetitors = new List <Competitor>();

                Random rnd = new Random();
                while (Competitors.Count > 0)
                {
                    //Randomly generate an index to grab
                    int rndIndex = rnd.Next(Competitors.Count);

                    //Get the competitor at that index and add it to the randomized collection
                    Competitor tempCompetitor = Competitors[rndIndex];
                    randomizedCompetitors.Add(tempCompetitor);
                    //Set the seed for the competitor
                    tempCompetitor.Seed = randomizedCompetitors.Count;
                    //Remove the competitor from the original source list
                    Competitors.RemoveAt(rndIndex);
                }

                //Now that our competitors are now in the randomized collection, assign that one
                //as the Competitor collection to use
                Competitors = randomizedCompetitors;
            }

            //Assign Competitor 1 slots in starting brackets
            AssignCompetitor1Brackets(bottomLevel);

            //Assign Competitor 2 slots in starting brackets
            AssignCompetitor2Brackets(bottomLevel);
        }