Example #1
0
        private void Showdown(Card[] board, ref List <int> winningPlayers, int lastToAct)
        {
            int  currPlayer = GetNextActivePlayer(lastToAct);
            int  firstToAct = currPlayer;
            Hand overallBestHand;

            // evaluate and show hand for first player to act - flag them as winning for now
            overallBestHand = Hand.FindPlayersBestHand(players[firstToAct].HoleCards(), board);
            BroadcastPlayerHand(firstToAct, overallBestHand);
            winningPlayers.Add(firstToAct);

            // Loop through other active players
            currPlayer = GetNextActivePlayer(currPlayer);

            do
            {
                ServerHoldemPlayer player = players[currPlayer];
                eActionType        playersAction;
                int playersAmount;

                // if not first to act then player may fold without showing cards
                player.GetAction(eStage.STAGE_SHOWDOWN, 0, 0, 0, 0, potSize, out playersAction, out playersAmount);

                if (playersAction == eActionType.ACTION_FOLD)
                {
                    BroadcastAction(eStage.STAGE_SHOWDOWN, currPlayer, playersAction, 0);
                }
                else
                {
                    Hand playerBestHand = Hand.FindPlayersBestHand(player.HoleCards(), board);
                    BroadcastPlayerHand(currPlayer, playerBestHand);

                    int result = Hand.compareHands(overallBestHand, playerBestHand);
                    if (result == 1)
                    {
                        // this hand is better than current best hand
                        winningPlayers.Clear();
                    }

                    if (result >= 0)
                    {
                        // this hand is equal to or better than current best hand
                        overallBestHand = playerBestHand;
                        winningPlayers.Add(player.PlayerNum);
                    }
                }

                currPlayer = GetNextActivePlayer(currPlayer);
            } while (currPlayer != firstToAct);
        }
        internal void UpdatePlayer(ServerHoldemPlayer player)
        {
            var                pos   = _playerPositions[player.PlayerNum];
            var                x     = pos.X;
            var                y     = pos.Y;
            var                stack = player.StackSize + "     ";
            ConsoleLine        playerName;
            ConsoleLine        stackSize;
            var                holeCards = player.HoleCards();
            List <ConsoleLine> cards;

            switch (pos.Type)
            {
            case PositionType.Top:
                playerName = new ConsoleLine(x, y, player.Name);
                stackSize  = new ConsoleLine(x, y + 1, stack);
                cards      = BuildCards(holeCards, x, y + 5, player.IsAlive);
                break;

            case PositionType.Right:
                playerName = new ConsoleLine(x + 15, y, player.Name);
                stackSize  = new ConsoleLine(x + 15, y + 1, stack);
                cards      = BuildCards(holeCards, x, y, player.IsAlive);
                break;

            case PositionType.Bottom:
                playerName = new ConsoleLine(x, y + 7, player.Name);
                stackSize  = new ConsoleLine(x, y + 8, stack);
                cards      = BuildCards(holeCards, x, y, player.IsAlive);
                break;

            case PositionType.Left:
                playerName = new ConsoleLine(x, y, player.Name);
                stackSize  = new ConsoleLine(x, y + 1, stack);
                cards      = BuildCards(holeCards, x + 12, y, player.IsAlive);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            DrawLines(new List <ConsoleLine> {
                playerName, stackSize
            }, ConsoleColor.Black, ConsoleColor.White);
            DrawLines(cards, ConsoleColor.White, ConsoleColor.Black);
        }