public static void SendWinningHand(Table t, HandRankings hr)
 {
     Poker.Shared.Message message = new Shared.Message("", MessageType.AnnounceWinner);
     message.Content = t.TableNo + ":" + hr.UserName + ":";
     for (int i = 0; i < 5; i++)
     {
         message.Content += hr.Cards[i].Rank + ":" + hr.Cards[i].Suit;
     }
     SendToTablePlayers(t, message);
 }
Example #2
0
        private void Form1_Load_1(object sender, EventArgs e)
        {
            this.MaximizeBox = false;
            //Table t = new Table(4);
            Deck d = Deck.GetShuffledDeck();
            Tuple <Card, Card, Card, Card, Card> hand = new Tuple <Card, Card, Card, Card, Card>(
                new Card(Suit.Diamond, Rank.Nine),
                new Card(Suit.Club, Rank.Nine),
                new Card(Suit.Spade, Rank.Nine),
                new Card(Suit.Club, Rank.Jack),
                new Card(Suit.Heart, Rank.Jack)
                );

            Tuple <Card, Card, Card, Card, Card> hand1 = new Tuple <Card, Card, Card, Card, Card>(
                new Card(Suit.Diamond, Rank.Ace),
                new Card(Suit.Club, Rank.King),
                new Card(Suit.Club, Rank.Queen),
                new Card(Suit.Club, Rank.Jack),
                new Card(Suit.Club, Rank.Ten)
                );

            Tuple <Card, Card, Card, Card, Card> hand2 = new Tuple <Card, Card, Card, Card, Card>(
                new Card(Suit.Diamond, Rank.Ace),
                new Card(Suit.Club, Rank.Two),
                new Card(Suit.Club, Rank.Three),
                new Card(Suit.Club, Rank.Four),
                new Card(Suit.Club, Rank.Five)
                );
            HandRankings h = new HandRankings(hand);

            h = new HandRankings(hand);
            h = new HandRankings(hand);
            Console.WriteLine(d.serialize());
            AllPokerHands aa = new AllPokerHands();

            aa.init();
        }
        public void init()
        {
            Deck d = Deck.GetShuffledDeck();

            Tuple <Card, Card, Card, Card, Card> hand = new Tuple <Card, Card, Card, Card, Card>(
                new Card(Suit.Diamond, Rank.Nine),
                new Card(Suit.Club, Rank.King),
                new Card(Suit.Club, Rank.Queen),
                new Card(Suit.Club, Rank.Jack),
                new Card(Suit.Club, Rank.Ten)
                );
            HandRankings h  = new HandRankings(hand);
            List <Card>  d1 = d.cards.ToList();
            List <Card>  d2 = d.cards.ToList();
            List <Card>  d3 = d.cards.ToList();
            List <Card>  d4 = d.cards.ToList();
            List <Card>  d5 = d.cards.ToList();
            List <Tuple <Card, Card, Card, Card, Card> > allpokerhands = new List <Tuple <Card, Card, Card, Card, Card> >();
            List <HandRankings> allpokerhands_1 = new List <HandRankings>();

            DateTime start   = DateTime.Now;
            int      counter = 10;

            for (int i = 0; i < d1.Count; i++)
            {
                for (int j = i + 1; j < d1.Count; j++)
                {
                    for (int k = j + 1; k < d1.Count; k++)
                    {
                        for (int l = k + 1; l < d1.Count; l++)
                        {
                            for (int m = l + 1; m < d1.Count; m++)
                            {
                                allpokerhands.Add(new Tuple <Card, Card, Card, Card, Card>(d1[i], d1[j], d1[k], d1[l], d1[m]));
                                allpokerhands_1.Add(new HandRankings(new Tuple <Card, Card, Card, Card, Card>(d1[i], d1[j], d1[k], d1[l], d1[m])));
                                //if (--counter < 0)
                                //    break;
                            }
                        }
                    }
                }
            }
            DateTime end = DateTime.Now;

            //List<HandRankings> allpokerhands_s = allpokerhands_1.Where(a => a.HandType == HandType.FOUR_OF_A_KIND).ToList();
            allpokerhands_1.Sort(new HandComparer());
            DateTime end1               = DateTime.Now;
            int      royalflushcount    = allpokerhands_1.Count(a => a.HandType == HandType.ROYAL_FLUSH);
            int      straightflushcount = allpokerhands_1.Count(a => a.HandType == HandType.STRAIGHT_FLUSH);
            int      fourofakindcount   = allpokerhands_1.Count(a => a.HandType == HandType.FOUR_OF_A_KIND);
            int      fullhousecount     = allpokerhands_1.Count(a => a.HandType == HandType.FULL_HOUSE);
            int      flushcount         = allpokerhands_1.Count(a => a.HandType == HandType.FLUSH);
            int      straightcount      = allpokerhands_1.Count(a => a.HandType == HandType.STRAIGHT);
            int      threeofakindcount  = allpokerhands_1.Count(a => a.HandType == HandType.THREE_OF_A_KIND);
            int      twopaircount       = allpokerhands_1.Count(a => a.HandType == HandType.TWO_PAIR);
            int      onepaircount       = allpokerhands_1.Count(a => a.HandType == HandType.ONE_PAIR);

            Console.WriteLine("Royal Flush count = " + royalflushcount.ToString());
            Console.WriteLine("Straight Flush count = " + straightflushcount.ToString());
            Console.WriteLine("Four of a kind count = " + fourofakindcount.ToString());
            Console.WriteLine("Full House count = " + fullhousecount.ToString());
            Console.WriteLine("Flush count = " + flushcount.ToString());
            Console.WriteLine("Straight count = " + straightcount.ToString());
            Console.WriteLine("Three of a kind count = " + threeofakindcount.ToString());
            Console.WriteLine("Two pair count = " + twopaircount.ToString());
            Console.WriteLine("One pair count = " + onepaircount.ToString());
            string s = "";
        }
Example #4
0
 public void setWinningHand(HandRankings hr)
 {
     _winninghand = hr;
 }
Example #5
0
        private void Start()
        {
            if (!((_table.SeatedPlayerCount() >= 3) && (!_GameInPogress)))
            {
                return;
            }

            if ((_game == null) || (_table == null))
            {
                throw new Exception("Table or Game cannot be null");
            }
            _GameInPogress = true;
            _GameStopFlag  = false;

            _table.SetDealerPosition();
            //deal hole cards to seated players
            int playercount = _table.SeatedPlayerCount();
            int gamecount   = 100;
            int timespan    = 33000;                    // 33 secs

            while ((gamecount > 0) && (!_GameStopFlag)) // game loop
            {
                gamecount--;
                _game.initialize();
                _table.ResetForGameStart();

                // initialize the player , resetting the folded hand state
                // Also consolidate who all players are in the game. Anybody who is not dealt a hole card should not be asked for betting

                _game.SetGameState("Starting");
                MessageFactory.SendGameUpdateMessage(_table); // this is sent to reset the board and holecards of the clients
                MessageFactory.SendTableUpdateMessage(_table);
                Thread.Sleep(5000);                           // deliberately delay to give client time to process.
                playercount = _table.SeatedPlayerCount();
                while (playercount > 0)
                {
                    Player player = _table.GetNextPlayer();
                    player.AssignDealerButton(0);
                    player.AssignHoleCards(_game.DealPlayerHand());
                    playercount--;
                }
                // do bet collecting round
                _table.ResetToUTG();
                playercount = _table.PlayingPlayerCount();
                //while (playercount > 0)
                while (playercount > 0)
                {
                    Player player = _table.GetNextPlayer();
                    if (player.InHand)
                    {
                        if (player.getPostedBetSoFar("preflop") == _table.GetCurrentMinBet())
                        {
                            break; // All players have posted their bets to completion
                        }
                        lock (_table.SynchronizeGame)
                        {
                            MessageFactory.RequestAction(_table, player, "preflop");
                            Monitor.Wait(_table.SynchronizeGame, timespan);
                        }
                    }
                    //playercount--;
                    playercount = _table.PlayingPlayerCount();
                }


                playercount = _table.PlayingPlayerCount();


                // deal the flop
                if (playercount > 1)
                {
                    Tuple <Card, Card, Card> flop = _game.GetFlop();
                    MessageFactory.SendFlop(_table, flop);
                }

                // do bet collecting round

                _table.ResetToSmallBlind();
                _table.ResetMinBet();

                while (playercount > 1)
                {
                    Player player = _table.GetNextPlayer();
                    if (player.InHand)
                    {
                        if (player.getPostedBetSoFar("postflop") == _table.GetCurrentMinBet())
                        {
                            break; // All players have posted their bets to completion
                        }
                        lock (_table.SynchronizeGame)
                        {
                            MessageFactory.RequestAction(_table, player, "postflop");
                            Monitor.Wait(_table.SynchronizeGame, timespan);
                        }
                    }
                    //playercount--;
                    playercount = _table.PlayingPlayerCount();
                }

                playercount = _table.PlayingPlayerCount();
                //deal the turn
                if (playercount > 1)
                {
                    Card turn = _game.GetTurn();
                    MessageFactory.SendTurn(_table, turn);
                }
                // do bet collecting round

                _table.ResetToSmallBlind();
                _table.ResetMinBet();

                while (playercount > 1)
                {
                    Player player = _table.GetNextPlayer();
                    if (player.InHand)
                    {
                        if (player.getPostedBetSoFar("postturn") == _table.GetCurrentMinBet())
                        {
                            break; // All players have posted their bets to completion
                        }
                        lock (_table.SynchronizeGame)
                        {
                            MessageFactory.RequestAction(_table, player, "postturn");
                            Monitor.Wait(_table.SynchronizeGame, timespan);
                        }
                    }
                    //playercount--;
                    playercount = _table.PlayingPlayerCount();
                }

                playercount = _table.PlayingPlayerCount();
                // deal the river
                if (playercount > 1)
                {
                    Card river = _game.GetRiver();
                    MessageFactory.SendRiver(_table, river);
                }
                // do the bet collecting round

                _table.ResetToSmallBlind();
                _table.ResetMinBet();

                while (playercount > 1)
                {
                    Player player = _table.GetNextPlayer();
                    if (player.InHand)
                    {
                        if (player.getPostedBetSoFar("postriver") == _table.GetCurrentMinBet())
                        {
                            break; // All players have posted their bets to completion
                        }
                        lock (_table.SynchronizeGame)
                        {
                            MessageFactory.RequestAction(_table, player, "postriver");
                            Monitor.Wait(_table.SynchronizeGame, timespan);
                        }
                    }
                    //playercount--;
                    playercount = _table.PlayingPlayerCount();
                }
                // announce the winner
                playercount = _table.PlayingPlayerCount();
                List <HandRankings> playerhands = new List <HandRankings>();
                while (playercount > 0)
                {
                    Player player = _table.GetNextPlayer();
                    if (player.InHand)
                    {
                        HandRankings besthand = HandRankings.ComputeBestHand(player, _game.GetBoard());
                        playerhands.Add(besthand);
                    }
                    playercount--;
                }
                if (playerhands.Count > 0)
                {
                    List <HandRankings> hlist = playerhands.Select(a => a).ToList <HandRankings>();
                    hlist.Sort(new HandComparer());
                    _game.setWinningHand(hlist[hlist.Count - 1]);
                }
                _game.SetGameState("Ending");
                MessageFactory.SendWinningHand(_table, _game.WinningHand);
                MessageFactory.SendGameUpdateMessage(_table);
                _GameInPogress = false;
                _table.AdvanceDealerPosition();
            }// end of game loop
        }