public void SamplePlays_Pure_ShouldMatchResults()
        {
            var counts = new CountsBy <X>();

            Parallel.ForEach(SampleHand.Load(@"PokerPlays.bin", true), hand =>
            {
                int?expectedWinner = null;
                int?actualWinner   = null;
                var madePlays      = new List <MadeHand>();

                // Run every player's hand
                for (int iPlayer = 0; iPlayer < hand.Plays.Count; iPlayer++)
                {
                    var play = hand.Plays[iPlayer];

                    var cards = play.Pocket.Concat(play.Board).Where(_ => _.IsValid).ToArray();

                    var made = MadeHand.MakeHand(cards);
                    madePlays.Add(made);

                    if (play.BestHandType != made.Type)
                    {
                        throw new Exception("Failed");
                    }
                    if (play.Won == 'y' && expectedWinner != null)
                    {
                        throw new Exception("Failed");
                    }
                    if (play.Won == 'y')
                    {
                        expectedWinner = iPlayer;
                    }

                    play.Result = made.Played;

                    if (actualWinner == null || madePlays[actualWinner.Value].Score < made.Score)
                    {
                        actualWinner = iPlayer;
                    }
                }

                var match = expectedWinner == actualWinner;
                counts.Increment(X.X, match);
            });

            counts.Report();
            Assert.IsTrue(counts.Success, $"Some failed");
        }
Exemplo n.º 2
0
        public static IEnumerable <SampleHand> Load(string filename, bool validWinsOnly)
        {
            const int sizeeach = 15;
            var       buffer   = new byte[sizeeach];

            using (var input = new BinaryReader(new FileStream(filename, FileMode.Open, FileAccess.Read)))
            {
                var nHands = input.ReadInt32();

                for (int iHand = 0; iHand < nHands; iHand++)
                {
                    var nPlayers = input.ReadInt32();
                    var hand     = new SampleHand();

                    for (int iPlayer = 0; iPlayer < nPlayers; iPlayer++)
                    {
                        input.Read(buffer, 0, sizeeach);
                        hand.Plays.Add(new SamplePlay(buffer));
                    }

                    // If we need to know exact winners and losers, don't keep anything that isn't an accurate record
                    if (validWinsOnly)
                    {
                        if (hand.Plays.Any(_ => !_.WinnerSpecified))
                        {
                            continue;
                        }
                        if (hand.Plays.Count(_ => _.Won == 'y') != 1)
                        {
                            continue;
                        }
                    }

                    yield return(hand);
                }
            }
        }