Beispiel #1
0
        public override bool Equals(object obj)
        {
            HandHistorySummary hand = obj as HandHistorySummary;

            if (hand == null)
            {
                return(false);
            }

            return(ToString().Equals(hand.ToString()));
        }
        public void DateIssue2()
        {
            HandHistorySummary expectedSummary = new HandHistorySummary()
            {
                GameDescription = new GameDescriptor()
                {
                    PokerFormat = PokerFormat.CashGame,
                    GameType = GameType.CapNoLimitHoldem,
                    Limit = Limit.FromSmallBlindBigBlind(1.0m, 2.00m, Currency.USD),
                    SeatType = SeatType.FromMaxPlayers(9),
                    Site = SiteName.PokerStars,
                    TableType = TableType.FromTableTypeDescriptions(TableTypeDescription.Regular)
                },
                DateOfHandUtc = new DateTime(2011, 5, 10, 11, 27, 21),
                DealerButtonPosition = 1,
                HandId = 61910233643,
                NumPlayersSeated = 7,
                TableName = "Toutatis III"
            };

            TestFullHandHistorySummary(expectedSummary, "DateIssue2");
        }
        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");
        }
        public void CancelledHand_Summary()
        {
            HandHistorySummary expectedSummary = new HandHistorySummary()
            {
                Cancelled = true,
                GameDescription = new GameDescriptor()
                {
                    PokerFormat = PokerFormat.CashGame,
                    GameType = GameType.PotLimitOmaha,
                    Limit = Limit.FromSmallBlindBigBlind(5m, 10m, Currency.USD),
                    SeatType = SeatType.FromMaxPlayers(6),
                    Site = SiteName.PokerStars,
                    TableType = TableType.FromTableTypeDescriptions(TableTypeDescription.Regular),
                },
                DateOfHandUtc = new DateTime(2014, 1, 16, 12, 17, 20),
                DealerButtonPosition = 6,
                HandId = 110222853693,
                NumPlayersSeated = 1,
                TableName = "Idelsonia III"
            };

            TestFullHandHistorySummary(expectedSummary, "CancelledHand");
        }
        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;
                }
            }
        }
        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;
        }
        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");
        }
        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");
        }
        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;
            }
        }
 protected virtual void ParseExtraHandInformation(string[] handLines, HandHistorySummary handHistorySummary)
 {
     // do nothing
 }
        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)
            {
                throw new ExtraHandParsingAction(handLines[0]);
            }

            return handHistorySummary;
        }
        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);
            }
        }
        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 = 132630000000,
                NumPlayersSeated = 6,
                TableName = "Diotima"
            };

            TestFullHandHistorySummary(expectedSummary, "ZoomHand");
        }
        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 $13.12 | Rake $0.59
                    // or
                    //  Total pot $62.63 Main pot $54.75. Side pot $5.38. | Rake $2.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);

                    handHistorySummary.Rake = decimal.Parse(rake, NumberStyles.AllowCurrencySymbol | NumberStyles.Number, _numberFormatInfo);

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

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

                    break;
                }
            }
        }
        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), NumberStyles.AllowCurrencySymbol | NumberStyles.Number, _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.IndexOf(" won by", colonIndex, StringComparison.Ordinal);

                    handHistory.TotalPot += decimal.Parse(handLine.Substring(colonIndex + 2, wonIndex - colonIndex - 2), NumberStyles.AllowCurrencySymbol | NumberStyles.Number, _numberFormatInfo);
                }

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

            throw new InvalidHandException("Couldn't find sumamry line.");
        }
        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);

            return handHistorySummary;
        }