Example #1
0
        protected override List <HandAction> AdjustHandActions(List <HandAction> actions)
        {
            actions = RaiseAdjuster.AdjustRaiseSizesAndCalls(actions);
            actions = UncalledBet.Fix(actions);

            return(actions);
        }
Example #2
0
        void TestUncalledbetWinsAdjustment(string expectedPlayer, decimal expectedWinAmount, List <HandAction> handActions, List <WinningsAction> winners)
        {
            var fixedWinners = UncalledBet.FixUncalledBetWins(UncalledBet.Fix(handActions), winners);
            var lastAction   = fixedWinners.Last();

            Assert.AreEqual(expectedPlayer, lastAction.PlayerName);
            Assert.AreEqual(expectedWinAmount, lastAction.Amount);
        }
Example #3
0
        void TestUncalledbet(string expectedPlayer, decimal?expectedAmount, HandHistory hand)
        {
            var actions = UncalledBet.Fix(hand.HandActions);

            var lastAction = actions.FirstOrDefault(p => p.HandActionType == HandActionType.UNCALLED_BET);

            if (expectedAmount == null)
            {
                Assert.AreEqual(null, lastAction);
            }
            else
            {
                Assert.AreEqual(expectedPlayer, lastAction.PlayerName);
                Assert.AreEqual(expectedAmount, lastAction.Amount);
            }
        }
Example #4
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);
            }
        }