Ejemplo n.º 1
0
        public void GenerateTournament()
        {
            if (GetEmptySlots() > 0)
            {
                throw new BracketsException($"This file needs {GetEmptySlots()} more players");
            }

            PlayerList         PlayerTemp;
            List <BracketGame> Games = new List <BracketGame>();
            bool failing;
            int  tries = 0;

            do
            {
                failing    = false;
                PlayerTemp = new PlayerList(Players);
                Games.Clear();

                while (PlayerTemp.GetTotalEntries() != 0)
                {
                    PlayerTemp.GetTopPlayer(out BracketPlayer player1, out int entries);

                    List <BracketPlayer> validPlayers = PlayerTemp.GetValidMatchups(player1);

                    for (int i = 0; i < entries; i++)
                    {
                        if (validPlayers.Count == 0)
                        {
                            failing = true;
                            break;
                        }
                        BracketPlayer player2 = validPlayers[rng.Next(validPlayers.Count)];



                        Games.Add(new BracketGame(player1, player2));
                        PlayerTemp.RemoveEntry(player1);
                        PlayerTemp.RemoveEntry(player2);
                        validPlayers.Remove(player2);
                    }

                    if (failing)
                    {
                        break;
                    }
                }



                if (!GenerateBrackets(Shuffle(Games)))
                {
                    failing = true;
                }


                if (failing)
                {
                    if (++tries > MAX_TRIES_BEFORE_FAIL)
                    {
                        throw new BracketsException("Too many iterations. Possible Impossible situation.");
                    }

                    continue;
                }
            } while (failing);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Determines the number of people needed to fill out the brackets
        /// </summary>
        /// <returns></returns>
        private int GetEmptySlots()
        {
            int reqdPlayers = GetReqdBrackets() * PlayersPerBracket;

            return(reqdPlayers - Players.GetTotalEntries());
        }