Esempio n. 1
0
        private void btnViewTables_Click(object sender, EventArgs e)
        {
            // list the poker clients connected to the server
            // will have ability to disconnect a client too.
            dataGridView_Tables.Rows.Clear();
            dataGridView_Tables.Columns.Clear();
            dataGridView_Tables.Columns.Add("TableNo", "TableNo");
            dataGridView_Tables.Columns.Add("PlayerCount", "PlayerCount");
            dataGridView_Tables.Columns.Add("StartGame", "StartGame");
            IEnumerable <ITable> tables = TableManager.Instance.GetRunningTables();
            int rowindex = 0;

            foreach (ITable table in tables)
            {
                Table t = (Table)table;

                dataGridView_Tables.Rows.Add(new object[] { t.TableNo, t.SeatedPlayerCount(), "Start" });
                Button bt = new Button();
                bt.Text = "Start the Game";
                //dataGridView_Tables.Controls.Add(bt);
                //bt.Location = this.dataGridView_Tables.GetCellDisplayRectangle(2,rowindex, true).Location;
                //bt.Size = this.dataGridView_Tables.GetCellDisplayRectangle(2,rowindex, true).Size;

                DataGridViewButtonCell buttonCell = new DataGridViewButtonCell();

                this.dataGridView_Tables[2, rowindex]       = buttonCell;
                this.dataGridView_Tables[2, rowindex].Value = "Start the Game";


                rowindex++;
            }
        }
Esempio n. 2
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
        }