public void Test_DetermineWinners_FullHouse_TwoWinners()
        {
            Player winner1 = new Player("Winner1", 1000);
            winner1.Cards.Add(new Card(Rank.Two, Suit.Spades));
            winner1.Cards.Add(new Card(Rank.Two, Suit.Hearts));

            Player winner2 = new Player("Winner2", 1000);
            winner2.Cards.Add(new Card(Rank.Two, Suit.Diamonds));
            winner2.Cards.Add(new Card(Rank.Two, Suit.Clubs));

            CardCollection communityCards = new CardCollection();
            communityCards.Add(new Card(Rank.Three, Suit.Hearts));
            communityCards.Add(new Card(Rank.Six, Suit.Clubs));
            communityCards.Add(new Card(Rank.King, Suit.Hearts));
            communityCards.Add(new Card(Rank.King, Suit.Spades));
            communityCards.Add(new Card(Rank.King, Suit.Diamonds));

            HandEvaluator eval = new HandEvaluator();

            Hand hand1 = eval.GetBestHand(winner1.Cards + communityCards);

            Hand hand2 = eval.GetBestHand(winner2.Cards + communityCards);

            Assert.AreEqual(0, HandEvaluator.Compare(hand1, hand2));
        }
Beispiel #2
0
        public void AddToPot(Player p, double amount, TableState tState)
        {
            //m_pcPotCollection[potIndex].AddToCurrentPot(new Bet(p, amount, tState));
            if (p.State == PlayerState.AllIn)
            {
                if (this.CurrentPot.Cap == -1)
                    this.CurrentPot.Cap = amount;
                else if (this.CurrentPot.Cap > amount)
                {
                    this.CurrentPot.Cap = amount;
                    //Cap has been reduced, must shift the pots right.
                    this.reducePotCap(amount, m_intPotIndex);
                }
            }

            if (this.CurrentPot.IsCapped && amount > this.CurrentPot.Cap)
            {
                double firstBet = this.CurrentPot.Cap;
                double secondBet = amount - firstBet;

                this.CurrentPot.AddToCurrentPot(new Bet(p, firstBet, tState));
                this.nextPot.AddToCurrentPot(new Bet(p, secondBet, tState));
            }
            else if (this.CurrentPot.IsCapped && amount < this.CurrentPot.Cap)
                throw new InvalidOperationException("The Player can only bet less than the Pot Cap if she/he is AllIn.");
            else
            {
                //The Pot is not capped, bet whatever you wish
                this.CurrentPot.AddToCurrentPot(new Bet(p, amount, tState));
                //this.CurrentPot.AddToCurrentPot(new Bet(p, firstBet, tState));
            }
        }
Beispiel #3
0
        public void AddToPot(Player player, double amount)
        {
            string pName = player.Name;

            if (m_dicPlayerBets.ContainsKey(pName))
                m_dicPlayerBets[pName] += amount;
            else
                m_dicPlayerBets.Add(pName, amount);
        }
Beispiel #4
0
        public void FillWithPlayer(Player newPlayer)
        {
            lock (SyncLock)
            {
                if (Player != null)
                    throw new InvalidOperationException("The Player property is already filled.");

                Player = newPlayer;
            }
        }
        public bool FillSlot(Player newPlayer, int pos)
        {
            lock (SyncLock)
            {
                PlayerSlot slot = SlotList[pos];

                if (slot.HasPlayer)
                    return false;

                slot.FillWithPlayer(newPlayer);

                return true;
            }
        }
Beispiel #6
0
        public double GetPlayerTotal(Player p)
        {
            double amount = 0;
            string name = p.Name;

            if (m_dicPlayerBets.ContainsKey(name))
            {
                amount = m_dicPlayerBets[name];

                if (amount <= 0)
                    m_dicPlayerBets.Remove(name);
            }

            return amount;
        }
Beispiel #7
0
 public double GetAmountPlayerRequiresToCall(Player p)
 {
     return this.GetHighestPlayerTotal() - this.GetPlayerTotal(p);
 }
        public void Test_DetermineWinners_OnePairKicker_OneWinner()
        {
            Player winner = new Player("Winner", 1000);
            winner.Cards.Add(new Card(Rank.Four, Suit.Clubs));
            winner.Cards.Add(new Card(Rank.Queen, Suit.Spades));

            Player loser = new Player("Loser", 1000);
            loser.Cards.Add(new Card(Rank.Four, Suit.Diamonds));
            loser.Cards.Add(new Card(Rank.Five, Suit.Spades));

            CardCollection communityCards = new CardCollection();
            communityCards.Add(new Card(Rank.Two, Suit.Hearts));
            communityCards.Add(new Card(Rank.Nine, Suit.Clubs));
            communityCards.Add(new Card(Rank.Four, Suit.Spades));
            communityCards.Add(new Card(Rank.Ten, Suit.Diamonds));
            communityCards.Add(new Card(Rank.Jack, Suit.Diamonds));

            HandEvaluator eval = new HandEvaluator();

            Hand winnersHand = eval.GetBestHand(winner.Cards + communityCards);

            Hand losersHand = eval.GetBestHand(loser.Cards + communityCards);

            Assert.AreEqual(true, HandEvaluator.Compare(winnersHand, losersHand) == 1 && winnersHand.HighCard.Rank == Rank.Queen);
        }
Beispiel #9
0
 public Bet(Player player, double value, TableState tState)
 {
     this.Player = player;
     this.Value = value;
     this.TableState = tState;
 }
Beispiel #10
0
 public Bet(Player player, double value)
 {
     this.Player = player;
     this.Value = value;
 }
        public PlayerDecisionResponse GetPlayerDecision(Player player, double minimumBet, DecisionType[] availableOptions)
        {
            PlayerDecisionResponse pd = new PlayerDecisionResponse();
            pd.Type = DecisionType.TimeOutAndFold;

            PlayerDecisionRequest pdr = new PlayerDecisionRequest();
            pdr.RequestId = Guid.NewGuid().ToString();
            pdr.MinimumBet = minimumBet;
            pdr.AvailableOptions = availableOptions;

            AddToOutgoingMessageQueue(GameMessageType.Client_ReceivePlayerDecisionRequest, pdr, player.ToList());

            int waitingFor = 0;
            while (waitingFor < Table.MAX_DECISION_TIME)
            {
                if (m_dicStorage.ContainsKey(pdr.RequestId))
                {
                    pd = (PlayerDecisionResponse)m_dicStorage[pdr.RequestId];
                    break;
                }

                //-- Perhaps the player has disconnected from the table
                if (Table.IsPlayerSittingAtTable(player.Name) == false)
                {
                    pd.Type = DecisionType.DisconnectAndFold;
                    break;
                }

                m_tcGameFlow.WaitHereFor(100);
                waitingFor += 100;
            }

            return pd;
        }
 public void SendPersonalAnnouncement(Player recipient, string message)
 {
     AddToOutgoingMessageQueue(GameMessageType.Client_ReceivePersonalAnnouncement, message, recipient.ToList());
 }
 public void SendJoinTableResponse(Player recipient, JoinTableResponse jtres)
 {
     AddToOutgoingMessageQueue(GameMessageType.Client_ReceiveJoinTableResponse, jtres, recipient.ToList());
 }
 private double GetAmountPlayerRequiresToCall(Player p)
 {
     return Table.PotManager.GetHighestPlayerTotal() - Table.PotManager.GetPlayerTotal(p);
 }
            private DecisionType[] GetValidOptions(Player player, double minimumBet)
            {
                List<DecisionType> options = new List<DecisionType>();
                options.Add(DecisionType.Fold); //You can fold at any time
                options.Add(DecisionType.Check);
                options.Add(DecisionType.Call);
                options.Add(DecisionType.Raise);
                options.Add(DecisionType.AllIn); //You can go all-in at any time

                if (minimumBet > 0)
                    options.Remove(DecisionType.Check); //Cannot check if you are required to be

                if (minimumBet <= 0)
                    options.Remove(DecisionType.Call); //No amount to call

                if (TurnCounter[player.Name] >= 1 || minimumBet >= player.Chips)
                    options.Remove(DecisionType.Raise); //Cannot raise when it's you second turn or you don't have enought money to raise
                                                        // the current bet

                return options.ToArray();
            }
Beispiel #16
0
        public double GetPlayerTotal(Player p)
        {
            var playerBets = from b in m_blBetList
                             where b.Player.Name == p.Name
                             select b;

            double total = 0;
            foreach (Bet bet in playerBets)
                total += bet.Value;

            return total;
        }
            private bool IsValidDecision(Player player, PlayerDecisionResponse decision, double callAmount)
            {
                //-- This method could probably use some simplification etc.. See the GetValidOptions() method.

                if (decision == null)
                    throw new NullReferenceException("The decision argument cannot be null.");

                if (callAmount > 0)
                {
                    switch (decision.Type)
                    {
                        case DecisionType.DisconnectAndFold:
                        case DecisionType.TimeOutAndFold:
                        case DecisionType.InvalidAndFold:
                        case DecisionType.Fold:
                            {
                                return true;
                            }

                        case DecisionType.Call:
                            {
                                if (callAmount >= player.Chips)
                                    return false;
                                else
                                    return true;
                            }

                        case DecisionType.AllIn:
                            return true;

                        case DecisionType.Raise:
                            {
                                if (TurnCounter[player.Name] == 0)
                                {
                                    if (decision.RaiseAmount <= callAmount)
                                        return false;
                                    else if (decision.RaiseAmount >= player.Chips)
                                        return false;
                                    else
                                        return true;
                                }
                                else
                                {
                                    //-- You cannot raise when its you second turn in the round
                                    return false;
                                }
                            }

                        case DecisionType.Check:
                            return false;

                        default:
                            throw new InvalidOperationException("An unknown DecisionType was encountered.");
                    }
                }
                else
                {
                    switch (decision.Type)
                    {
                        case DecisionType.DisconnectAndFold:
                        case DecisionType.TimeOutAndFold:
                        case DecisionType.InvalidAndFold:
                        case DecisionType.Fold:
                        case DecisionType.Check:
                        case DecisionType.AllIn:
                            return true;

                        case DecisionType.Raise:
                            {
                                if (TurnCounter[player.Name] == 0)
                                {
                                    if (decision.RaiseAmount <= callAmount)
                                        return false;
                                    else if (decision.RaiseAmount >= player.Chips)
                                        return false;
                                    else
                                        return true;
                                }
                                else
                                {
                                    //-- You cannot raise when its you second turn in the round
                                    return false;
                                }
                            }

                        case DecisionType.Call:
                            return false;

                        default:
                            throw new InvalidOperationException("An unknown DecisionType was encountered.");
                    }
                }
            }
            private void HandlePlayerDecision(Player player, PlayerDecisionResponse decision)
            {
                switch (decision.Type)
                {
                    case DecisionType.DisconnectAndFold:
                    case DecisionType.TimeOutAndFold:
                    case DecisionType.InvalidAndFold:
                    case DecisionType.Fold:
                        player.State = PlayerState.Folded;
                        break;

                    case DecisionType.Check:
                        player.State = PlayerState.Playing;
                        break;

                    case DecisionType.Call:
                        {
                            double callAmount = GetAmountPlayerRequiresToCall(player);
                            Table.PotManager.AddToPot(player, player.HandOverChips(callAmount));
                            player.State = PlayerState.Playing;
                            break;
                        }

                    case DecisionType.Raise:
                        {
                            Table.PotManager.AddToPot(player, player.HandOverChips(decision.RaiseAmount));
                            player.State = PlayerState.Playing;
                            break;
                        }

                    case DecisionType.AllIn:
                        {
                            Table.PotManager.AddToPot(player, player.AllIn());
                            player.State = PlayerState.AllIn;
                            break;
                        }

                    default:
                        throw new InvalidOperationException("An unknown DecisionType was encountered.");
                }
            }
 public void SendForcedTableDisconnectionNotice(Player recipient, string reason)
 {
     ForcedTableLeaveNotice fln = new ForcedTableLeaveNotice();
     fln.TableId = Table.TableId;
     fln.Message = reason;
     fln.PlayerName = recipient.Name;
     AddToOutgoingMessageQueue(GameMessageType.Client_ReceiveForcedTableLeaveNotice, fln, recipient.ToList());
 }
Beispiel #20
0
        public void Test_DetermineWinner_FullHouse_OneWinner()
        {
            Player winner = new Player("Winner", 1000);
            winner.Cards.Add(new Card(Rank.King, Suit.Diamonds));
            winner.Cards.Add(new Card(Rank.Eight, Suit.Hearts));

            Player loser = new Player("Loser", 1000);
            loser.Cards.Add(new Card(Rank.Two, Suit.Spades));
            loser.Cards.Add(new Card(Rank.Seven, Suit.Hearts));

            CardCollection communityCards = new CardCollection();
            communityCards.Add(new Card(Rank.Two, Suit.Hearts));
            communityCards.Add(new Card(Rank.Two, Suit.Clubs));
            communityCards.Add(new Card(Rank.King, Suit.Hearts));
            communityCards.Add(new Card(Rank.King, Suit.Spades));
            communityCards.Add(new Card(Rank.Queen, Suit.Diamonds));

            HandEvaluator eval = new HandEvaluator();

            Hand winnersHand = eval.GetBestHand(winner.Cards + communityCards);

            Hand losersHand = eval.GetBestHand(loser.Cards + communityCards);

            Assert.AreEqual(1, HandEvaluator.Compare(winnersHand, losersHand));
        }