Esempio n. 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);
        }
Esempio n. 2
0
 public void AddEntry(BracketPlayer player)
 {
     if (Players.ContainsKey(player))
     {
         Players[player]++;
     }
     else
     {
         Players.Add(player, 1);
     }
 }
Esempio n. 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));
     }
 }
Esempio n. 4
0
 public void RemoveEntry(BracketPlayer player)
 {
     if (Players.TryGetValue(player, out int entries))
     {
         if (entries == 1)
         {
             Players.Remove(player);
         }
         else
         {
             Players[player]--;
         }
     }
 }
Esempio n. 5
0
        public void GenerateTournament()
        {
            if (GetEmptySlots() > 0)
            {
                Console.WriteLine(GetEmptySlots() + " more bowlers required");
                return;
            }

            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 SeedingFailedException("Too many iterations. Possible Impossible situation.");
                    }

                    continue;
                }
            } while (failing);
        }
Esempio n. 6
0
 public void RemoveEntry(BracketPlayer player)
 {
     Players.RemoveEntry(player);
 }
Esempio n. 7
0
 public void AddEntry(BracketPlayer player)
 {
     Players.AddEntry(player);
 }
Esempio n. 8
0
 public void GetTopPlayer(out BracketPlayer player, out int entries)
 {
     entries = Players.Values.Max();
     player  = Players.First(x => x.Value == Players.Values.Max()).Key;
 }
Esempio n. 9
0
 public bool HasPlayer(BracketPlayer player)
 {
     return(Players.Contains(player));
 }
 public BracketGame(BracketPlayer player1, BracketPlayer player2)
 {
     this.p1 = player1;
     this.p2 = player2;
 }