void Evaluate7Cards(ref CardSet mask)
        {
            _count++;
            UInt32 handVal = CardSetEvaluator.Evaluate(ref mask);

            _checksum += handVal;
        }
        void Evaluate7CardsParam(ref CardSet mask, CardSetEvaluator_Test param)
        {
            param._count++;
            UInt32 handVal = CardSetEvaluator.Evaluate(ref mask);

            _checksum += handVal;
        }
Пример #3
0
        void OnPocket(ref CardSet hand, CalculateAverageHsParam param)
        {
            uint handValue = CardSetEvaluator.Evaluate(ref hand);
            int  ordinal   = HandValueToOrdinal.GetOrdinal7(handValue);

            param.Sum += ordinal;
            param.Count++;
        }
Пример #4
0
        public void Test_Showdown()
        {
            int seed = (int)DateTime.Now.Ticks;

            Console.WriteLine("RNG seed {0}", seed);
            SequenceRng dealer = new SequenceRng(seed, StdDeck.Descriptor.FullDeckIndexes);

            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];
            }

            int repCount = 1000000;

            for (int r = 0; r < repCount; ++r)
            {
                dealer.Shuffle(2 + 2 + 5);
                hands[0][0] = dealer.Sequence[0];
                hands[0][1] = dealer.Sequence[1];
                hands[1][0] = dealer.Sequence[2];
                hands[1][1] = dealer.Sequence[3];
                for (int i = 0; i < 5; ++i)
                {
                    hands[0][2 + i] = hands[1][2 + i] = dealer.Sequence[4 + i];
                }
                gr.Showdown(_gd, hands, ranks);
                int actResult = -1;
                if (ranks[0] > ranks[1])
                {
                    actResult = 1;
                }
                else if (ranks[0] == ranks[1])
                {
                    actResult = 0;
                }
                CardSet h0        = _gd.DeckDescr.GetCardSet(hands[0]);
                CardSet h1        = _gd.DeckDescr.GetCardSet(hands[1]);
                UInt32  v0        = CardSetEvaluator.Evaluate(ref h0);
                UInt32  v1        = CardSetEvaluator.Evaluate(ref h1);
                int     expResult = -1;
                if (v0 > v1)
                {
                    expResult = 1;
                }
                else if (v0 == v1)
                {
                    expResult = 0;
                }
                Assert.AreEqual(expResult, actResult);
            }
        }
        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 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);
        }
            void Evaluate(ref CardSet board)
            {
                CardSet h1 = new CardSet(board, _mPocket);
                CardSet h2 = new CardSet(board, _mOther);
                UInt32  v1 = CardSetEvaluator.Evaluate(ref h1);
                UInt32  v2 = CardSetEvaluator.Evaluate(ref h2);

                if (v1 > v2)
                {
                    _evCount += 2;
                }
                if (v1 == v2)
                {
                    _evCount += 1;
                }
            }
Пример #10
0
        public void Benchmark_All7Cards_InlineEnumeration()
        {
            CardSet[] cardSets = StdDeck.Descriptor.CardSets;
            // Using a local variable instead of static speeds up the test!.
            int      count = 0;
            UInt32   checksum = 0;
            DateTime startTime = DateTime.Now;
            CardSet  cs = new CardSet();
            UInt64   m1, m2, m3, m4, m5, m6;

            for (int c1 = 52 - 1; c1 >= 6; --c1)
            {
                m1 = cardSets[c1].bits;
                for (int c2 = c1 - 1; c2 >= 5; --c2)
                {
                    m2 = m1 | cardSets[c2].bits;
                    for (int c3 = c2 - 1; c3 >= 4; --c3)
                    {
                        m3 = m2 | cardSets[c3].bits;
                        for (int c4 = c3 - 1; c4 >= 3; --c4)
                        {
                            m4 = m3 | cardSets[c4].bits;
                            for (int c5 = c4 - 1; c5 >= 2; --c5)
                            {
                                m5 = m4 | cardSets[c5].bits;
                                for (int c6 = c5 - 1; c6 >= 1; --c6)
                                {
                                    m6 = m5 | cardSets[c6].bits;
                                    for (int c7 = c6 - 1; c7 >= 0; --c7)
                                    {
                                        count++;
                                        cs.bits   = m6 | cardSets[c7].bits;
                                        checksum += CardSetEvaluator.Evaluate(ref cs);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            double runTime = (DateTime.Now - startTime).TotalSeconds;

            PrintResult(count, runTime, checksum);
        }
        static int Showdown(CardSet ourPocket, CardSet oppPocket, CardSet board, int handSize)
        {
            Debug.Assert(!ourPocket.IsIntersectingWith(oppPocket));
            Debug.Assert(!ourPocket.IsIntersectingWith(board));
            Debug.Assert(!ourPocket.IsIntersectingWith(board));

            CardSet ourHand = new CardSet(ourPocket, board);
            CardSet oppHand = new CardSet(oppPocket, board);

            UInt32 ourRank = CardSetEvaluator.Evaluate(ref ourHand);
            UInt32 oppRank = CardSetEvaluator.Evaluate(ref oppHand);

            if (ourRank > oppRank)
            {
                return(1);
            }
            else if (ourRank < oppRank)
            {
                return(-1);
            }
            return(0);
        }
Пример #12
0
        void Evaluate2Players(ref CardSet handMask)
        {
            _count++;
            CardSet hand1 = handMask | _player1;
            CardSet hand2 = handMask | _player2;

            UInt32 val1 = CardSetEvaluator.Evaluate(ref hand1);
            UInt32 val2 = CardSetEvaluator.Evaluate(ref hand2);

            if (val1 > val2)
            {
                _win++;
            }
            else if (val1 < val2)
            {
                _lose++;
            }
            else
            {
                _tie++;
            }
        }
Пример #13
0
        public void Test_ValueToString()
        {
            CardSet m;
            UInt32  value;
            string  text;

            m     = StdDeck.Descriptor.GetCardSet("2s 3h 6c Ah 9d Kd Js");
            value = CardSetEvaluator.Evaluate(ref m);
            text  = HandValue.ValueToString(m, value);
            Assert.AreEqual("High Card: Ah Kd Js 9d 6c", text);

            m     = StdDeck.Descriptor.GetCardSet("7s 6h 7c Ah 9d Qd Jd");
            value = CardSetEvaluator.Evaluate(ref m);
            text  = HandValue.ValueToString(m, value);
            Assert.AreEqual("Pair: 7c 7s Ah Qd Jd", text);

            m     = StdDeck.Descriptor.GetCardSet("7s 6h 7c Ah 9d Qd Ad");
            value = CardSetEvaluator.Evaluate(ref m);
            text  = HandValue.ValueToString(m, value);
            Assert.AreEqual("2 Pair: Ad Ah 7c 7s Qd", text);

            m     = StdDeck.Descriptor.GetCardSet("2s 6h 7c Ah 2d Qd 2c");
            value = CardSetEvaluator.Evaluate(ref m);
            text  = HandValue.ValueToString(m, value);
            Assert.AreEqual("3 of a Kind: 2c 2d 2s Ah Qd", text);

            m     = StdDeck.Descriptor.GetCardSet("2s 6h 3c 5h 4d 8d 2c");
            value = CardSetEvaluator.Evaluate(ref m);
            text  = HandValue.ValueToString(m, value);
            Assert.AreEqual("Straight: 6h 5h 4d 3c 2c", text);

            m     = StdDeck.Descriptor.GetCardSet("2s Ah 3c 5h 4d 8d 2c");
            value = CardSetEvaluator.Evaluate(ref m);
            text  = HandValue.ValueToString(m, value);
            Assert.AreEqual("Straight: 5h 4d 3c 2c Ah", text);

            m     = StdDeck.Descriptor.GetCardSet("2s 6s Qs 4h 8s 8d 7s");
            value = CardSetEvaluator.Evaluate(ref m);
            text  = HandValue.ValueToString(m, value);
            Assert.AreEqual("Flush: Qs 8s 7s 6s 2s", text);

            m     = StdDeck.Descriptor.GetCardSet("2s 6h 7c Ah 2d Qd 2c");
            value = CardSetEvaluator.Evaluate(ref m);
            text  = HandValue.ValueToString(m, value);
            Assert.AreEqual("3 of a Kind: 2c 2d 2s Ah Qd", text);

            m     = StdDeck.Descriptor.GetCardSet("2s 6h 7c 6c 2d Qd 2c");
            value = CardSetEvaluator.Evaluate(ref m);
            text  = HandValue.ValueToString(m, value);
            Assert.AreEqual("Full House: 2c 2d 2s 6c 6h", text);

            m     = StdDeck.Descriptor.GetCardSet("2s 6h 7c Ah 2d 2h 2c");
            value = CardSetEvaluator.Evaluate(ref m);
            text  = HandValue.ValueToString(m, value);
            Assert.AreEqual("4 of a Kind: 2c 2d 2h 2s Ah", text);

            m     = StdDeck.Descriptor.GetCardSet("As 5s 9s 7s 8s 6s Qc");
            value = CardSetEvaluator.Evaluate(ref m);
            text  = HandValue.ValueToString(m, value);
            Assert.AreEqual("Straight Flush: 9s 8s 7s 6s 5s", text);
        }
Пример #14
0
        private static void CountDistinctHandValues(ref CardSet mask)
        {
            UInt32 handVal = CardSetEvaluator.Evaluate(ref mask);

            CountHandValues(handVal);
        }
Пример #15
0
 static void OnDeal(ref CardSet hand, CalulateParam p)
 {
     p.Sum += HandValueToOrdinal.GetOrdinal7(CardSetEvaluator.Evaluate(ref hand));
 }