Example #1
0
        private void AdjustHandHistory(HandHistory handHistory)
        {
            if (handHistory == null)
            {
                return;
            }

            HandHistoryUtils.UpdateAllInActions(handHistory);
            HandHistoryUtils.CalculateBets(handHistory);
            HandHistoryUtils.CalculateTotalPot(handHistory);
            HandHistoryUtils.RemoveSittingOutPlayers(handHistory);

            foreach (var player in handHistory.Players)
            {
                handHistory.HandActions
                .Where(x => x.PlayerName == player.PlayerName)
                .ForEach(x => x.PlayerName = player.PlayerNick);

                if (handHistory.HeroName == player.PlayerName)
                {
                    handHistory.HeroName = player.PlayerNick;
                }

                player.PlayerName = player.PlayerNick;
                player.PlayerNick = null;
            }
        }
Example #2
0
        private void AdjustHandHistory(HandHistory handHistory, long heroId)
        {
            // replace 1st raise with bet
            ReplaceFirstRaiseWithBet(handHistory.Flop);
            ReplaceFirstRaiseWithBet(handHistory.Turn);
            ReplaceFirstRaiseWithBet(handHistory.River);

            HandHistoryUtils.AddShowActions(handHistory);
            HandHistoryUtils.AddWinningActions(handHistory);
            HandHistoryUtils.CalculateBets(handHistory);
            HandHistoryUtils.CalculateUncalledBets(handHistory, true);
            HandHistoryUtils.CalculateTotalPot(handHistory);
            HandHistoryUtils.SortHandActions(handHistory);
            HandHistoryUtils.RemoveSittingOutPlayers(handHistory);
        }
        private void AdjustHandHistory(HandHistory history)
        {
            const decimal divider = 100m;

            if (history == null)
            {
                return;
            }

            HandHistoryUtils.UpdateAllInActions(history);
            HandHistoryUtils.CalculateBets(history);
            HandHistoryUtils.CalculateUncalledBets(history, false);
            HandHistoryUtils.CalculateTotalPot(history);
            HandHistoryUtils.RemoveSittingOutPlayers(history);

            if (history.GameDescription.IsTournament)
            {
                history.GameDescription.Tournament.BuyIn.PrizePoolValue /= divider;
                history.GameDescription.Tournament.BuyIn.KnockoutValue  /= divider;
                history.GameDescription.Tournament.BuyIn.Rake           /= divider;
                history.GameDescription.Tournament.Addon      /= divider;
                history.GameDescription.Tournament.Rebuy      /= divider;
                history.GameDescription.Tournament.Winning    /= divider;
                history.GameDescription.Tournament.Bounty     /= divider;
                history.GameDescription.Tournament.TotalPrize /= divider;
            }

            history.HandActions.ForEach(a => a.Amount = a.Amount / divider);

            history.GameDescription.Limit.SmallBlind /= divider;
            history.GameDescription.Limit.BigBlind   /= divider;
            history.GameDescription.Limit.Ante       /= divider;

            history.Players.ForEach(p =>
            {
                p.Bet           /= divider;
                p.StartingStack /= divider;
                p.Win           /= divider;
            });

            history.TotalPot /= divider;

            if (!history.GameDescription.IsTournament)
            {
                HandHistoryUtils.CalculateRake(history);
            }
        }
Example #4
0
        private void AdjustHandHistory(HandHistory handHistory)
        {
            if (handHistory == null)
            {
                return;
            }

            HandHistoryUtils.UpdateAllInActions(handHistory);
            HandHistoryUtils.CalculateBets(handHistory);
            HandHistoryUtils.CalculateUncalledBets(handHistory, true);
            HandHistoryUtils.CalculateTotalPot(handHistory);
            HandHistoryUtils.RemoveSittingOutPlayers(handHistory);

            if (handHistory.GameDescription == null)
            {
                throw new HandBuilderException(handHistory.HandId, "GameDescription must be not null.");
            }

            if (!handHistory.GameDescription.IsTournament)
            {
                const decimal divider = 100m;

                handHistory.HandActions.ForEach(a => a.Amount = a.Amount / divider);

                if (handHistory.GameDescription.Limit == null)
                {
                    throw new HandBuilderException(handHistory.HandId, "GameDescription.Limit must be not null.");
                }

                handHistory.GameDescription.Limit.SmallBlind /= divider;
                handHistory.GameDescription.Limit.BigBlind   /= divider;
                handHistory.GameDescription.Limit.Ante       /= divider;

                handHistory.Players.ForEach(p =>
                {
                    p.Bet           /= divider;
                    p.StartingStack /= divider;
                    p.Win           /= divider;
                });

                handHistory.TotalPot /= divider;
            }
        }
        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);
            }
        }