示例#1
0
        public void GoAllIn(Collection <Player> players)
        {
            Collection <Player> playersInPot = new Collection <Player>(players.ToList());
            int minPot = GetMinPlayerPot(players);

            foreach (Player P in players)
            {
                P.PlayerPot -= minPot;
                Pots[currPotForBetting].AddChips(minPot);
                if (P.PlayerPot == 0)
                {
                    playersInPot.Remove(P);
                }
            }

            while (playersInPot.Count != 0)
            {
                minPot             = GetMinPlayerPot(playersInPot);
                currPotForBetting += 1;
                Pots.Add(new Pot(playersInPot));
                Collection <Player> playersNewInPot = new Collection <Player>(playersInPot.ToList());
                foreach (Player P in playersInPot)
                {
                    P.PlayerPot -= minPot;
                    Pots[currPotForBetting].AddChips(minPot);
                    if (P.PlayerPot == 0)
                    {
                        playersNewInPot.Remove(P);
                    }
                }
                playersInPot = new Collection <Player>(playersNewInPot.ToList());
            }
        }
示例#2
0
 public PotManager(Collection <Player> players, GameType gameType, Chip bigBlind)
 {
     _gameType = gameType;
     _bigBlind = bigBlind;
     this.currPotForBetting = 0;
     this._previousRaise    = new Chip(0);
     this.Pots = new Collection <Pot>();
     Pots.Add(new Pot(players));
 }
示例#3
0
        private void SetPot(int index, IEnumerable <Player> playerPool = null)
        {
            var players = playerPool ?? Players;

            if (MinBet != 0 || players.Count() > 0) // We didn't check around, if we did there is no money to add to the pot
            {
                var testValue = players.Max(x => x.CurrentBet);
                if (players.All(x => x.CurrentBet == testValue || x.CurrentBet == 0))
                {
                    Pots[index].AddToPot(Players.Sum(x => x.CurrentBet));
                    foreach (var p in players)
                    {
                        p.CurrentBet = 0;
                    }
                }
                else
                {
                    var playerAllIn       = players.Where(x => x.CurrentBet == (players.Min(y => y.CurrentBet))).ElementAt(0);
                    var betValue          = playerAllIn.CurrentBet;
                    var sumAddedToMainPot = 0.0;
                    foreach (var p in Players)
                    {
                        if (p.CurrentBet != 0 && p.CurrentBet >= playerAllIn.CurrentBet)
                        {
                            sumAddedToMainPot += betValue;
                            p.CurrentBet      -= betValue;
                        }
                        else if (p.CurrentBet < playerAllIn.CurrentBet) // the player(p) had folded
                        {
                            sumAddedToMainPot += p.CurrentBet;
                            p.CurrentBet       = 0;
                        }
                    }
                    Pots[index].AddToPot(sumAddedToMainPot);

                    Pot newPot = new Pot();
                    newPot.EligiblePlayers = players.Where(x => x.CurrentBet > 0).ToList();
                    if (newPot.EligiblePlayers.Count == 1)
                    {
                        newPot.EligiblePlayers.ElementAt(0).Chips     += newPot.EligiblePlayers.ElementAt(0).CurrentBet;
                        newPot.EligiblePlayers.ElementAt(0).CurrentBet = 0;
                    }
                    else
                    {
                        Pots.Add(newPot);
                        currentPotIndex++;
                        SetPot(currentPotIndex, players.Where(x => x.CurrentBet > 0));
                    }
                }
            }
        }
示例#4
0
        private void SetupPots()
        {
            while (Players.Count(x => x.Chips > 0) > 1)
            {
                var pot = new Pot()
                {
                    Name            = Pots.Count < 1 ? "main pot" : $"side pot {Pots.Count}",
                    EligiblePlayers = new List <Player>()
                };

                var lowestChipAmount = Players.Where(x => x.Chips > 0).OrderBy(x => x.Chips).First().Chips;

                foreach (var player in Players.Where(x => x.Chips >= lowestChipAmount))
                {
                    player.Chips -= lowestChipAmount;
                    pot.Chips    += lowestChipAmount;
                    pot.EligiblePlayers.Add(player);
                }

                Pots.Add(pot);
            }
        }
示例#5
0
        public void AddNewPot()
        {
            Pots.Add(new Pot());

            Console.WriteLine("New pot has been created");
        }