Example #1
0
        // TODO: check if we should apply this function for blinds posting
        private void PutChipsToPot(Player player, int amount)
        {
            Pot potToPutChips = null;

            foreach (Pot pot in CurrentHand.Pots)
            {
                bool hasPlayersAllIn = false;
                foreach (Player playerInPot in pot.PlayersInPot)
                {
                    if (playerInPot.IsAllIn)
                    {
                        hasPlayersAllIn = true;
                        break;
                    }
                }
                if (!hasPlayersAllIn)
                {
                    potToPutChips = pot;
                    break;
                }
            }

            if (potToPutChips == null)
            {
                Pot newPot = new Pot();
                CurrentHand.AddPot(newPot);
                GameController.Instance.AddPot();
                potToPutChips = newPot;
            }

            player.PutChipsToPot(potToPutChips, amount);
        }
Example #2
0
        public void PutChipsToPot(Pot pot, int amount)
        {
            int newStackSize = ChipCount - amount;

            ChipCount = newStackSize;

            CurrentBet += amount;
            if (!pot.IsPlayerInPot(this))
            {
                pot.PlayersInPot.Add(this);
            }
            pot.Size += amount;
        }
Example #3
0
        public override void PlayHand()
        {
            _deck.StartNewHand();
            Hand newHand = new Hand();

            newHand.AddPlayers(_players);
            // For the first hand, players positions are already set in Start method
            if (!IsFirstHand)
            {
                newHand.SetPlayersPositions();
            }
            newHand.SetBlindsAndAntes(_bigBlindSize, _anteSize);
            newHand.PostBlindsAndAntes();
            _hands.Add(newHand);

            CurrentHandState.Instance.SetState(HandState.Preflop);

            Pot mainPot = new Pot();

            newHand.AddPot(mainPot);
            GameController.Instance.AddPot();

            PostBlindsAndAntes();
        }
Example #4
0
 public void AddPot(Pot pot)
 {
     _pots.Add(pot);
 }
Example #5
0
        public List <Player> GetWinners(Pot pot)
        {
            List <Player> winners = new List <Player>();

            // TODO: cache winner value because this method is called more than once at the end of each hand
            if (_playersInvolved.Count == 1)
            {
                winners.Add(_playersInvolved[0]);
                return(winners);
            }

            PlayerHandInfo strongestHand;

            strongestHand.HandType   = HandType.Invalid;
            strongestHand.HandColour = Colour.Invalid;
            strongestHand.MainRank   = Rank.Invalid;
            strongestHand.SecondRank = Rank.Invalid;

            Player winner = null;

            foreach (Player player in pot.PlayersInPot)
            {
                if (player.CurrentHandInfo.HandType > strongestHand.HandType)
                {
                    strongestHand = player.CurrentHandInfo;
                    winner        = player;
                }
                else if (player.CurrentHandInfo.HandType == strongestHand.HandType)
                {
                    if (player.CurrentHandInfo.MainRank != Rank.Invalid)
                    {
                        if (player.CurrentHandInfo.MainRank > strongestHand.MainRank)
                        {
                            strongestHand = player.CurrentHandInfo;
                            winner        = player;
                        }
                        else if (player.CurrentHandInfo.MainRank == strongestHand.MainRank)
                        {
                            if (player.CurrentHandInfo.SecondRank != Rank.Invalid)
                            {
                                if (player.CurrentHandInfo.SecondRank > strongestHand.SecondRank)
                                {
                                    strongestHand = player.CurrentHandInfo;
                                    winner        = player;
                                }
                                else if (player.CurrentHandInfo.SecondRank == strongestHand.SecondRank)
                                {
                                    // Hands are completely equal
                                    winners.Add(winner);
                                    winner = player;
                                }
                            }
                            else
                            {
                                // Hand type and main rank are equal and there's no second rank
                                winners.Add(winner);
                                winner = player;
                            }
                        }
                    }
                }
            }

            winners.Add(winner);

            return(winners);
        }