private void Raise(double amountToRaise)
        {
            Pot lastPartialPot = currentPot;

            while (lastPartialPot.PartialPot != null)
            {
                lastPartialPot = lastPartialPot.PartialPot;
            }

            lastPartialPot.Value         += amountToRaise;
            lastPartialPot.AmountToClaim += amountToRaise;
            CurrentPlayer.SubstractMoney(amountToRaise);
            LiveBets[CurrentPlayer] += amountToRaise;
            lastRaise   = amountToRaise;
            totalRaise += LastRaise;

            //reset the players claiming this pot
            lastPartialPot.PlayersClaimPot = new List <Player>
            {
                CurrentPlayer
            };
            if (currentPlayer.Wallet.AmountOfMoney == 0)
            {
                lastPartialPot.PartialPot = new Pot(lastPartialPot);
            }

            lastPlayerToRaise = CurrentPlayer;
        }
        public Round(Player dealer, ICollection <Player> activeUnfoldedPlayers, Pot currentPot, bool isPreflop, GamePreferences config)
        {
            this.IsPreflop = isPreflop;

            //Set up players info
            this.dealer = dealer;
            this.activeUnfoldedPlayers = activeUnfoldedPlayers;
            liveBets = new Dictionary <Player, double>();
            foreach (Player player in activeUnfoldedPlayers)
            {
                LiveBets.Add(player, 0);
            }
            currentPlayer     = this.activeUnfoldedPlayers.ElementAt((this.activeUnfoldedPlayers.ToList().IndexOf(dealer) + 1) % this.activeUnfoldedPlayers.Count);
            lastPlayerToRaise = dealer;

            //Set up raise info
            totalRaise = 0;
            lastRaise  = 0;


            //Others
            this.currentPot = currentPot;
            currentTurn     = new Turn(currentPlayer);
            this.config     = config;
        }
Esempio n. 3
0
        public void PlayHand(object _lock)
        {
            PrepareHand();

            //PRE FLOP
            CurrentRound.IsPreflop = true;
            CurrentRound.PlayBettingRound(_lock);
            UpdatePlayersBets();
            pot = CurrentRound.CurrentPot;

            //FLOP
            deck.PullCard(Card.State.FaceDown); //burn card
            int i = 0;

            foreach (Card card in deck.PullCards(3))
            {
                communityCards[i] = card;
                i++;
            }

            //SECOND BETTING ROUND
            CurrentRound  = new Round(dealer, activePlayers, pot, false, preferences);
            activePlayers = CurrentRound.PlayBettingRound(_lock);
            UpdatePlayersBets();
            pot = CurrentRound.CurrentPot;

            //TURN
            deck.PullCard(Card.State.FaceDown); //burn card
            communityCards[i] = deck.PullCard(Card.State.FaceUp);
            i++;

            //THIRD BETTING ROUND
            CurrentRound  = new Round(dealer, activePlayers, pot, false, preferences);
            activePlayers = CurrentRound.PlayBettingRound(_lock);
            UpdatePlayersBets();
            pot = CurrentRound.CurrentPot;

            //RIVER
            deck.PullCard(Card.State.FaceDown); //burn card
            communityCards[i] = deck.PullCard(Card.State.FaceUp);

            //FORTH BETTING ROUND
            CurrentRound  = new Round(dealer, activePlayers, pot, false, preferences);
            activePlayers = CurrentRound.PlayBettingRound(_lock);
            UpdatePlayersBets();
            pot = CurrentRound.CurrentPot;
        }
        private void Fold()
        {
            CurrentPlayer.Fold();
            Player playerToRemove = CurrentPlayer;

            //Remover player from all pots
            Pot partialPotIterator = CurrentPot;

            while (partialPotIterator != null)
            {
                partialPotIterator.PlayersClaimPot.Remove(playerToRemove);
                partialPotIterator = partialPotIterator.PartialPot;
            }

            //Remove player from round
            currentPlayer = ActiveUnfoldedPlayers.ElementAt((ActiveUnfoldedPlayers.ToList().IndexOf(CurrentPlayer) - 1) % ActiveUnfoldedPlayers.Count);
            ActiveUnfoldedPlayers.Remove(playerToRemove);
        }
Esempio n. 5
0
 public Hand(Player dealer, ICollection <Player> players, GamePreferences preferences)
 {
     if (players.Count < MINIMAL_NUMBER_OF_ACTIVE_PLAYERS_TO_START)
     {
         throw new NotEnoughPlayersException();
     }
     this.preferences = preferences;
     deck             = new Deck();
     activePlayers    = players;
     PlayersBets      = new Dictionary <Player, double>();
     foreach (Player player in activePlayers)
     {
         player.CurrentState = Player.State.ActiveUnfolded;
         PlayersBets.Add(player, 0);
     }
     communityCards = new Card[NUM_OF_COMMUNITY_CARDS];
     pot            = new Pot();
     this.dealer    = dealer;
     CurrentRound   = new Round(dealer, activePlayers, pot, false, this.preferences);
     Active         = true;
 }
Esempio n. 6
0
        private void PickAWinner()
        {
            //Change all player's bets to negative numbers (for statistics)
            foreach (Player player in activePlayers)
            {
                PlayersBets[player] *= -1;
            }

            //Go to the last pot
            Pot lastPot = CurrentRound.CurrentPot;

            while (lastPot.BasePot != null)
            {
                lastPot = lastPot.BasePot;
            }

            List <Player> potWinners;

            //pick winner for each pot separately
            while (lastPot != null)
            {
                PickAWinner pickPotWinner = new PickAWinner(lastPot.PlayersClaimPot, communityCards);
                potWinners = pickPotWinner.GetWinners();

                double playerWinningMoney = lastPot.Value / potWinners.Count;
                //divide pot money to winning players
                foreach (Player player in potWinners)
                {
                    if (!PlayersBets.ContainsKey(player))
                    {
                        throw new PlayerNotFoundException("Can't find the winning player in the acitveUnfoldedPlayers... not possible");
                    }
                    PlayersBets[player] += playerWinningMoney;
                    player.AddMoney(playerWinningMoney);
                }

                lastPot = lastPot.PartialPot;
            }
        }
        private void Call(double amountToBetOrCall)
        {
            if (amountToBetOrCall == 0)
            {
                amountToBetOrCall = TotalRaise - LiveBets[CurrentPlayer];
            }
            double playerCurrentBet = LiveBets[CurrentPlayer];

            Pot    partialPotIterator   = CurrentPot;
            Pot    lastPartialPot       = partialPotIterator;
            double amountToAdd          = amountToBetOrCall; //how much money does the player need to add in order to claim the pot
            double lastPlayerCurrentBet = 0;

            while (partialPotIterator != null && partialPotIterator.AmountToClaim > 0 && amountToBetOrCall > 0)
            {
                if (playerCurrentBet < partialPotIterator.AmountToClaim)
                {
                    if (amountToBetOrCall + playerCurrentBet >= partialPotIterator.AmountToClaim) //if regular call
                    {
                        amountToAdd = partialPotIterator.AmountToClaim - playerCurrentBet;
                    }
                    else    //if call all-in
                    {
                        amountToAdd = amountToBetOrCall;
                    }
                    CurrentPlayer.SubstractMoney(amountToAdd);
                    LiveBets[CurrentPlayer]  += amountToAdd;
                    partialPotIterator.Value += amountToAdd;
                    amountToBetOrCall        -= amountToAdd;
                    lastPlayerCurrentBet      = playerCurrentBet;
                    playerCurrentBet          = 0;
                }
                else
                {
                    playerCurrentBet -= partialPotIterator.AmountToClaim;
                }

                //Add the current player to claiming this partial pot
                if (!partialPotIterator.PlayersClaimPot.Contains(CurrentPlayer))
                {
                    partialPotIterator.PlayersClaimPot.Add(CurrentPlayer);
                }

                lastPartialPot     = partialPotIterator;
                partialPotIterator = partialPotIterator.PartialPot;
            }
            //CurrentTurn.Call(amountToBetOrCall);

            if (amountToBetOrCall + playerCurrentBet > lastPartialPot.AmountToClaim)
            {
                throw new WrongIOException("Not enough partial pots were created! Something isn't right!");
            }

            //if this is a Call All-In move then make new partial pot
            if (CurrentPlayer.Wallet.AmountOfMoney == 0)
            {
                //Add new partial pot in the middle
                Pot newPartialPot = new Pot(lastPartialPot.BasePot)
                {
                    PartialPot = lastPartialPot
                };
                lastPartialPot.BasePot = newPartialPot;

                if (newPartialPot.BasePot != null)
                {
                    newPartialPot.BasePot.PartialPot = newPartialPot;
                }
                else
                {
                    currentPot = newPartialPot;
                }

                //Update partial pot's fields
                foreach (Player player in lastPartialPot.PlayersClaimPot)
                {
                    newPartialPot.PlayersClaimPot.Add(player);
                }

                lastPartialPot.PlayersClaimPot.Remove(CurrentPlayer);

                newPartialPot.AmountToClaim   = amountToAdd + lastPlayerCurrentBet;
                lastPartialPot.AmountToClaim -= newPartialPot.AmountToClaim;
                newPartialPot.Value           = lastPartialPot.Value - (lastPartialPot.AmountToClaim * lastPartialPot.PlayersClaimPot.Count);
                lastPartialPot.Value          = lastPartialPot.AmountToClaim * lastPartialPot.PlayersClaimPot.Count;
            }
        }
Esempio n. 8
0
 public void CreatePartialPot()
 {
     PartialPot = new Pot(this);
 }
Esempio n. 9
0
 public Pot(Pot basePot) : this()
 {
     BasePot = basePot;
 }