Пример #1
0
        public List <BracketPlayer> GetValidMatchups(BracketPlayer player)
        {
            var a = Players.Where(x => x.Value > 0)
                    .Select(x => x.Key).ToList();

            a.Remove(player);
            return(a);
        }
Пример #2
0
 public void AddEntry(BracketPlayer player)
 {
     if (Players.ContainsKey(player))
     {
         Players[player]++;
     }
     else
     {
         Players.Add(player, 1);
     }
 }
Пример #3
0
 public override bool Equals(object obj)
 {
     if ((obj == null) || !this.GetType().Equals(obj.GetType()))
     {
         return(false);
     }
     else
     {
         BracketPlayer p = (BracketPlayer)obj;
         return((name == p.name) && (games == p.games));
     }
 }
Пример #4
0
 public void RemoveEntry(BracketPlayer player)
 {
     if (Players.TryGetValue(player, out int entries))
     {
         if (entries == 1)
         {
             Players.Remove(player);
         }
         else
         {
             Players[player]--;
         }
     }
 }
Пример #5
0
 public BracketGame(BracketPlayer player1, BracketPlayer player2)
 {
     this.p1 = player1;
     this.p2 = player2;
 }
Пример #6
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);
        }
Пример #7
0
 public void RemoveEntry(BracketPlayer player)
 {
     Players.RemoveEntry(player);
 }
Пример #8
0
 public void AddEntry(BracketPlayer player)
 {
     Players.AddEntry(player);
 }
Пример #9
0
 public void GetTopPlayer(out BracketPlayer player, out int entries)
 {
     entries = Players.Values.Max();
     player  = Players.First(x => x.Value == Players.Values.Max()).Key;
 }
Пример #10
0
 public bool HasPlayer(BracketPlayer player)
 {
     return(Players.Contains(player));
 }