コード例 #1
0
        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);
        }
コード例 #2
0
        public void Benchmark_Showdown()
        {
            HoldemGameRules gr = new HoldemGameRules();

            int [][] hands = new int[2][];
            UInt32[] ranks = new UInt32[2];
            for (int p = 0; p < 2; ++p)
            {
                hands[p] = new int[7];
            }
            hands[0][0] = 0;
            hands[0][1] = 1;
            hands[1][0] = 2;
            hands[1][1] = 3;
            // Force loading LUT
            UInt32   checksum  = LutEvaluator7.Evaluate(0, 1, 2, 3, 4, 5, 6);
            DateTime startTime = DateTime.Now;
            int      count     = 0;

            for (int b0 = 4; b0 < 52 - 4; ++b0)
            {
                hands[0][2] = hands[1][2] = b0;
                for (int b1 = b0 + 1; b1 < 52 - 3; ++b1)
                {
                    hands[0][3] = hands[1][3] = b1;
                    for (int b2 = b1 + 1; b2 < 52 - 2; ++b2)
                    {
                        hands[0][4] = hands[1][4] = b2;
                        for (int b3 = b2 + 1; b3 < 52 - 1; ++b3)
                        {
                            hands[0][5] = hands[1][5] = b3;
                            for (int b4 = b3 + 1; b4 < 52 - 0; ++b4)
                            {
                                hands[0][6] = hands[1][6] = b4;
                                gr.Showdown(_gd, hands, ranks);
                                checksum += ranks[0] + ranks[1];
                                count++;
                            }
                        }
                    }
                }
            }
            double runTime = (DateTime.Now - startTime).TotalSeconds;

            Assert.AreEqual(EnumAlgos.CountCombin(52 - 4, 5), count);
            Console.WriteLine("Showdown for 2 players, {0:#,#} hands, {1:#,#} h/s, time: {2:0.000} s, checksum: {3}",
                              count, count / runTime, runTime, checksum);
        }
コード例 #3
0
        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);
            }
        }
コード例 #4
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);
        }
コード例 #5
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);
        }
コード例 #6
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);
        }
コード例 #7
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);
        }
コード例 #8
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);
        }