コード例 #1
0
        public HandHistory ParseFullHandHistory(string[] handLines, bool rethrowExceptions = false)
        {
            //Set members outside of the constructor for easier performance analysis
            HandHistory handHistory = new HandHistory();

            try
            {
                bool isCancelled;
                if (IsValidOrCancelledHand(handLines, out isCancelled) == false)
                {
                    throw new InvalidHandException(string.Join("\r\n", handLines));
                }

                handHistory.FullHandHistoryText = string.Join("\r\n", handLines);
                handHistory.DateOfHandUtc       = ParseDateUtc(handLines);
                handHistory.GameDescription     = ParseGameDescriptor(handLines);
                handHistory.HandId               = ParseHandId(handLines);
                handHistory.TableName            = ParseTableName(handLines);
                handHistory.DealerButtonPosition = ParseDealerPosition(handLines);
                handHistory.ComumnityCards       = ParseCommunityCards(handLines);
                handHistory.Cancelled            = isCancelled;
                handHistory.Players              = ParsePlayers(handLines);
                handHistory.NumPlayersSeated     = handHistory.Players.Count;
                string heroName = ParseHeroName(handLines);
                handHistory.Hero        = handHistory.Players.FirstOrDefault(p => p.PlayerName == heroName);
                handHistory.HandActions = ParseHandActions(handLines, handHistory.GameDescription.GameType);

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

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

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

                if (RequiresActionSorting)
                {
                    handHistory.HandActions = OrderHandActions(handHistory.HandActions);
                }
                if (RequiresAdjustedRaiseSizes)
                {
                    handHistory.HandActions = AdjustRaiseSizes(handHistory.HandActions);
                }
                if (RequiresAllInDetection)
                {
                    handHistory.HandActions = IdentifyAllInActions(handLines, handHistory.HandActions);
                }
                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);
                }

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

                if (RequiresSittingOutAssesment)
                {
                    handHistory.Players = FindSittingOutPlayers(handHistory);
                }
                handHistory.HandActions = FixShowdownHands(handHistory.HandActions, handHistory.NumPlayersActive);
                if (AmountsAsBigBlindMultiples)
                {
                    handHistory.Normalise(handHistory.GameDescription.Limit.BigBlind);
                }
            }
            catch (Exception ex)
            {
                if (rethrowExceptions)
                {
                    throw;
                }

                logger.Warn("Couldn't parse hand {0} with error {1} and trace {2}", string.Join("\r\n", handLines), ex.Message, ex.StackTrace);
                return(null);
            }
            return(handHistory);
        }