コード例 #1
0
        private HandAction ParseActionFromActionLine(string handLine, Street street, PlayerList playerList, List <HandAction> actions)
        {
            bool AllIn      = false;
            var  actionType = GetActionTypeFromActionLine(handLine);

            decimal value = GetValueFromActionLine(handLine);

            int actionNumber = GetActionNumberFromActionLine(handLine);

            if (actionNumber == -1 || actionType == HandActionType.UNKNOWN)
            {
                return(null);
            }

            int    playerSeat = GetPlayerSeatFromActionLine(handLine);
            string playerName = playerList.First(p => p.SeatNumber == playerSeat).PlayerName;

            if (actionType == HandActionType.ALL_IN)
            {
                AllIn      = true;
                actionType = AllInActionHelper.GetAllInActionType(playerName, value, street, actions);
            }

            return(new HandAction(playerName, actionType, value, street, AllIn, actionNumber));
        }
コード例 #2
0
        public List <HandAction> ParseHandActions(string handText, out List <WinningsAction> winners)
        {
            try
            {
                var handactions = ParseHandActions(GetCategories(handText).Action, out winners);

                if (RequiresAdjustedRaiseSizes)
                {
                    handactions = RaiseAdjuster.AdjustRaiseSizes(handactions);
                }
                if (RequiresAllInDetection)
                {
                    var playerList = ParsePlayers(Lines.Seat);
                    handactions = AllInActionHelper.IdentifyAllInActions(playerList, handactions);
                }
                if (RequiresAllInUpdates)
                {
                    handactions = AllInActionHelper.UpdateAllInActions(handactions);
                }
                if (RequiresUncalledBetWinAdjustment)
                {
                    winners = UncalledBet.FixUncalledBetWins(handactions, winners);
                }

                return(handactions);
            }
            catch (Exception ex)
            {
                throw new HandActionException(handText, "ParseHandActions: Error:" + ex.Message + " Stack:" + ex.StackTrace);
            }
        }
コード例 #3
0
        public static HandAction ParseActionFromActionLine(string handLine, Street street, PlayerList playerList, List <HandAction> actions)
        {
            bool AllIn      = false;
            var  actionType = GetActionTypeFromActionLine(handLine);

            if (actionType == HandActionType.UNKNOWN)
            {
                return(null);
            }

            int actionNumber = GetActionNumberFromActionLine(handLine);

            if (actionNumber == -1)
            {
                return(null);
            }

            decimal value = GetValueFromActionLine(handLine);

            int    playerSeat = GetPlayerSeatFromActionLine(handLine);
            string playerName = playerList.First(p => p.SeatNumber == playerSeat).PlayerName;

            if (actionType == HandActionType.ALL_IN)
            {
                AllIn = true;
                bool BBposted = actions.FirstOrDefault(p => p.HandActionType == HandActionType.BIG_BLIND) != null;
                if (!BBposted)
                {
                    actionType = HandActionType.BIG_BLIND;
                }
                bool SBposted = actions.FirstOrDefault(p => p.HandActionType == HandActionType.SMALL_BLIND) != null;
                if (!SBposted)
                {
                    actionType = HandActionType.SMALL_BLIND;
                }

                if (SBposted && BBposted)
                {
                    actionType = AllInActionHelper.GetAllInActionType(playerName, value, street, actions);
                }
            }

            //Bet may occur during preflop, we need to change that to a raise
            if (street == Street.Preflop && actionType == HandActionType.BET)
            {
                actionType = HandActionType.RAISE;
            }

            return(new HandAction(playerName, actionType, value, street, AllIn, actionNumber));
        }
        public List <HandAction> ParseHandActions(string handText, out List <WinningsAction> winners)
        {
            try
            {
                string[]          handLines   = SplitHandsLines(handText);
                GameType          gameType    = ParseGameType(handLines);
                List <HandAction> handActions = ParseHandActions(handLines, gameType, out winners);

                if (RequiresActionSorting)
                {
                    handActions = OrderHandActions(handActions);
                }
                if (RequiresAdjustedRaiseSizes)
                {
                    handActions = RaiseAdjuster.AdjustRaiseSizes(handActions);
                }
                if (RequiresAllInDetection)
                {
                    var playerList = ParsePlayers(handLines);

                    handActions = AllInActionHelper.IdentifyAllInActions(playerList, handActions);
                }

                if (RequiresAllInUpdates)
                {
                    handActions = AllInActionHelper.UpdateAllInActions(handActions);
                }

                if (RequiresUncalledBetWinAdjustment)
                {
                    winners = UncalledBet.FixUncalledBetWins(handActions, winners);
                }

                return(handActions);
            }
            catch (Exception ex)
            {
                throw new HandActionException(handText, "ParseHandActions: Error:" + ex.Message + " Stack:" + ex.StackTrace);
            }
        }
コード例 #5
0
        public HandHistory ParseFullHandHistory(string handText, bool rethrowExceptions = false)
        {
            GetCategories(handText);

            try
            {
                bool isCancelled;
                if (IsValidOrCancelledHand(Lines, out isCancelled) == false)
                {
                    throw new InvalidHandException(handText);
                }

                //Set members outside of the constructor for easier performance analysis
                HandHistory handHistory = new HandHistory();

                handHistory.FullHandHistoryText = handText;
                handHistory.DateOfHandUtc       = ParseDateUtc(Lines.Header);
                handHistory.GameDescription     = ParseGameDescriptor(Lines.Header);
                handHistory.HandId               = ParseHandId(Lines.Header);
                handHistory.TableName            = ParseTableName(Lines.Header);
                handHistory.DealerButtonPosition = ParseDealerPosition(Lines.Header);
                handHistory.CommunityCards       = ParseCommunityCards(Lines.Summary);
                handHistory.Cancelled            = isCancelled;
                handHistory.Players              = ParsePlayers(Lines.Seat);
                handHistory.NumPlayersSeated     = handHistory.Players.Count;

                string heroName = ParseHeroName(Lines.Other);
                handHistory.Hero = handHistory.Players.FirstOrDefault(p => p.PlayerName == heroName);

                if (handHistory.Cancelled)
                {
                    return(handHistory);
                }

                if (handHistory.Players.Count(p => p.IsSittingOut == false) <= 1)
                {
                    throw new PlayersException(handText, "Only found " + handHistory.Players.Count + " players with actions.");
                }

                //    if (SupportRunItTwice)
                //    {
                //        handHistory.RunItTwiceData = ParseRunItTwice(handLines);
                //    }

                List <WinningsAction> winners;
                handHistory.HandActions = ParseHandActions(Lines.Action, out winners);
                handHistory.Winners     = winners;

                if (RequiresAdjustedRaiseSizes)
                {
                    handHistory.HandActions = RaiseAdjuster.AdjustRaiseSizes(handHistory.HandActions);
                }
                if (RequiresAllInDetection)
                {
                    var playerList = ParsePlayers(Lines.Seat);
                    handHistory.HandActions = AllInActionHelper.IdentifyAllInActions(playerList, handHistory.HandActions);
                }

                if (RequiresAllInUpdates)
                {
                    handHistory.HandActions = AllInActionHelper.UpdateAllInActions(handHistory.HandActions);
                }

                if (RequiresUncalledBetFix)
                {
                    handHistory.HandActions = UncalledBet.Fix(handHistory.HandActions);
                }

                if (RequiresUncalledBetWinAdjustment)
                {
                    winners = UncalledBet.FixUncalledBetWins(handHistory.HandActions, winners);
                }

                //Pot calculation mus be done after uncalledBetFix
                if (RequiresTotalPotCalculation)
                {
                    handHistory.TotalPot = PotCalculator.CalculateTotalPot(handHistory);
                    handHistory.Rake     = PotCalculator.CalculateRake(handHistory);
                }

                HandAction anteAction = handHistory.HandActions.FirstOrDefault(a => a.HandActionType == HandActionType.ANTE);
                if (anteAction != null && handHistory.GameDescription.PokerFormat.Equals(PokerFormat.CashGame))
                {
                    handHistory.GameDescription.Limit.IsAnteTable = true;
                    handHistory.GameDescription.Limit.Ante        = Math.Abs(anteAction.Amount);
                }

                ParseExtraHandInformation(Lines, handHistory);

                if (handHistory.Players.All(p => p.SeatNumber != handHistory.DealerButtonPosition))
                {
                    throw new InvalidHandException(handText, "Dealer not found");
                }

                FinalizeHand(handHistory);

                SetActionNumbers(handHistory);

                Lines.Clear();
                return(handHistory);
            }
            catch (Exception ex)
            {
                if (rethrowExceptions)
                {
                    throw;
                }

                logger.Warn("Couldn't parse hand {0} with error {1} and trace {2}", handText, ex.Message, ex.StackTrace);
                return(null);
            }
        }
コード例 #6
0
        public static HandAction ParseRegularAction(string line, Street currentStreet, PlayerList playerList, List <HandAction> actions, bool PlayerWithSpaces)
        {
            string PlayerName = PlayerWithSpaces ?
                                GetPlayerNameWithSpaces(line, playerList) :
                                GetPlayerNameWithoutSpaces(line);

            int  actionIDIndex = actionPlayerNameStartIndex + PlayerName.Length + 1;
            char actionID      = line[actionIDIndex];

            switch (actionID)
            {
            //Player PersnicketyBeagle folds
            case 'f':
                return(new HandAction(PlayerName, HandActionType.FOLD, 0, currentStreet));

            case 'r':
                return(new HandAction(PlayerName, HandActionType.RAISE, ParseActionAmountAfterPlayer(line), currentStreet));

            //checks or calls
            case 'c':
                //Player butta21 calls (20)
                //Player jayslowplay caps (3.50)
                //Player STOPCRYINGB79 checks
                char actionID2 = line[actionIDIndex + 2];
                if (actionID2 == 'e')
                {
                    return(new HandAction(PlayerName, HandActionType.CHECK, 0, currentStreet));
                }
                else if (actionID2 == 'l')
                {
                    return(new HandAction(PlayerName, HandActionType.CALL, ParseActionAmountAfterPlayer(line), currentStreet));
                }
                else if (actionID2 == 'p')
                {
                    var capAmount     = ParseActionAmountAfterPlayer(line);
                    var capActionType = AllInActionHelper.GetAllInActionType(PlayerName, capAmount, currentStreet, actions);
                    return(new HandAction(PlayerName, capActionType, capAmount, currentStreet, true));
                }
                else
                {
                    throw new NotImplementedException("HandActionType: " + line);
                }

            case 'b':
                if (currentStreet == Street.Preflop)
                {
                    return(new HandAction(PlayerName, HandActionType.RAISE, ParseActionAmountAfterPlayer(line), currentStreet));
                }
                else
                {
                    return(new HandAction(PlayerName, HandActionType.BET, ParseActionAmountAfterPlayer(line), currentStreet));
                }

            //Player PersnicketyBeagle allin (383)
            case 'a':
                var allinAmount     = ParseActionAmountAfterPlayer(line);
                var allinActionType = AllInActionHelper.GetAllInActionType(PlayerName, allinAmount, currentStreet, actions);
                return(new HandAction(PlayerName, allinActionType, allinAmount, currentStreet, true));

            case 'm':    //Player PersnicketyBeagle mucks cards
            case 'i':    //Player ECU7184 is timed out.
                return(null);
            }
            throw new HandActionException(line, "HandActionType: " + line);
        }
        void TestAdjustedCallAllInAmount(decimal amount, List <HandAction> actions, decimal expectedAmount)
        {
            var result = AllInActionHelper.GetAdjustedCallAllInAmount(amount, actions);

            Assert.AreEqual(expectedAmount, result);
        }
コード例 #8
0
        public virtual HandHistory ParseFullHandHistory(string handText, bool rethrowExceptions = false)
        {
            var handHistory = new HandHistory();

            try
            {
                handText = ClearHandHistory(handText);

                if (string.IsNullOrEmpty(handText))
                {
                    return(null);
                }

                string[] handLines = SplitHandsLines(handText);

                // parse summary hand
                if (IsSummaryHand(handLines))
                {
                    return(ParseSummaryHand(handLines, handHistory));
                }

                if (!IsValidOrCanceledHand(handLines, out bool isCancelled))
                {
                    throw new InvalidHandException(handText ?? "NULL");
                }

                //Set members outside of the constructor for easier performance analysis
                handHistory.DateOfHandUtc   = ParseDateUtc(handLines);
                handHistory.GameDescription = ParseGameDescriptor(handLines);

                if (handHistory.GameDescription.PokerFormat == PokerFormat.Tournament)
                {
                    handHistory.GameDescription.Tournament = ParseTournament(handLines);
                }

                handHistory.HandId               = ParseHandId(handLines);
                handHistory.TableName            = ParseTableName(handLines);
                handHistory.DealerButtonPosition = ParseDealerPosition(handLines);
                handHistory.FullHandHistoryText  = string.Join("\r\n", handLines);
                handHistory.CommunityCards       = ParseCommunityCards(handLines);
                handHistory.Cancelled            = isCancelled;

                handHistory.Players          = ParsePlayers(handLines);
                handHistory.NumPlayersSeated = handHistory.Players.Count;

                var heroName = ParseHeroName(handLines, handHistory.Players);

                if (!string.IsNullOrEmpty(heroName))
                {
                    handHistory.Hero = handHistory.Players.FirstOrDefault(p => p.PlayerName == heroName);
                }

                if (handHistory.Cancelled)
                {
                    return(handHistory);
                }

                if (handHistory.Players.Count(p => p.IsSittingOut == false) <= 1)
                {
                    throw new PlayersException(handText, "Only found " + handHistory.Players.Count + " players with actions.");
                }

                handHistory.HandActions = ParseHandActions(handLines, handHistory.GameDescription.GameType);

                if (handHistory.GameDescription.Limit.BigBlind == 0 || handHistory.GameDescription.Limit.SmallBlind == 0)
                {
                    ParseBlinds(handHistory);
                }

                if (RequiresActionSorting)
                {
                    handHistory.HandActions = OrderHandActions(handHistory.HandActions, handHistory.Players, handHistory);
                }

                if (RequiresAdjustedRaiseSizes)
                {
                    handHistory.HandActions = AdjustRaiseSizes(handHistory.HandActions);
                }

                if (RequiresAllInDetection)
                {
                    handHistory.HandActions = AllInActionHelper.IdentifyAllInActions(handHistory.Players, handHistory.HandActions);
                }

                if (RequiresAllInUpdates)
                {
                    handHistory.HandActions = AllInActionHelper.UpdateAllInActions(handHistory.HandActions);
                }

                if (RequiresSeatTypeAdjustment)
                {
                    AdjustSeatTypes(handHistory);
                }

                if (handHistory.GameDescription.IsTournament && RequiresTournamentSpeedAdjustment)
                {
                    AdjustTournamentSpeed(handHistory);
                }

                if (RequiresUncalledBetCalculations)
                {
                    CalculateUncalledBets(handLines, handHistory);
                }

                if (handHistory.TotalPot == null)
                {
                    HandHistoryUtils.CalculateTotalPot(handHistory);
                }

                HandAction anteAction = handHistory.HandActions.FirstOrDefault(a => a.HandActionType == HandActionType.ANTE);

                if (!handHistory.GameDescription.Limit.IsAnteTable && anteAction != null)
                {
                    handHistory.GameDescription.Limit.IsAnteTable = true;
                    handHistory.GameDescription.Limit.Ante        = Math.Abs(anteAction.Amount);
                }

                try
                {
                    ParseExtraHandInformation(handLines, handHistory);
                }
                catch (Exception)
                {
                    throw new ExtraHandParsingAction(handLines[0]);
                }

                // remove inactive players
                var players = handHistory.HandActions.Where(x => x.Street == Street.Preflop).Select(x => x.PlayerName).ToList();

                foreach (var player in handHistory.Players.ToList())
                {
                    if (players.Contains(player.PlayerName))
                    {
                        if (RequiresBetWinAdjustment)
                        {
                            var playerActions = handHistory.HandActions.Where(x => x.PlayerName.Equals(player.PlayerName));

                            if (playerActions != null && playerActions.Any())
                            {
                                player.Win = playerActions.Where(x => x.IsWinningsAction).Sum(x => x.Amount);
                                player.Bet = Math.Abs(playerActions.Where(x => x.Amount < 0).Sum(x => x.Amount));

                                var uncalledBet = playerActions.Where(x => x.HandActionType == HandActionType.UNCALLED_BET).Sum(x => x.Amount);
                                player.Bet -= uncalledBet;
                            }
                        }

                        continue;
                    }

                    handHistory.Players.Remove(player);
                }

                return(handHistory);
            }
            catch (Exception ex)
            {
                if (rethrowExceptions)
                {
                    throw;
                }

                LogProvider.Log.Warn(this, string.Format("Couldn't parse hand {0} with error {1} and trace {2}", handText, ex.Message, ex.StackTrace));

                handHistory.Exception = ex;

                return(handHistory);
            }
        }
        void TestAllInActionHelper(string playerName, decimal amount, Street street, List <HandAction> actions, HandActionType expectedAllInActionType)
        {
            var result = AllInActionHelper.GetAllInActionType(playerName, amount, street, actions);

            Assert.AreEqual(expectedAllInActionType, result);
        }
コード例 #10
0
        private HandAction ParseAction(string Line, Street currentStreet, List <HandAction> actions)
        {
            const int playerHandActionStartIndex = 21;
            const int fixedAmountDistance        = 9;

            char   handActionType = Line[playerHandActionStartIndex];
            int    playerNameStartIndex;
            string playerName;

            switch (handActionType)
            {
            //<ACTION TYPE="ACTION_ALLIN" PLAYER="SAMERRRR" VALUE="15972.51"></ACTION>
            case 'A':
                playerNameStartIndex = playerHandActionStartIndex + 15;
                playerName           = GetActionPlayerName(Line, playerNameStartIndex);
                decimal        amount    = GetActionAmount(Line, playerNameStartIndex + playerName.Length + fixedAmountDistance);
                HandActionType allInType = AllInActionHelper.GetAllInActionType(playerName, amount, currentStreet, actions);
                if (allInType == HandActionType.CALL)
                {
                    amount = AllInActionHelper.GetAdjustedCallAllInAmount(amount, actions.Player(playerName));
                }

                return(new HandAction(playerName, allInType, amount, currentStreet, true));

            //<ACTION TYPE="ACTION_BET" PLAYER="ItalyToast" VALUE="600.00"></ACTION>
            case 'B':
                playerNameStartIndex = playerHandActionStartIndex + 13;
                playerName           = GetActionPlayerName(Line, playerNameStartIndex);
                return(new HandAction(
                           playerName,
                           HandActionType.BET,
                           GetActionAmount(Line, playerNameStartIndex + playerName.Length + fixedAmountDistance),
                           currentStreet
                           ));

            //<ACTION TYPE="ACTION_CHECK" PLAYER="gasmandean"></ACTION>
            //<ACTION TYPE="ACTION_CALL" PLAYER="fatima1975" VALUE="0.04"></ACTION>
            case 'C':
                if (Line[playerHandActionStartIndex + 1] == 'H')
                {
                    playerNameStartIndex = playerHandActionStartIndex + 15;
                    playerName           = GetActionPlayerName(Line, playerNameStartIndex);
                    return(new HandAction(
                               playerName,
                               HandActionType.CHECK,
                               0,
                               currentStreet
                               ));
                }
                else
                {
                    playerNameStartIndex = playerHandActionStartIndex + 14;
                    playerName           = GetActionPlayerName(Line, playerNameStartIndex);
                    return(new HandAction(
                               playerName,
                               HandActionType.CALL,
                               GetActionAmount(Line, playerNameStartIndex + playerName.Length + fixedAmountDistance),
                               currentStreet
                               ));
                }

            //<ACTION TYPE="ACTION_FOLD" PLAYER="Belanak"></ACTION>
            case 'F':
                playerNameStartIndex = playerHandActionStartIndex + 14;
                playerName           = GetActionPlayerName(Line, playerNameStartIndex);
                return(new HandAction(
                           playerName,
                           HandActionType.FOLD,
                           0,
                           currentStreet
                           ));

            //<ACTION TYPE="ACTION_RAISE" PLAYER="ItalyToast" VALUE="400.00"></ACTION>
            case 'R':
                playerNameStartIndex = playerHandActionStartIndex + 15;
                playerName           = GetActionPlayerName(Line, playerNameStartIndex);
                return(new HandAction(
                           playerName,
                           HandActionType.RAISE,
                           GetActionAmount(Line, playerNameStartIndex + playerName.Length + fixedAmountDistance),
                           currentStreet
                           ));

            default:
                throw new ArgumentOutOfRangeException("Unkown hand action: " + handActionType + " - " + Line);
            }
        }