public void TestParserWith7Cards()
 {
     foreach (ulong mask in RefEvaluator.RandomHands(7, 20.0))
     {
         string hand     = RefEvaluator.MaskToString(mask);
         ulong  testmask = RefEvaluator.ParseHand(hand);
         Assert.AreEqual(RefEvaluator.BitCount(testmask), 7, "Parsed Results should be 7 cards");
         Assert.AreEqual(mask, testmask, "Make sure that MaskToString() and ParseHand() return consistant results");
     }
 }
        public void Test_Simple()
        {
            CardSet hand = new CardSet {
                bits = 0x7F
            };
            UInt32 handVal1 = CardSetEvaluator.Evaluate(ref hand);

            UInt32 handVal2 = RefEvaluator.Evaluate(hand.bits, 7);

            Assert.AreEqual(handVal1, handVal2);
        }
        public void Test_Simple()
        {
            string handS = "As Ks Kd Kc 2c 2d 5c";

            int[]   handA = StdDeck.Descriptor.GetIndexes(handS);
            CardSet handC = StdDeck.Descriptor.GetCardSet(handS);
            UInt32  val1  = LutEvaluator7.Evaluate(handA);
            UInt32  val2  = RefEvaluator.Evaluate(handC.bits, 7);

            Assert.AreEqual(val2, val1);
        }
        public void Benchmark_RandomCards()
        {
            int handCount = 1000000;

#if DEBUG
            int repCount = 1;
#else
            int repCount = 40;
#endif
            Console.WriteLine("Random hands: {0}, repetitions: {1}, total: {2}", handCount, repCount, handCount * repCount);

            RandomHandGenerator randomHands = new RandomHandGenerator();
            randomHands.Generate(handCount);
            randomHands.SetMask(5);
            Console.WriteLine("{0} random 5-hands generated", handCount);

            DateTime startTime;
            double   runTime;
            UInt32   checksum = 0;
            startTime = DateTime.Now;
            for (int r = 0; r < repCount; ++r)
            {
                for (int i = 0; i < handCount; ++i)
                {
                    UInt32 value = CardSetEvaluator.Evaluate(ref randomHands.hands[i].CardSet);
                    checksum += value;
#if DEBUG
                    VerifyHandValue(RefEvaluator.Evaluate(randomHands.hands[i].CardSet.bits,
                                                          randomHands.hands[i].CardSet.CountCards()), value);
#endif
                }
            }
            runTime = (DateTime.Now - startTime).TotalSeconds;
            PrintResult(handCount * repCount, runTime, checksum);

            randomHands.SetMask(7);

            Console.WriteLine("\n{0} random 7-hands generated", handCount);

            startTime = DateTime.Now;
            for (int r = 0; r < repCount; ++r)
            {
                for (int i = 0; i < handCount; ++i)
                {
                    UInt32 value = CardSetEvaluator.Evaluate(ref randomHands.hands[i].CardSet);
                    checksum += value;
#if DEBUG
                    VerifyHandValue(RefEvaluator.Evaluate(randomHands.hands[i].CardSet.bits, 7), value);
#endif
                }
            }
            runTime = (DateTime.Now - startTime).TotalSeconds;
            PrintResult(handCount * repCount, runTime, checksum);
        }
        private void Compare5Cards(ref CardSet mask)
        {
            _count++;
            UInt32 handVal1 = CardSetEvaluator.Evaluate(ref mask);
            UInt32 handVal2 = RefEvaluator.Evaluate(mask.bits, 5);

            if (handVal1 != handVal2)
            {
            }
            Assert.IsTrue(0 < handVal1);
            Assert.AreEqual(handVal1, handVal2);
            _handTypeCounter.Count(handVal1);
        }
        private void Compare7Cards(ref CardSet mask)
        {
            _count++;
            UInt32 handVal1 = CardSetEvaluator.Evaluate(ref mask);
            UInt32 handVal2 = RefEvaluator.Evaluate(mask.bits, 7);

            // Use direct check, it is faster than NUnit assert, and for 133M repetitions it makes a difference.
            if (handVal1 != handVal2)
            {
                Assert.Fail();
            }
            _handTypeCounter.Count(handVal1);
        }
        public void TestMoreInstanceOperators()
        {
            string board = "2d kh qh 3h qc";
            // Create a hand with AKs plus board
            RefEvaluator h1 = new RefEvaluator("ad kd", board);
            // Create a hand with 23 unsuited plus board
            RefEvaluator h2 = new RefEvaluator("2h 3d", board);

            Assert.IsTrue(h1 > h2);
            Assert.IsTrue(h1 >= h2);
            Assert.IsTrue(h2 <= h1);
            Assert.IsTrue(h2 < h1);
            Assert.IsTrue(h1 != h2);
        }
        public void Test_RandomCards_Array()
        {
            int handCount = 1000000;
            int rngSeed   = (int)DateTime.Now.Ticks;

            Console.WriteLine("Seed: {0}", rngSeed);
            RandomHandGenerator randomHands = new RandomHandGenerator(rngSeed);

            randomHands.Generate(handCount);
            randomHands.SetMask(7);
            for (int i = 0; i < handCount; ++i)
            {
                UInt32 value = LutEvaluator7.Evaluate(randomHands.hands[i].Cards);
                VerifyHandValue(RefEvaluator.Evaluate(randomHands.hands[i].CardSet.bits, 7), value);
            }
        }
 public void TestInstanceOperators()
 {
     foreach (ulong pocketmask in RefEvaluator.Hands(2))
     {
         string pocket = RefEvaluator.MaskToString(pocketmask);
         foreach (ulong boardmask in RefEvaluator.RandomHands(0UL, pocketmask, 5, 0.001))
         {
             string       board = RefEvaluator.MaskToString(boardmask);
             RefEvaluator hand1 = new RefEvaluator(pocket, board);
             RefEvaluator hand2 = new RefEvaluator();
             hand2.PocketMask = pocketmask;
             hand2.BoardMask  = boardmask;
             Assert.IsTrue(hand1 == hand2, "Equality test failed");
         }
     }
 }
示例#10
0
        public void Benchmark_All7Cards_Incremental()
        {
            CardSet[] cardSets  = StdDeck.Descriptor.CardSets;
            int       count     = 0;
            UInt32    checksum  = LutEvaluator7.Evaluate(0, 1, 2, 3, 4, 5, 6);
            DateTime  startTime = DateTime.Now;

            for (int c1 = 52 - 1; c1 >= 6; --c1)
            {
                UInt32 v1 = LutEvaluator7.pLut[c1];
                for (int c2 = c1 - 1; c2 >= 5; --c2)
                {
                    UInt32 v2 = LutEvaluator7.pLut[v1 + c2];
                    for (int c3 = c2 - 1; c3 >= 4; --c3)
                    {
                        UInt32 v3 = LutEvaluator7.pLut[v2 + c3];
                        for (int c4 = c3 - 1; c4 >= 3; --c4)
                        {
                            UInt32 v4 = LutEvaluator7.pLut[v3 + c4];
                            for (int c5 = c4 - 1; c5 >= 2; --c5)
                            {
                                UInt32 v5 = LutEvaluator7.pLut[v4 + c5] + (uint)c5 - 1;
                                for (int c6 = c5 - 1; c6 >= 1; --c6, --v5)
                                {
                                    UInt32 v6 = LutEvaluator7.pLut[v5] + (uint)c6 - 1;
                                    for (int c7 = c6 - 1; c7 >= 0; --c7, --v6)
                                    {
                                        count++;
                                        UInt32 value = LutEvaluator7.pLut[v6];
                                        checksum += value;
#if DEBUG
                                        int []  handA = new int[] { c1, c2, c3, c4, c5, c6, c7 };
                                        CardSet handC = StdDeck.Descriptor.GetCardSet(handA);
                                        VerifyHandValue(RefEvaluator.Evaluate(handC.bits, 7), value);
#endif
                                    }
                                }
                            }
                        }
                    }
                }
            }
            double runTime = (DateTime.Now - startTime).TotalSeconds;
            PrintResult(count, runTime, checksum);
        }
示例#11
0
        public void TestBasicIterators()
        {
            long count = 0;

            foreach (ulong mask in RefEvaluator.Hands(1))
            {
                count++;
            }
            Assert.AreEqual(count, 52, "Check one card hand count");

            count = 0;
            foreach (ulong mask in RefEvaluator.Hands(2))
            {
                count++;
            }
            Assert.AreEqual(count, 1326, "Check two card hand count");

            count = 0;
            foreach (ulong mask in RefEvaluator.Hands(3))
            {
                count++;
            }
            Assert.AreEqual(count, 22100, "Check three card hand count");

            count = 0;
            foreach (ulong mask in RefEvaluator.Hands(4))
            {
                count++;
            }
            Assert.AreEqual(count, 270725, "Check four card hand count");

            count = 0;
            foreach (ulong mask in RefEvaluator.Hands(5))
            {
                count++;
            }
            Assert.AreEqual(count, 2598960, "Check five card hand count");

            count = 0;
            foreach (ulong mask in RefEvaluator.Hands(6))
            {
                count++;
            }
            Assert.AreEqual(count, 20358520, "Check six card hand count");
        }
示例#12
0
        public void TestParserWith5Cards()
        {
            int count = 0;

            for (int i = 0; i < 52; i++)
            {
                Assert.AreEqual(RefEvaluator.ParseCard(RefEvaluator.CardTable[i]), i, "Make sure parser and text match");
            }

            foreach (ulong mask in RefEvaluator.Hands(5))
            {
                string hand     = RefEvaluator.MaskToString(mask);
                ulong  testmask = RefEvaluator.ParseHand(hand);
                Assert.AreEqual(RefEvaluator.BitCount(testmask), 5, "Parsed Results should be 5 cards");

                //System.Diagnostics.Debug.Assert(mask == testmask);

                Assert.AreEqual(mask, testmask, "Make sure that MaskToString() and ParseHand() return consistant results");
                count++;
            }
        }
示例#13
0
        private void EvaluateAndVerify(CardSet handCs, int[] handA)
        {
            UInt32 expectedVal = RefEvaluator.Evaluate(handCs.bits, 7);
            UInt32 actualVal   = LutEvaluator7.Evaluate(handA);

            // Use direct check, it is faster than NUnit assert, and for 133M repetitions it makes a difference.
            if (actualVal != expectedVal)
            {
                Assert.Fail();
            }

            actualVal = LutEvaluator7.Evaluate(handA[0], handA[1], handA[2], handA[3], handA[4], handA[5], handA[6]);

            // Use direct check, it is faster than NUnit assert, and for 133M repetitions it makes a difference.
            if (actualVal != expectedVal)
            {
                Assert.Fail();
            }

            _handTypeCounter.Count(actualVal);
        }
示例#14
0
        public void Benchmark_All7Cards_Indexes()
        {
            CardSet[] cardSets = StdDeck.Descriptor.CardSets;
            // Using a local variable instead of static speeds up the test!.
            int      count     = 0;
            UInt32   checksum  = LutEvaluator7.Evaluate(0, 1, 2, 3, 4, 5, 6);
            DateTime startTime = DateTime.Now;

            for (int c1 = 52 - 1; c1 >= 6; --c1)
            {
                for (int c2 = c1 - 1; c2 >= 5; --c2)
                {
                    for (int c3 = c2 - 1; c3 >= 4; --c3)
                    {
                        for (int c4 = c3 - 1; c4 >= 3; --c4)
                        {
                            for (int c5 = c4 - 1; c5 >= 2; --c5)
                            {
                                for (int c6 = c5 - 1; c6 >= 1; --c6)
                                {
                                    for (int c7 = c6 - 1; c7 >= 0; --c7)
                                    {
                                        count++;
                                        UInt32 value = LutEvaluator7.Evaluate(c1, c2, c3, c4, c5, c6, c7);
                                        checksum += value;
#if DEBUG
                                        int []  handA = new int[] { c1, c2, c3, c4, c5, c6, c7 };
                                        CardSet handC = StdDeck.Descriptor.GetCardSet(handA);
                                        VerifyHandValue(RefEvaluator.Evaluate(handC.bits, 7), value);
#endif
                                    }
                                }
                            }
                        }
                    }
                }
            }
            double runTime = (DateTime.Now - startTime).TotalSeconds;
            PrintResult(count, runTime, checksum);
        }
示例#15
0
        public void Benchmark_All7Cards_Array()
        {
            int count = 0;
            // Force loading and JIT.
            UInt32 checksum = LutEvaluator7.Evaluate(new int[] { 0, 1, 2, 3, 4, 5, 6 });

            int []   hand      = new int[7];
            DateTime startTime = DateTime.Now;

            for (hand[0] = 52 - 1; hand[0] >= 6; --hand[0])
            {
                for (hand[1] = hand[0] - 1; hand[1] >= 5; --hand[1])
                {
                    for (hand[2] = hand[1] - 1; hand[2] >= 4; --hand[2])
                    {
                        for (hand[3] = hand[2] - 1; hand[3] >= 3; --hand[3])
                        {
                            for (hand[4] = hand[3] - 1; hand[4] >= 2; --hand[4])
                            {
                                for (hand[5] = hand[4] - 1; hand[5] >= 1; --hand[5])
                                {
                                    for (hand[6] = hand[5] - 1; hand[6] >= 0; --hand[6])
                                    {
                                        count++;
                                        UInt32 value = LutEvaluator7.Evaluate(hand);
                                        checksum += value;
#if DEBUG
                                        CardSet handC = StdDeck.Descriptor.GetCardSet(hand);
                                        VerifyHandValue(RefEvaluator.Evaluate(handC.bits, 7), value);
#endif
                                    }
                                }
                            }
                        }
                    }
                }
            }
            double runTime = (DateTime.Now - startTime).TotalSeconds;
            PrintResult(count, runTime, checksum);
        }
示例#16
0
        public void Test7CardHands()
        {
            int[] handtypes = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
            int   count     = 0;

            // Iterate through all possible 7 card hands
            foreach (ulong mask in RefEvaluator.Hands(7))
            {
                handtypes[(int)RefEvaluator.EvaluateType(mask, 7)]++;
                count++;
            }

            Assert.AreEqual(58627800, handtypes[(int)RefEvaluator.HandTypes.Pair], "Pair Returned Incorrect Value");
            Assert.AreEqual(31433400, handtypes[(int)RefEvaluator.HandTypes.TwoPair], "TwoPair Returned Incorrect Value");
            Assert.AreEqual(6461620, handtypes[(int)RefEvaluator.HandTypes.Trips], "Trips Returned Incorrect Value");
            Assert.AreEqual(6180020, handtypes[(int)RefEvaluator.HandTypes.Straight], "Straight Returned Incorrect Value");
            Assert.AreEqual(4047644, handtypes[(int)RefEvaluator.HandTypes.Flush], "Flush Returned Incorrect Value");
            Assert.AreEqual(3473184, handtypes[(int)RefEvaluator.HandTypes.FullHouse], "FullHouse Returned Incorrect Value");
            Assert.AreEqual(224848, handtypes[(int)RefEvaluator.HandTypes.FourOfAKind], "FourOfAKind Returned Incorrect Value");
            Assert.AreEqual(41584, handtypes[(int)RefEvaluator.HandTypes.StraightFlush], "StraightFlush Returned Incorrect Value");
            Assert.AreEqual(133784560, count, "Count Returned Incorrect Value");
        }
示例#17
0
        public void TestSuitConsistancy()
        {
            ulong mask = RefEvaluator.ParseHand("Ac Tc 2c 3c 4c");
            uint  sc   = (uint)((mask >> (RefEvaluator.CLUB_OFFSET)) & 0x1fffUL);

            Assert.AreEqual(RefEvaluator.BitCount(sc), 5, "Club consistancy check");

            mask = RefEvaluator.ParseHand("Ad Td 2d 3d 4d");
            uint sd = (uint)((mask >> (RefEvaluator.DIAMOND_OFFSET)) & 0x1fffUL);

            Assert.AreEqual(RefEvaluator.BitCount(sd), 5, "Diamond consistancy check");

            mask = RefEvaluator.ParseHand("Ah Th 2h 3h 4h");
            uint sh = (uint)((mask >> (RefEvaluator.HEART_OFFSET)) & 0x1fffUL);

            Assert.AreEqual(RefEvaluator.BitCount(sh), 5, "Hearts consistancy check");

            mask = RefEvaluator.ParseHand("As Ts 2s 3s 4s");
            uint ss = (uint)((mask >> (RefEvaluator.SPADE_OFFSET)) & 0x1fffUL);

            Assert.AreEqual(RefEvaluator.BitCount(ss), 5, "Spade consistancy check");
        }
示例#18
0
        public void Benchmark_RandomCards_Indexes()
        {
            int handCount = 1000000;

#if DEBUG
            int repCount = 1;
#else
            int repCount = 20;
#endif
            Console.WriteLine("Random hands: {0}, repetitions: {1}, total: {2}", handCount, repCount, handCount * repCount);

            RandomHandGenerator randomHands = new RandomHandGenerator();
            randomHands.Generate(handCount);


            // Force loading and JIT.
            UInt32 checksum = LutEvaluator7.Evaluate(0, 1, 2, 3, 4, 5, 6);
            randomHands.SetMask(7);

            Console.WriteLine("\n{0} random 7-hands generated", handCount);

            DateTime startTime = DateTime.Now;
            for (int r = 0; r < repCount; ++r)
            {
                for (int i = 0; i < handCount; ++i)
                {
                    RandomHandGenerator.Hand h = randomHands.hands[i];
                    UInt32 value = LutEvaluator7.Evaluate(h.c1, h.c2, h.c3, h.c4, h.c5, h.c6, h.c7);
                    checksum += value;
#if DEBUG
                    VerifyHandValue(RefEvaluator.Evaluate(randomHands.hands[i].CardSet.bits, 7), value);
#endif
                }
            }

            double runTime = (DateTime.Now - startTime).TotalSeconds;
            PrintResult(handCount * repCount, runTime, checksum);
        }
示例#19
0
        public void Test5CardHands()
        {
            int[] handtypes = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
            int   count     = 0;

            // Iterate through all possible 5 card hands
            foreach (ulong mask in RefEvaluator.Hands(5))
            {
                handtypes[(int)RefEvaluator.EvaluateType(mask, 5)]++;
                count++;
            }

            // Validate results.
            Assert.AreEqual(1302540, handtypes[(int)RefEvaluator.HandTypes.HighCard], "HighCard Returned Incorrect Count");
            Assert.AreEqual(1098240, handtypes[(int)RefEvaluator.HandTypes.Pair], "Pair Returned Incorrect Count");
            Assert.AreEqual(123552, handtypes[(int)RefEvaluator.HandTypes.TwoPair], "TwoPair Returned Incorrect Count");
            Assert.AreEqual(54912, handtypes[(int)RefEvaluator.HandTypes.Trips], "Trips Returned Incorrect Count");
            Assert.AreEqual(10200, handtypes[(int)RefEvaluator.HandTypes.Straight], "Trips Returned Incorrect Count");
            Assert.AreEqual(5108, handtypes[(int)RefEvaluator.HandTypes.Flush], "Flush Returned Incorrect Count");
            Assert.AreEqual(3744, handtypes[(int)RefEvaluator.HandTypes.FullHouse], "FullHouse Returned Incorrect Count");
            Assert.AreEqual(624, handtypes[(int)RefEvaluator.HandTypes.FourOfAKind], "FourOfAKind Returned Incorrect Count");
            Assert.AreEqual(40, handtypes[(int)RefEvaluator.HandTypes.StraightFlush], "StraightFlush Returned Incorrect Count");
            Assert.AreEqual(2598960, count, "Count Returned Incorrect Value");
        }
示例#20
0
        public void TestRandomIterators()
        {
            long start, freq, curtime;
            int  count = 0;

            // Test Random Hand Trials Iteration
            foreach (ulong mask in RefEvaluator.RandomHands(7, 20000))
            {
                count++;
            }
            Assert.AreEqual(count, 20000, "Should match the requested number of hands");

            QueryPerformanceFrequency(out freq);
            QueryPerformanceCounter(out start);

            count = 0;
            foreach (ulong mask in RefEvaluator.RandomHands(7, 2.5))
            {
                count++;
            }
            QueryPerformanceCounter(out curtime);

            Assert.Greater(((curtime - start) / ((double)freq)), 2.5, "Make sure ran the correct amount of time");
        }