示例#1
0
        protected override void ParseExtraHandInformation(string[] handLines, HandHistorySummary handHistory)
        {
            handHistory.Rake     = 0m;
            handHistory.TotalPot = 0m;
            for (int i = handLines.Length - 1; i >= 0; i--)
            {
                string handLine = handLines[i];

                //Rake taken: $0.12
                if (handLine[0] == 'R')
                {
                    handHistory.Rake = decimal.Parse(handLine.Substring(12).TrimStart(CurrencyChars), _numberFormatInfo);
                }

                //Main pot: $1.28 won by cristimanea ($1.20)
                //Side pot 1: $0.70 won by cristimanea ($0.66)
                else if (handLine[1] == 'i' || handLine[0] == 'M')
                {
                    int colonIndex = handLine.IndexOf(':');
                    int wonIndex   = handLine.IndexOfFast(" won by");

                    handHistory.TotalPot += decimal.Parse(handLine.Substring(colonIndex + 2, wonIndex - colonIndex - 2).TrimStart(CurrencyChars), _numberFormatInfo);
                }

                // we hit the summary line
                else if (handLine[1] == 'u')
                {
                    return;
                }
            }

            throw new InvalidHandException("Couldn't find sumamry line.");
        }
        protected override void ParseExtraHandInformation(Categories lines, HandHistorySummary handHistorySummary)
        {
            var line  = lines.Summary[0];
            var items = line.Split(new string[] { " | " }, StringSplitOptions.None);

            handHistorySummary.Rake = 0;

            foreach (var item in items)
            {
                switch (item[0])
                {
                case 'T':    //Total pot $79.50
                    handHistorySummary.TotalPot = item.Substring(10).ParseAmount();
                    break;

                case 'R':    //Rake $0.46
                    var rake = item.Substring(5).ParseAmount();
                    handHistorySummary.Rake      = rake;
                    handHistorySummary.TotalPot += rake;
                    break;

                case 'J':    //JP Fee $0.04
                    var jp = item.Substring(7).ParseAmount();
                    handHistorySummary.Rake     += jp;
                    handHistorySummary.TotalPot += jp;
                    break;

                default:
                    throw new ArgumentException("Unhandled Summary item");
                }
            }
        }
示例#3
0
        protected override void ParseExtraHandInformation(string[] handLines, HandHistorySummary handHistory)
        {
            // rake is at the end of the first line of a hand history
            string line           = handLines[0];
            var    rakeStartIndex = line.LastIndexOf('=') + 2;
            var    rakeEndIndex   = line.LastIndexOf('"');
            var    rakeString     = line.Substring(rakeStartIndex, rakeEndIndex - rakeStartIndex);

            handHistory.Rake     = decimal.Parse(rakeString) / 100.0m;
            handHistory.TotalPot = handHistory.Rake;

            int winningsLine = GetWinningsLineNumberFromHandLines(handLines);

            // sum up all winnings, amount starts at index 22
            for (int k = winningsLine; k < handLines.Length - 1; k++)
            {
                // leave the loop on </Action>
                if (handLines[k][1] == '/')
                {
                    break;
                }
                string amountString = handLines[k].Substring(22, handLines[k].IndexOf('"', 22) - 22);
                handHistory.TotalPot += decimal.Parse(amountString, provider);
            }
        }
        protected HandHistorySummary ParseFullHandSummary(string[] handLines, bool isCancelled = false)
        {
            HandHistorySummary handHistorySummary = new HandHistorySummary();

            handHistorySummary.Cancelled       = isCancelled;
            handHistorySummary.DateOfHandUtc   = ParseDateUtc(handLines);
            handHistorySummary.GameDescription = ParseGameDescriptor(handLines);

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

            handHistorySummary.HandId               = ParseHandId(handLines);
            handHistorySummary.TableName            = ParseTableName(handLines);
            handHistorySummary.NumPlayersSeated     = ParsePlayers(handLines).Count;
            handHistorySummary.DealerButtonPosition = ParseDealerPosition(handLines);
            handHistorySummary.FullHandHistoryText  = string.Join("\r\n", handLines);

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

            return(handHistorySummary);
        }
        public void PlayerDisconnected()
        {
            var handText            = SampleHandHistoryRepository.GetGeneralHandHistoryText(PokerFormat.CashGame, Site, "Disconnect");
            HandHistorySummary hand = GetSummmaryParser().ParseFullHandSummary(handText, true);

            Assert.IsFalse(hand.Cancelled);
        }
        public HandHistorySummary ParseFullHandSummary(string handText, bool rethrowExceptions = false)
        {
            try
            {
                if (IsValidHand(handText) == false)
                {
                    throw new InvalidHandException(handText ?? "NULL");
                }

                HandHistorySummary handHistorySummary = new HandHistorySummary()
                {
                    DateOfHandUtc        = ParseDateUtc(handText),
                    GameDescription      = ParseGameDescriptor(handText),
                    HandId               = ParseHandId(handText),
                    TableName            = ParseTableName(handText),
                    NumPlayersSeated     = ParseNumPlayers(handText),
                    DealerButtonPosition = ParseDealerPosition(handText)
                };

                handHistorySummary.FullHandHistoryText = handText.Replace("\r", "").Replace("\n", "\r\n");

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

                //logger.Warn("Couldn't parse hand {0} with error {1}", handText, ex.Message);
                return(null);
            }
        }
        public void HandleUnformattedHand_Works()
        {
            Assert.IsTrue(GetParser().IsValidHand(_unformattedXmlHand));

            HandHistorySummary summary       = GetParser().ParseFullHandSummary(_unformattedXmlHand);
            HandHistory        fullHandParse = GetParser().ParseFullHandHistory(_unformattedXmlHand);

            Assert.AreEqual(_expectedHandId, summary.HandId, "IHandHistorySummaryParser: ParseHandId");
            Assert.AreEqual(_expectedHandId, fullHandParse.HandId, "IHandHistoryParser: ParseHandId");
            Assert.AreEqual(_expectedNumActions, fullHandParse.HandActions.Count, "IHandHistoryParser: ParseHandId");
        }
示例#8
0
        protected override void ParseExtraHandInformation(JObject JSON, HandHistorySummary summary)
        {
            var handJSON     = JSON["history"][0];
            var showdownJSON = handJSON["showDown"];

            var totalpot = showdownJSON["pot"].Value <decimal>();
            var rake     = showdownJSON["rake"]?.Value <decimal>() ?? 0m;

            summary.TotalPot = totalpot + rake;
            summary.Rake     = rake;
        }
        public HandHistory ParseFullHandHistory(string handText, bool rethrowExceptions = false)
        {
            try
            {
                if (IsValidHand(handText) == false)
                {
                    throw new InvalidHandException(handText ?? "NULL");
                }

                HandHistorySummary handHistorySummary = ParseFullHandSummary(handText, rethrowExceptions);

                HandHistory handHistory = new HandHistory()
                {
                    DateOfHandUtc        = handHistorySummary.DateOfHandUtc,
                    GameDescription      = handHistorySummary.GameDescription,
                    HandId               = handHistorySummary.HandId,
                    TableName            = handHistorySummary.TableName,
                    NumPlayersSeated     = handHistorySummary.NumPlayersSeated,
                    DealerButtonPosition = handHistorySummary.DealerButtonPosition
                };

                handHistory.FullHandHistoryText = handText.Replace("\r", "").Replace("\n", "\r\n");

                handHistory.ComumnityCards = ParseCommunityCards(handText);

                List <HandAction> handActions;
                handHistory.Players     = ParsePlayers(handText, out handActions);
                handHistory.HandActions = handActions;

                handHistory.Players = SetSittingOutPlayers(handHistory.Players, handHistory.HandActions);

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

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

                //logger.Warn("Couldn't parse hand {0} with error {1}", handText, ex.Message);
                return(null);
            }
        }
示例#10
0
        public HandHistorySummary ParseFullHandSummary(string handText, bool rethrowExceptions = false)
        {
            Lines.Clear();

            var textlines = SplitHandsLines(handText);

            Categorize(Lines, textlines);

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

                HandHistorySummary handHistorySummary = new HandHistorySummary();

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

                try
                {
                    ParseExtraHandInformation(Lines, handHistorySummary);
                }
                catch
                {
                    throw new ExtraHandParsingAction(handText);
                }

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

                logger.Warn("Couldn't parse hand {0} with error {1} and trace {2}", string.Join("\r\n", textlines), ex.Message, ex.StackTrace);
                return(null);
            }
        }
示例#11
0
        private HandHistorySummary TestFullHandHistorySummary(HandHistorySummary expectedSummary, string fileName)
        {
            string handText = SampleHandHistoryRepository.GetHandExample(PokerFormat.CashGame, Site, "ExtraHands", fileName);

            HandHistorySummary actualSummary = GetSummmaryParser().ParseFullHandSummary(handText, true);

            Assert.AreEqual(expectedSummary.GameDescription, actualSummary.GameDescription);
            Assert.AreEqual(expectedSummary.DealerButtonPosition, actualSummary.DealerButtonPosition);
            Assert.AreEqual(expectedSummary.DateOfHandUtc, actualSummary.DateOfHandUtc);
            Assert.AreEqual(expectedSummary.HandId, actualSummary.HandId);
            Assert.AreEqual(expectedSummary.NumPlayersSeated, actualSummary.NumPlayersSeated);
            Assert.AreEqual(expectedSummary.TableName, actualSummary.TableName);

            return(actualSummary);
        }
示例#12
0
        protected override void ParseExtraHandInformation(string[] handLines, HandHistorySummary handHistorySummary)
        {
            if (handHistorySummary.Cancelled)
            {
                return;
            }

            for (int i = handLines.Length - 1; i >= 0; i--)
            {
                string line = handLines[i];


                // Check for summary line:
                //  *** SUMMARY ***
                if (line[0] == '*' && line[4] == 'S')
                {
                    // Line after summary line is:
                    //  Total pot 3€ | No rake
                    // or
                    //  Total pot 62.50€ | Rake 1.50€
                    string totalLine = handLines[i + 1];

                    int lastSpaceIndex        = totalLine.LastIndexOf(' ');
                    int spaceAfterFirstNumber = totalLine.IndexOf(' ', 11);

                    string rake = totalLine.Substring(lastSpaceIndex + 1, totalLine.Length - lastSpaceIndex - 1);
                    try
                    {
                        handHistorySummary.Rake = decimal.Parse(rake, NumberStyles.AllowCurrencySymbol | NumberStyles.Number, _numberFormatInfo);
                    }
                    catch (Exception)
                    {
                        // we can't parse "rake" in No rake -> 0.00m rake paid
                        handHistorySummary.Rake = 0.0m;
                    }

                    string totalPot = totalLine.Substring(10, spaceAfterFirstNumber - 10);

                    handHistorySummary.TotalPot = decimal.Parse(totalPot, NumberStyles.AllowCurrencySymbol | NumberStyles.Number, _numberFormatInfo);

                    // the pot in the hand history already deducted the rake, so we need to readd it
                    handHistorySummary.TotalPot += handHistorySummary.Rake;
                    break;
                }
            }
        }
        protected override void ParseExtraHandInformation(string[] handLines, HandHistorySummary handHistorySummary)
        {
            if (handHistorySummary.Cancelled)
            {
                return;
            }

            for (int i = handLines.Length - 1; i >= 0; i--)
            {
                string line = handLines[i];


                // Check for summary line:
                //  *** SUMMARY ***
                if (line[0] == '*' && line[4] == 'S')
                {
                    // Line after summary line is:
                    //  Total pot 3€ | No rake
                    // or
                    //  Total pot 62.50€ | Rake 1.50€
                    string totalLine = handLines[i + 1];

                    int lastSpaceIndex        = totalLine.LastIndexOf(' ');
                    int spaceAfterFirstNumber = totalLine.IndexOf(' ', 11);

                    string rake = totalLine.Substring(lastSpaceIndex + 1, totalLine.Length - lastSpaceIndex - 1);

                    if (totalLine.EndsWithFast("No rake"))
                    {
                        handHistorySummary.Rake = 0;
                    }
                    else
                    {
                        handHistorySummary.Rake = rake.ParseAmount();
                    }

                    string totalPot = totalLine.Substring(10, spaceAfterFirstNumber - 10);

                    handHistorySummary.TotalPot = totalPot.ParseAmount();

                    // the pot in the hand history already deducted the rake, so we need to re-add it
                    handHistorySummary.TotalPot += handHistorySummary.Rake;
                    break;
                }
            }
        }
示例#14
0
        public HandHistorySummary ParseFullHandSummary(string handText, bool rethrowExceptions = false)
        {
            var JSON = GetJSONObject(handText);

            HandHistorySummary summary = new HandHistorySummary();

            summary.DateOfHandUtc        = ParseDateUtc(JSON);
            summary.DealerButtonPosition = ParseDealerPosition(JSON);
            summary.FullHandHistoryText  = handText;
            summary.HandId           = ParseHandId(JSON);
            summary.NumPlayersSeated = ParseNumPlayers(JSON);
            summary.TableName        = ParseTableName(JSON);
            summary.GameDescription  = ParseGameDescriptor(JSON);

            ParseExtraHandInformation(JSON, summary);

            return(summary);
        }
        protected override void ParseExtraHandInformation(string[] handLines, HandHistorySummary handHistorySummary)
        {
            base.ParseExtraHandInformation(handLines, handHistorySummary);

            var handHistory = handHistorySummary as HandHistory;

            if (handHistory == null || handHistory.HandActions.Count == 0)
            {
                return;
            }

            var isFastFold = IsFastFold(handHistory.TableName);

            if (!isFastFold)
            {
                return;
            }

            handHistory.GameDescription.TableType = TableType.FromTableTypeDescriptions(TableTypeDescription.FastFold);

            AdjustFastFoldHandHistory(handHistory);
        }
示例#16
0
        public void DateIssue1()
        {
            HandHistorySummary expectedSummary = new HandHistorySummary()
            {
                GameDescription = new GameDescriptor()
                {
                    PokerFormat = PokerFormat.CashGame,
                    GameType    = GameType.NoLimitHoldem,
                    Limit       = Limit.FromSmallBlindBigBlind(0.50m, 1.00m, Currency.USD),
                    SeatType    = SeatType.FromMaxPlayers(6),
                    Site        = SiteName.PokerStars,
                    TableType   = TableType.FromTableTypeDescriptions(TableTypeDescription.Regular)
                },
                DateOfHandUtc        = new DateTime(2011, 5, 7, 3, 51, 38),
                DealerButtonPosition = 4,
                HandId           = 61777648755,
                NumPlayersSeated = 4,
                TableName        = "Tezcatlipoca III"
            };

            TestFullHandHistorySummary(expectedSummary, "DateIssue1");
        }
示例#17
0
        public void PlayerWithColon()
        {
            HandHistorySummary expectedSummary = new HandHistorySummary()
            {
                GameDescription = new GameDescriptor()
                {
                    PokerFormat = PokerFormat.CashGame,
                    GameType    = GameType.NoLimitHoldem,
                    Limit       = Limit.FromSmallBlindBigBlind(0.10m, 0.25m, Currency.USD),
                    SeatType    = SeatType.FromMaxPlayers(9),
                    Site        = SiteName.PokerStars,
                    TableType   = TableType.FromTableTypeDescriptions(TableTypeDescription.Regular)
                },
                DateOfHandUtc        = new DateTime(2012, 7, 18, 16, 25, 8),
                DealerButtonPosition = 9,
                HandId           = 83504515230,
                NumPlayersSeated = 9,
                TableName        = "Hygiea IV 40-100 bb"
            };

            TestFullHandHistorySummary(expectedSummary, "PlayerWithColon");
        }
示例#18
0
        public void TableNameWithDash()
        {
            HandHistorySummary expectedSummary = new HandHistorySummary()
            {
                GameDescription = new GameDescriptor()
                {
                    PokerFormat = PokerFormat.CashGame,
                    GameType    = GameType.PotLimitOmaha,
                    Limit       = Limit.FromSmallBlindBigBlind(25.0m, 50.00m, Currency.USD),
                    SeatType    = SeatType.FromMaxPlayers(2),
                    Site        = SiteName.PokerStars,
                    TableType   = TableType.FromTableTypeDescriptions(TableTypeDescription.Regular)
                },
                DateOfHandUtc        = new DateTime(2011, 5, 19, 00, 41, 04),
                DealerButtonPosition = 1,
                HandId           = 62279382715,
                NumPlayersSeated = 2,
                TableName        = "Isildur's PLO 50"
            };

            TestFullHandHistorySummary(expectedSummary, "TableNameWithDash");
        }
示例#19
0
        public void DateIssue2()
        {
            HandHistorySummary expectedSummary = new HandHistorySummary()
            {
                GameDescription = new GameDescriptor()
                {
                    PokerFormat = PokerFormat.CashGame,
                    GameType    = GameType.NoLimitHoldem,
                    Limit       = Limit.FromSmallBlindBigBlind(1.0m, 2.00m, Currency.USD),
                    SeatType    = SeatType.FromMaxPlayers(9),
                    Site        = SiteName.PokerStars,
                    TableType   = TableType.FromTableTypeDescriptions(TableTypeDescription.Cap)
                },
                DateOfHandUtc        = new DateTime(2011, 5, 10, 11, 27, 21),
                DealerButtonPosition = 1,
                HandId           = 61910233643,
                NumPlayersSeated = 7,
                TableName        = "Toutatis III"
            };

            TestFullHandHistorySummary(expectedSummary, "DateIssue2");
        }
        public void ZoomHand()
        {
            HandHistorySummary expectedSummary = new HandHistorySummary()
            {
                GameDescription = new GameDescriptor()
                {
                    PokerFormat = PokerFormat.CashGame,
                    GameType    = GameType.PotLimitOmaha,
                    Limit       = Limit.FromSmallBlindBigBlind(1m, 2m, Currency.USD),
                    SeatType    = SeatType.FromMaxPlayers(6),
                    Site        = SiteName.PokerStars,
                    TableType   = TableType.FromTableTypeDescriptions(TableTypeDescription.Zoom)
                },
                DateOfHandUtc        = new DateTime(2014, 2, 21, 17, 45, 8),
                DealerButtonPosition = 1,
                HandId           = HandID.From(132630000000),
                NumPlayersSeated = 6,
                TableName        = "Diotima"
            };

            TestFullHandHistorySummary(expectedSummary, "ZoomHand");
        }
        protected HandHistorySummary ParseFullHandSummary(string[] handLines)
        {
            HandHistorySummary handHistorySummary = new HandHistorySummary();

            handHistorySummary.DateOfHandUtc        = ParseDateUtc(handLines);
            handHistorySummary.GameDescription      = ParseGameDescriptor(handLines);
            handHistorySummary.HandId               = ParseHandId(handLines);
            handHistorySummary.TableName            = ParseTableName(handLines);
            handHistorySummary.NumPlayersSeated     = ParsePlayers(handLines).Count;
            handHistorySummary.DealerButtonPosition = ParseDealerPosition(handLines);
            handHistorySummary.FullHandHistoryText  = string.Join("\r\n", handLines);

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

            return(handHistorySummary);
        }
 protected virtual void FinalizeHandHistorySummary(HandHistorySummary Hand)
 {
 }
示例#23
0
 protected virtual void ParseExtraHandInformation(JObject JSON, HandHistorySummary handHistorySummary)
 {
     // do nothing
 }
示例#24
0
 protected virtual void ParseExtraHandInformation(Categories lines, HandHistorySummary handHistorySummary)
 {
 }
示例#25
0
 protected virtual void ParseExtraHandInformation(string[] handLines, HandHistorySummary handHistorySummary)
 {
     // do nothing
 }