public string GetActionString(TableInfo tInfo)
        {
            string action     = "";
            int    currentBet = PreviousSituation.GetPlayerCurrentBet(PlayerName);

            if (Decision == -1)
            {
                action = "folds";
            }
            else if (Decision == 0)
            {
                action = "checks";
            }
            else if (Decision <= tInfo.SmallBlind && PreviousSituation.Deep == 0)
            {
                action = "posts small blind " + Decision;
            }
            else if (Decision <= tInfo.SmallBlind * 2 && PreviousSituation.Deep == 1)
            {
                action = "posts big blind " + Decision;
            }
            else if (Decision + currentBet <= PreviousSituation.MaxBet)
            {
                action = "calls " + Decision;
            }
            else if (PreviousSituation.MaxBet == 0)
            {
                action = "bets " + Decision;
            }
            else
            {
                action = "raises " + (Decision - (PreviousSituation.MaxBet - currentBet)) + " to " + (Decision + currentBet);
            }
            if (tInfo.Players[PlayerName] - GetPlayerPot(PlayerName) == 0)
            {
                action += " and is all-in";
            }
            return(action);
        }
        private static TableLog HandRound(StackPlayers sPlayers, TableInfo tInfo, bool showLog)
        {
            ulong     dead  = 0UL;
            ulong     board = 0UL;
            TableLog  log   = new TableLog(showLog);
            GameState state = GameState.STARTINFO;

            log.Add(state,
                    "Hand ID - " + tInfo.HandId + ", small blind - " + tInfo.SmallBlind + ", players count - " + sPlayers.Count + ", button seats on - " + (tInfo.Button + 1));
            for (int p = 0; p < sPlayers.Count; p++)
            {
                log.Add(state,
                        "Seat " + (p + 1) + ": " + sPlayers[p].Agent.GetName() + " has stack - " + sPlayers[p].Stack);
            }
            #region Streets
            List <Action> streets = new List <Action>
            {
                () =>
                {
                    // Раздаем карты
                    for (int p = 0; p < sPlayers.Count; p++)
                    {
                        sPlayers[p].Hand = Hand.RandomHand(dead, 2);
                        dead            |= sPlayers[p].Hand;
                        if (sPlayers[p].Agent.GetType() == typeof(Player))
                        {
                            log.Add(state, sPlayers[p].Agent.GetName() + " pocket cards are " + Hand.MaskToString(sPlayers[p].Hand));
                        }
                    }
                    state = GameState.PREFLOP;
                    log.Add(state, "*** " + state.ToString() + " ***");
                },
                () =>
                {
                    ulong flop = Hand.RandomHand(dead, 3);
                    board = flop;
                    dead |= flop;
                    state = GameState.FLOP;
                    log.Add(state, "*** FLOP *** [" + Hand.MaskToString(flop) + "]");
                },
                () =>
                {
                    ulong turn = Hand.RandomHand(dead, 1);
                    state = GameState.TURN;
                    log.Add(state, "*** TURN *** [" + Hand.MaskToString(board) + "]  [" + Hand.MaskToString(turn) + "]");
                    board |= turn;
                    dead  |= turn;
                },
                () =>
                {
                    ulong river = Hand.RandomHand(dead, 1);
                    state = GameState.RIVER;
                    log.Add(state, "*** RIVER *** [" + Hand.MaskToString(board) + "]  [" + Hand.MaskToString(river) + "]");
                    board |= river;
                }
            };
            #endregion
            // Создаем начальную ситуацию с пустым столом
            BoardSituation currentSituation = null;
            foreach (var street in streets)
            {
                street();
                currentSituation = new BoardSituation(currentSituation, board, "", -1);
                EmulatorPlayer player;
                while (player = sPlayers.GetNextPlayer(currentSituation, tInfo))
                {
                    int decision = -1;
                    // Если нужно ставить блайды - ставим, иначе запрашиваем ставку у агента
                    if (currentSituation.Deep == 0)
                    {
                        decision = tInfo.SmallBlind;
                    }
                    else if (currentSituation.Deep == 1)
                    {
                        decision = tInfo.SmallBlind * 2;
                    }
                    else
                    {
                        decision = player.Agent.GetDecision(currentSituation, tInfo);
                    }
                    //Проверяем верность ставки
                    int currentBet = currentSituation.GetPlayerCurrentBet(player.Agent.GetName());
                    if (decision >= 0)
                    {
                        if (decision + currentBet < currentSituation.MaxBet ||
                            sPlayers.GetNotFoldedAndNotAllInInGamePlayers() == 1 ||
                            currentSituation.RaiseCount == 3)
                        {
                            decision = currentSituation.MaxBet - currentBet;
                        }
                    }
                    if (decision > player.Stack)
                    {
                        decision = player.Stack;
                    }
                    else if (decision < -1)
                    {
                        decision = -1;
                    }
                    // Добавляем ситуацию в дерево
                    currentSituation = new BoardSituation(currentSituation, board, player.Agent.GetName(), decision);
                    log.Add(state, player.Agent.GetName() + ": " + currentSituation.GetActionString(tInfo));
                }
                if (sPlayers.IsGameOver(currentSituation, tInfo, ref log))
                {
                    break;
                }
            }
            log.Add(GameState.ENDINFO, "Game Over");
            return(log);
        }
        public EmulatorPlayer GetNextPlayer(BoardSituation currentSituation, TableInfo tInfo)
        {
            // Меняем стэк сходившего игрока
            if (currentSituation.Decision > 0)
            {
                players[GetIndexPlayerByName(currentSituation.PlayerName)].Stack -= currentSituation.Decision;
            }
            else if (currentSituation.Decision == -1 && currentSituation.PlayerName != "")
            {
                players[GetIndexPlayerByName(currentSituation.PlayerName)].Folded = true;
            }

            int sbPlayer = 0;

            if (players.Count > 2)
            {
                sbPlayer = GetNextIndexInGame(tInfo.Button);
            }
            else
            {
                sbPlayer = tInfo.Button;
            }
            if (currentSituation.Deep == 0)
            {
                return(players[sbPlayer]);
            }
            else if (currentSituation.Deep == 1)
            {
                return(players[GetNextIndexInGame(sbPlayer)]);
            }

            // Если игроков в игре и не сбросивших меньше 2х, круг закончен
            if (players.Count(p => p.Folded == false) < 2)
            {
                return(null);
            }

            int curIndex  = GetNextIndexInGame(currentSituation.PlayerName);
            int?prevIndex = null;

            if (currentSituation.PlayerName == "")
            {
                curIndex = GetNextIndexInGame(tInfo.Button);
            }
            else
            {
                prevIndex = GetIndexPlayerByName(currentSituation.PlayerName);
            }
            // Если текущий игрок выставился, берем следующего
            while (prevIndex != curIndex && (players[curIndex].Stack == 0 || players[curIndex].Folded))
            {
                if (prevIndex == null)
                {
                    prevIndex = curIndex;
                }
                curIndex = GetNextIndexInGame(curIndex);
            }
            if (curIndex == prevIndex)
            {
                return(null);
            }
            int curBet = currentSituation.GetPlayerCurrentBet(players[curIndex].Agent.GetName());

            // Если ставки заколированы и игрок уже ходил, круг закончен
            if (curBet == currentSituation.MaxBet && (currentSituation.GetActionsCount(players[curIndex].Agent.GetName()) > 0 ||
                                                      players.Count(p => p.Stack > 0 && p.Folded == false) <= 1))
            {
                return(null);
            }
            return(players[curIndex]);
        }