Exemplo n.º 1
0
        public void TableDescriptionIsParsedTest(string handHistoryFile, TableTypeDescription tableDescription)
        {
            var parser = new Poker888FastParserImpl();

            string rawHands = File.ReadAllText(handHistoryFile);
            var    hands    = parser.SplitUpMultipleHands(rawHands).ToArray();

            var succeded = 0;
            var total    = hands.Count();

            for (int i = 0; i < total; i++)
            {
                HandHistory hand = parser.ParseFullHandHistory(hands[i], true);
                var         tableTypeDescription = hand.GameDescription.TableType.FirstOrDefault();

                if (tableTypeDescription == tableDescription)
                {
                    succeded++;
                }
            }

            Assert.AreEqual(total, succeded);

            Debug.WriteLine("Processed hands: {0}/{1}", succeded, total);
        }
Exemplo n.º 2
0
        public void HandIdIsParsedTest(string handHistoryFile, long[] handsId)
        {
            var parser = new Poker888FastParserImpl();

            string rawHands = File.ReadAllText(handHistoryFile);
            var    hands    = parser.SplitUpMultipleHands(rawHands).ToArray();

            if (handsId.Length != hands.Count())
            {
                throw new InvalidDataException(hands.Count() > handsId.Length
                    ? "Too many hands."
                    : "Too many ids.");
            }

            var succeded = 0;
            var total    = hands.Count();

            for (int i = 0; i < total; i++)
            {
                HandHistory hand = parser.ParseFullHandHistory(hands[i], true);

                if (hand.HandId == handsId[i])
                {
                    succeded++;
                }
            }

            Assert.AreEqual(total, succeded);

            Debug.WriteLine("Processed hands: {0}/{1}", succeded, total);
        }
Exemplo n.º 3
0
        public void IsTournamentTest(string handHistoryFile, bool mustBeTournamet = true)
        {
            var parser = new Poker888FastParserImpl();

            string rawHands = File.ReadAllText(handHistoryFile);
            var    hands    = parser.SplitUpMultipleHands(rawHands).ToArray();

            List <bool> allIsTournaments = new List <bool>();

            for (int i = 0; i < hands.Count(); i++)
            {
                HandHistory hand = parser.ParseFullHandHistory(hands[i], true);

                if (hand.GameDescription.IsTournament)
                {
                    allIsTournaments.Add(true);
                }
                else
                {
                    allIsTournaments.Add(false);
                }
            }

            Assert.True(mustBeTournamet ? !allIsTournaments.Contains(false) : !allIsTournaments.Contains(true));
        }
Exemplo n.º 4
0
        private HandHistory ParseFirstGame(string handHistoryFile)
        {
            var parser = new Poker888FastParserImpl();

            string rawHand = File.ReadAllText(handHistoryFile);

            return(parser.ParseFullHandHistory(parser.SplitUpMultipleHands(rawHand).FirstOrDefault()));
        }
Exemplo n.º 5
0
        public void HeroWinIsParsedTest(string handHistoryFile, decimal win)
        {
            var parser = new Poker888FastParserImpl();

            string      rawHand = File.ReadAllText(handHistoryFile);
            HandHistory hand    = parser.ParseFullHandHistory(rawHand, true);

            Assert.AreEqual(win, hand.Hero.Win);
        }
Exemplo n.º 6
0
        private HandHistory ParseHandHistory(string handHistoryFile)
        {
            var parser = new Poker888FastParserImpl();

            var handHistoryText = File.ReadAllText(handHistoryFile);

            var hands = parser.SplitUpMultipleHands(handHistoryText).ToArray();

            var hand = hands.Single();

            var handHistory = parser.ParseFullHandHistory(hand, true);

            return(handHistory);
        }
Exemplo n.º 7
0
        public void ParsingDoesNotThrowExceptions(string culture)
        {
            var cultureInfo = new CultureInfo(culture);

            Thread.CurrentThread.CurrentCulture = cultureInfo;

            var testDataDirectoryInfo = new DirectoryInfo(TestDataFolder);

            var handHistoryFiles = testDataDirectoryInfo.GetFiles("*.txt", SearchOption.AllDirectories);

            var parser = new Poker888FastParserImpl();

            var succeded = 0;
            var total    = 0;

            foreach (var handHistoryFile in handHistoryFiles)
            {
                var handHistory = File.ReadAllText(handHistoryFile.FullName);

                var hands = parser.SplitUpMultipleHands(handHistory).ToArray();

                total += hands.Length;

                var hash = new HashSet <string>();

                foreach (var hand in hands)
                {
                    try
                    {
                        parser.ParseFullHandHistory(hand, true);
                        succeded++;
                    }
                    catch (Exception e)
                    {
                        if (!hash.Contains(handHistoryFile.FullName))
                        {
                            Debug.WriteLine(handHistoryFile.FullName);
                            Debug.WriteLine(hand);
                        }

                        Assert.Fail(e.ToString());
                    }
                }
            }

            Assert.AreEqual(total, succeded);

            Debug.WriteLine("Processed hands: {0}/{1}", succeded, total);
        }
Exemplo n.º 8
0
        public void DealerButtonPositionIsParsedTest(string handHistoryFile, int[] dealerButtonPosition)
        {
            var parser = new Poker888FastParserImpl();

            string rawHands = File.ReadAllText(handHistoryFile);
            var    hands    = parser.SplitUpMultipleHands(rawHands).ToArray();

            var succeded = 0;
            var total    = hands.Count();

            for (int i = 0; i < total; i++)
            {
                HandHistory hand = parser.ParseFullHandHistory(hands[i], true);

                if (hand.DealerButtonPosition == dealerButtonPosition[i])
                {
                    succeded++;
                }
            }

            Assert.AreEqual(total, succeded);

            Debug.WriteLine("Processed hands: {0}/{1}", succeded, total);
        }
Exemplo n.º 9
0
        public void HeroStartingStackIsParsedTest(string handHistoryFile, double[] startingStack)
        {
            var parser = new Poker888FastParserImpl();

            string rawHands = File.ReadAllText(handHistoryFile);
            var    hands    = parser.SplitUpMultipleHands(rawHands).ToArray();

            var succeded = 0;
            var total    = hands.Count();

            for (int i = 0; i < total; i++)
            {
                HandHistory hand = parser.ParseFullHandHistory(hands[i], true);

                if (hand.Hero.StartingStack == (decimal)startingStack[i])
                {
                    succeded++;
                }
            }

            Assert.AreEqual(total, succeded);

            Debug.WriteLine("Processed hands: {0}/{1}", succeded, total);
        }
Exemplo n.º 10
0
        public void TournamentSummaryIsParsedTest(string handHistoryFile, bool isSummary)
        {
            var parser = new Poker888FastParserImpl();

            string rawHands = File.ReadAllText(handHistoryFile);
            var    hands    = parser.SplitUpMultipleHands(rawHands).ToArray();

            var succeded = 0;
            var total    = hands.Count();

            for (int i = 0; i < total; i++)
            {
                HandHistory hand = parser.ParseFullHandHistory(hands[i], true);

                if (hand.GameDescription.Tournament.IsSummary == isSummary)
                {
                    succeded++;
                }
            }

            Assert.AreEqual(total, succeded);

            Debug.WriteLine("Processed hands: {0}/{1}", succeded, total);
        }
Exemplo n.º 11
0
        static void Main(string[] args)
        {// takes a full path to a directory that contains raw *.txt poker history files from 888 poker.
            IHandHistoryParserFactory handHistoryParserFactory = new HandHistoryParserFactoryImpl();

            // Get the correct parser from the factory.
            var handHistoryParser = new Poker888FastParserImpl();
            HandHistoryParserFastImpl fastParser = handHistoryParser as HandHistoryParserFastImpl;

            try
            {
                // The true causes hand-parse errors to get thrown. If this is false, hand-errors will
                // be silent and null will be returned.
                string[] files     = Directory.GetFiles(args[0], "*.txt", SearchOption.AllDirectories);
                int      fileCount = files.Length;
                foreach (string file in files)
                {
                    Console.WriteLine("number of files left {0} out of {1}", fileCount--, files.Length);
                    string fileText   = new StreamReader(file).ReadToEnd();
                    var    hands      = fastParser.SplitUpMultipleHandsToLines(fileText);
                    var    outputFile = new StreamWriter(file + ".csv");
                    outputFile.WriteLine("DateOfHandUtc,HandId,DealerButtonPosition,TableName,GameDescription,NumPlayersActive,NumPlayersSeated,Rake,ComumnityCards,TotalPot,PlayerName,HoleCards,StartingStack,SeatNumber,ActionNumber,Amount,HandActionType,Outs,CardOuts,CurrentHandRank,currentPostSize,Street,IsAggressiveAction,IsAllIn,IsAllInAction,IsBlinds,IsGameAction,IsPreFlopRaise,IsRaise,IsWinningsAction");
                    foreach (var hand in hands)
                    {
                        var parsedHand = fastParser.ParseFullHandHistory(hand, true);

                        // probably not the best way to do this. This should be added to the ParseHandActions function or something.
                        decimal currentPotSize = 0;
                        int     actionNumber   = 0;
                        foreach (var action in parsedHand.HandActions)
                        {
                            // I tried to do this (this = 'actionNumber++') rtdfgcvdrt properly via the ParseHandActions function in Poker888FastParserImpl.cs file to be 1-1 with the raw handlines, however
                            // I was getting some un-expected behavior when the action was all in and the winning action the handline index would be 0 so you would end up with
                            // actions sequences like 1,2,3,4,5,6,0,8,9,10.
                            actionNumber++;
                            if (action.HandActionType == HandHistories.Objects.Actions.HandActionType.ANTE ||
                                action.HandActionType == HandHistories.Objects.Actions.HandActionType.BET ||
                                action.HandActionType == HandHistories.Objects.Actions.HandActionType.SMALL_BLIND ||
                                action.HandActionType == HandHistories.Objects.Actions.HandActionType.RAISE ||
                                action.HandActionType == HandHistories.Objects.Actions.HandActionType.BIG_BLIND ||
                                action.HandActionType == HandHistories.Objects.Actions.HandActionType.CALL ||
                                action.HandActionType == HandHistories.Objects.Actions.HandActionType.ALL_IN)
                            {
                                currentPotSize += action.Amount;
                            }

                            // Don't judge me.... this code is just chaos...but it's works.
                            string handRank;
                            HandEvaluator.HandEvaluator he = new HandEvaluator.HandEvaluator();
                            string handstring = String.Format("{0}{1}", parsedHand.Players.First(p => p.PlayerName.Equals(action.PlayerName)).HoleCards, parsedHand.ComumnityCards);
                            string flopstring;
                            string turnstring;
                            string riverstring;
                            string currenthandstring;
                            Hand   h = new Hand();
                            // holecards
                            Hand hc = new Hand();
                            Dictionary <Hand, int>          handOuts = new Dictionary <Hand, int>();
                            Dictionary <Hand, List <Card> > cardouts;
                            int    outs  = 0;
                            double hr    = 0.0;
                            string couts = "";
                            if (handstring.Length >= 14)
                            {
                                currenthandstring = "";
                                flopstring        = handstring.Substring(4, 6);
                                turnstring        = handstring.Substring(10, 2);
                                riverstring       = handstring.Substring(12, 2);
                                // build the hand play-by-play so we can get current hand ranking and also build in hand outs.
                                switch (action.Street)
                                {
                                case HandHistories.Objects.Cards.Street.Flop:
                                    currenthandstring = handstring.Substring(0, 4) + flopstring;
                                    h        = new Hand(currenthandstring, 7, 5);
                                    hc       = new Hand(handstring.Substring(0, 4), 7, 5);
                                    hr       = he.RankHand(h, out handRank);
                                    handOuts = he.ComputeOuts(h, hc.HAND, new Hand(flopstring, 7, 5).HAND, out cardouts);
                                    outs     = handOuts[h];
                                    couts    = new Hand(cardouts[h], 52, 5).HandToString();

                                    break;

                                case HandHistories.Objects.Cards.Street.Turn:
                                    currenthandstring = handstring.Substring(0, 4) + flopstring + turnstring;
                                    h  = new Hand(currenthandstring, 7, 5);
                                    hc = new Hand(handstring.Substring(0, 4), 7, 5);

                                    hr       = he.RankHand(h, out handRank);
                                    handOuts = he.ComputeOuts(h, hc.HAND, new Hand(flopstring + turnstring, 7, 5).HAND, out cardouts);
                                    outs     = handOuts[h];
                                    couts    = new Hand(cardouts[h], 52, 5).HandToString();

                                    break;

                                case HandHistories.Objects.Cards.Street.River:
                                    currenthandstring = handstring.Substring(0, 4) + flopstring + turnstring + riverstring;
                                    h    = new Hand(currenthandstring, 7, currenthandstring.Length / 2);
                                    hc   = new Hand(handstring.Substring(0, 4), 7, 5);
                                    hr   = he.RankHand(h, out handRank);
                                    outs = 0;     // No need to compute outs on the river.  No more cards to come.

                                    break;

                                default:
                                    hr   = 0.0;
                                    outs = 0;

                                    break;
                                }
                            }
                            else
                            {
                                hr   = 0.0;
                                outs = 0;
                            }
                            outputFile.WriteLine("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14},{15},{16},{17},{18},{19},{20},{21},{22},{23},{24},{25},{26},{27},{28},{29}",
                                                 parsedHand.DateOfHandUtc
                                                 , parsedHand.HandId
                                                 , parsedHand.DealerButtonPosition
                                                 , parsedHand.TableName
                                                 , parsedHand.GameDescription
                                                 , parsedHand.NumPlayersActive
                                                 , parsedHand.NumPlayersSeated
                                                 , parsedHand.Rake
                                                 , parsedHand.ComumnityCards
                                                 , parsedHand.TotalPot
                                                 , action.PlayerName
                                                 , parsedHand.Players.First(p => p.PlayerName.Equals(action.PlayerName)).HoleCards
                                                 , parsedHand.Players.First(p => p.PlayerName.Equals(action.PlayerName)).StartingStack
                                                 , parsedHand.Players.First(p => p.PlayerName.Equals(action.PlayerName)).SeatNumber
                                                 , actionNumber
                                                 , action.Amount
                                                 , action.HandActionType
                                                 , outs.ToString()
                                                 , couts
                                                 , hr.ToString()
                                                 , currentPotSize
                                                 , action.Street
                                                 , action.IsAggressiveAction
                                                 , action.IsAllIn
                                                 , action.IsAllInAction
                                                 , action.IsBlinds
                                                 , action.IsGameAction
                                                 , action.IsPreFlopRaise
                                                 , action.IsRaise
                                                 , action.IsWinningsAction
                                                 );
                        }
                    }
                    outputFile.Close();
                }
            }
            catch (Exception ex)                                     // Catch hand-parsing exceptions
            {
                Console.WriteLine("Parsing Error: {0}", ex.Message); // Example logging.
                Console.ReadLine();
            }
        }