public void Benchmark_2Players_GenericEnumeration()
        {
            // 1 Player has AcKd, 2 has 2h2s
            _count   = 0;
            _player1 = StdDeck.Descriptor.GetCardSet("Ac Kd");
            _player2 = StdDeck.Descriptor.GetCardSet("2h 2s");
            CardSet dead = _player1 | _player2;

            int REPETITIONS = 50;

            _win = _lose = _tie = 0;
            DateTime startTime = DateTime.Now;

            for (int r = 0; r < REPETITIONS; ++r)
            {
                CardEnum.Combin(StdDeck.Descriptor, 5, CardSet.Empty, dead, Evaluate2Players);
            }
            double runTime = (DateTime.Now - startTime).TotalSeconds;

            PrintResult(_count * 2, runTime, 0);
            Assert.AreEqual(1712304 * REPETITIONS, _count);
            Assert.AreEqual(799119 * REPETITIONS, _win);
            Assert.AreEqual(903239 * REPETITIONS, _lose);
            Assert.AreEqual(9946 * REPETITIONS, _tie);
        }
 public void Test_EvaluateAll7CardsCombinations()
 {
     _handTypeCounter.Reset();
     CardEnum.Combin(StdDeck.Descriptor, 7, CardSet.Empty, CardSet.Empty, Compare7Cards);
     _handTypeCounter.Verify(7);
     _handTypeCounter.Print();
 }
        public void Benchmark_3Players_GenericEnumeration()
        {
            // 1st Player has KcKh, 2nd has 7s6s, 3rd has AcQc
            _count   = 0;
            _player1 = StdDeck.Descriptor.GetCardSet("Kc Kh");
            _player2 = StdDeck.Descriptor.GetCardSet("7s 6s");
            _player3 = StdDeck.Descriptor.GetCardSet("Ac Qc");
            CardSet dead = _player1 | _player2 | _player3;

            int REPETITIONS = 20;

            _win = _lose = _tie = 0;
            DateTime startTime = DateTime.Now;

            for (int r = 0; r < REPETITIONS; ++r)
            {
                CardEnum.Combin(StdDeck.Descriptor, 5, CardSet.Empty, dead, Evaluate3Players);
            }
            double runTime = (DateTime.Now - startTime).TotalSeconds;

            PrintResult(_count * 3, runTime, 0);
            Assert.AreEqual(1370754 * REPETITIONS, _count);
            Assert.AreEqual(683919 * REPETITIONS, _win);
            Assert.AreEqual(683386 * REPETITIONS, _lose);
            Assert.AreEqual(3449 * REPETITIONS, _tie);
        }
Пример #4
0
        public static float[] Calculate(int[] hand, int handLength, int sdRound)
        {
            VerifyParameters(handLength, sdRound);
            float[] hssd = new float[2];
            hssd[0] = HandStrength.CalculateFast(hand, handLength);

            if (handLength == 7)
            {
                // Nothing more to do on the river.
                return(hssd);
            }

            int sdHandLength = HeHelper.RoundToHandSize[sdRound];

            CardSet cs = StdDeck.Descriptor.GetCardSet(hand, 0, handLength);
            Params  p  = new Params {
                Hand = new int[sdHandLength]
            };

            for (int i = 0; i < handLength; ++i)
            {
                p.Hand[i] = hand[i];
            }

            p.Hs = hssd[0];

            CardEnum.Combin <Params>(StdDeck.Descriptor, sdHandLength - handLength, p.Hand, handLength, p.Hand, handLength, OnDeal, p);
            Debug.Assert(FloatingPoint.AreEqual(p.Hs, p.SumHs / p.Count, 0.00001));
            hssd[1] = (float)Math.Sqrt(p.SumDiff / p.Count);
            return(hssd);
        }
 void Calculate()
 {
     foreach (Pocket p in _pockets)
     {
         _mPocket = new CardSet(
             StdDeck.Descriptor.CardSets[(int)p._c1],
             StdDeck.Descriptor.CardSets[(int)p._c2]);
         List <double> evList = new List <double>(1225);
         for (int c1 = StdDeck.Descriptor.Size - 1; c1 >= 0; --c1)
         {
             CardSet m1 = StdDeck.Descriptor.CardSets[c1];
             if (m1.IsIntersectingWith(_mPocket))
             {
                 continue;
             }
             for (int c2 = c1 - 1; c2 >= 0; --c2)
             {
                 CardSet m2 = new CardSet(m1, StdDeck.Descriptor.CardSets[c2]);
                 if (m2.IsIntersectingWith(_mPocket))
                 {
                     continue;
                 }
                 _evCount = 0;
                 _mOther  = m2;
                 CardEnum.Combin(StdDeck.Descriptor, 5, CardSet.Empty, _mPocket | m2, Evaluate);
                 double ev = 0.5 * _evCount / _boardsCount;
                 p._evDict.Add(m2, ev);
             }
         }
     }
 }
Пример #6
0
        public void Test_Random()
        {
            int REPETITIONS = 100;

#if DEBUG
            REPETITIONS = 8;
#endif

            int seed = (int)DateTime.Now.Ticks;
            Console.WriteLine("Random seed {0}", seed);
            Random rand = new Random(seed);
            _cardRng = new SequenceRng(seed);
            _cardRng.SetSequence(StdDeck.Descriptor.FullDeckIndexes);
            for (int r = 0; r < REPETITIONS; ++r)
            {
                _enumCount = r % 7;
                int sharedCount = rand.Next(0, StdDeck.Descriptor.Size + 1 - _enumCount);
                int deadCount   = rand.Next(0, StdDeck.Descriptor.Size + 1 - sharedCount - _enumCount);

                _cardRng.Shuffle(sharedCount + deadCount);
                int rc = 0;

                _shared = new CardSet();
                for (int i = 0; i < sharedCount; ++i)
                {
                    _shared |= StdDeck.Descriptor.CardSets[_cardRng.Sequence[rc++]];
                }

                _dead = new CardSet();
                for (int i = 0; i < deadCount; ++i)
                {
                    _dead |= StdDeck.Descriptor.CardSets[_cardRng.Sequence[rc++]];
                }
                Debug.Assert(rc == sharedCount + deadCount);
                Debug.Assert(!_shared.IsIntersectingWith(_dead));

                //Console.WriteLine("B: {0:x16} D:{1:x16}", board, dead);
                _combinationsCount = 0;
                _lastCs            = 0;
                CardEnum.Combin(StdDeck.Descriptor, _enumCount, _shared, _dead, VerifyCombination);
                Assert.AreEqual(EnumAlgos.CountCombin(StdDeck.Descriptor.Size - sharedCount - deadCount, _enumCount), _combinationsCount);

                _combinationsCount1 = 0;
                _lastCs1            = 0;
                CardEnum.Combin(StdDeck.Descriptor, _enumCount, _shared, _dead, VerifyCombinationParam, _combinationsCount);
                Assert.AreEqual(EnumAlgos.CountCombin(StdDeck.Descriptor.Size - sharedCount - deadCount, _enumCount), _combinationsCount1);

                _combinationsCount1 = 0;
                _lastCs1            = 0;
                int[] cards = new int[_enumCount + sharedCount].Fill(-1);
                StdDeck.Descriptor.GetIndexesAscending(_shared).ToArray().CopyTo(cards, 0);
                int[] deadIdx = StdDeck.Descriptor.GetIndexesAscending(_shared | _dead).ToArray();

                CardEnum.Combin(StdDeck.Descriptor, _enumCount, cards, sharedCount, deadIdx, deadIdx.Length, VerifyCombinationParam, _combinationsCount);
                Assert.AreEqual(EnumAlgos.CountCombin(StdDeck.Descriptor.Size - sharedCount - deadCount, _enumCount), _combinationsCount1);
            }
            Console.WriteLine("{0} repetitions done.", REPETITIONS);
        }
Пример #7
0
        public static float Calculate(CardSet board)
        {
            CalulateParam param     = new CalulateParam();
            int           boardSize = board.CountCards();
            int           toDeal    = 7 - boardSize;

            CardEnum.Combin(StdDeck.Descriptor, toDeal, board, CardSet.Empty, OnDeal, param);
            return((float)(param.Sum / EnumAlgos.CountCombin(52 - boardSize, toDeal)));
        }
Пример #8
0
 public void Test_CountCombinations_Idx()
 {
     int[] cards = new int[7];
     for (int i = 0; i <= 6; ++i)
     {
         _combinationsCount1 = 0;
         CardEnum.Combin(StdDeck.Descriptor, i, cards, 0, null, 0, CountCombinationsParam, 33);
         Assert.AreEqual(EnumAlgos.CountCombin(52, i), _combinationsCount1);
     }
 }
        public void Benchmark_All7Cards_GenericEnumerationParam()
        {
            _count = 0;
            DateTime startTime = DateTime.Now;

            CardEnum.Combin(StdDeck.Descriptor, 7, CardSet.Empty, CardSet.Empty, Evaluate7CardsParam, this);
            double runTime = (DateTime.Now - startTime).TotalSeconds;

            PrintResult(_count, runTime, _checksum);
        }
Пример #10
0
        double CalculateAverageHVO(int[] board)
        {
            CardSet boardCs = StdDeck.Descriptor.GetCardSet(board);
            CalculateAverageHsParam param = new CalculateAverageHsParam();
            int toDealCount = 7 - board.Length;

            CardEnum.Combin(StdDeck.Descriptor, toDealCount, boardCs, CardSet.Empty, OnPocket, param);
            Assert.AreEqual(EnumAlgos.CountCombin(52 - board.Length, toDealCount), param.Count);
            return(param.Sum / param.Count);
        }
Пример #11
0
        public void Test_ProofOfConcept()
        {
            ProofOfConceptParam param = new ProofOfConceptParam();

            CardEnum.Combin(StdDeck.Descriptor, 2, CardSet.Empty, CardSet.Empty, OnCombinProofOfConcept, param);
            double avHs = param.SumHs / param.Count;

            Assert.AreEqual(0, param.SumDev, 0.0001);
            Assert.AreEqual(0.5, avHs, 0.0001);
        }
Пример #12
0
        private List <HandDistrEntry> CalculateHsDistribution(string boardS)
        {
            CardSet         board = StdDeck.Descriptor.GetCardSet(boardS);
            HandDistrParams param = new HandDistrParams {
                Board = board, Distr = new List <HandDistrEntry>()
            };

            CardEnum.Combin(StdDeck.Descriptor, 2, CardSet.Empty, board, OnPocket, param);
            param.Distr.Sort();
            return(param.Distr);
        }
Пример #13
0
        public void Omaha()
        {
            Reset();
            Console.WriteLine("Calculate number of chance nodes from 1 player perspective for Omaha");

            CardEnum.Combin(StdDeck.Descriptor, 4, CardSet.Empty, CardSet.Empty, SuitIsomorphismPreflopOmaha);
            Console.WriteLine("Preflop Chance Nodes: colored: {0}, color-isomorphic: {1} {2:0.##}%",
                              _pocketCount, _normPreflopCount, 100.0 * _normPreflopCount / _pocketCount);
            Assert.AreEqual(EnumAlgos.CountCombin(52, 4), _pocketCount);
            // Value verified in Wiki, etc.
            Assert.AreEqual(16432, _normPreflopCount);
        }
Пример #14
0
        public void Test_CountCombinations_CardSet()
        {
            for (int i = 0; i <= 6; ++i)
            {
                _combinationsCount = 0;
                CardEnum.Combin(StdDeck.Descriptor, i, CardSet.Empty, CardSet.Empty, CountCombinations);
                Assert.AreEqual(EnumAlgos.CountCombin(52, i), _combinationsCount);

                _combinationsCount1 = 0;
                CardEnum.Combin(StdDeck.Descriptor, i, CardSet.Empty, CardSet.Empty, CountCombinationsParam, _combinationsCount);
                Assert.AreEqual(EnumAlgos.CountCombin(52, i), _combinationsCount1);
            }
        }
Пример #15
0
        public void Test_CombinArray_CardSet()
        {
            CardSet[] arr = CardEnum.Combin(StdDeck.Descriptor, 2, CardSet.Empty, CardSet.Empty);
            Assert.AreEqual(1326, arr.Length);
            CardSet prev = arr[0];

            Assert.AreEqual(2, prev.CountCards());
            for (int i = 1; i < arr.Length; ++i)
            {
                CardSet cur = arr[i];
                Assert.Less(prev.bits, cur.bits);
                Assert.AreEqual(2, cur.CountCards());
                prev = cur;
            }
        }
Пример #16
0
        public void Benchmark_CountCombinations_Idx()
        {
            int      count;
            DateTime startTime;
            double   runTime;

            int[] cards = new int[7];

            count     = 0;
            startTime = DateTime.Now;
            CardEnum.Combin(StdDeck.Descriptor, 7, cards, 0, null, 0, (int[] c, CardEnum_Test t) => { count++; }, this);
            runTime = (DateTime.Now - startTime).TotalSeconds;
            Console.WriteLine("Cardset (object parameter): {0:#,#} combinations, {1:0.0} s, {2:#,#} comb/s", count, runTime,
                              count / runTime);
        }
Пример #17
0
 public void Test_CountDistinctHandValues7()
 {
     for (int i = 0; i < (int)HandValue.Kind._Count + 1; ++i)
     {
         _uniqHandValues[i] = new HashSet <uint>();
     }
     CardEnum.Combin(StdDeck.Descriptor, 7, CardSet.Empty, CardSet.Empty, CountDistinctHandValues);
     Console.WriteLine("Number of unique 7-card combinations:");
     for (int i = 0; i < (int)HandValue.Kind._Count + 1; ++i)
     {
         Console.WriteLine("{0, 13}: {1,4}", ((HandValue.Kind)i).ToString(), _uniqHandValues[i].Count);
     }
     // Cross-verified with LutEvaluator7.
     Assert.AreEqual(4824, _uniqHandValues[(int)HandValue.Kind._Count].Count);
 }
Пример #18
0
        /// <summary>
        /// Precalculate and store tables. If the output already exists, will not overwrite.
        /// <remarks>Long-running. </remarks>
        /// </summary>
        /// <param name="round">Round (0, 1 or 2).</param>
        public static void Precalculate(int round)
        {
            DateTime startTime = DateTime.Now;

            string lutPath = GetLutPath(round);

            if (File.Exists(lutPath))
            {
                // Do not ovewriting an existing file to save time.
                Console.WriteLine("LUT file {0} already exist, exiting. Delete the file to recalculate.", lutPath);
                return;
            }

            int POCKETS_COUNT = (int)HePocketKind.__Count;
            //POCKETS_COUNT = 1; // Test

            PrecalculationContext context = new PrecalculationContext {
                Round = round
            };

            int[] listSize = new int[] { 169, 1361802, 15111642 };
            context.list = round < 2 ? (object)new List <Entry01>(listSize[round]) : (object)new List <Entry2>(listSize[round]);

            Console.WriteLine("Calculating for round {0}: ", round);

            int boardSize = HeHelper.RoundToHandSize[round] - 2;

            for (int p = 0; p < POCKETS_COUNT; ++p)
            {
                context.pocketKind = (HePocketKind)p;
                context.pocket     = HePocket.KindToCardSet((HePocketKind)p);
                context.pocketSei.Reset();
                context.pocketSei.Convert(context.pocket);
                Console.Write("{0} ", HePocket.KindToString((HePocketKind)p));
                CardEnum.Combin(StdDeck.Descriptor, boardSize, CardSet.Empty, context.pocket, OnPrecalculateBoard, context);
            }
            Console.WriteLine();
            Debug.Assert(EnumAlgos.CountCombin(50, boardSize) * POCKETS_COUNT == context.count);
            if (round < 2)
            {
                WriteTable((List <Entry01>)context.list, lutPath);
            }
            else
            {
                WriteTable((List <Entry2>)context.list, lutPath);
            }
            Console.WriteLine("LUT file {0} written, calculated in {1:0.0} s", lutPath, (DateTime.Now - startTime).TotalSeconds);
        }
Пример #19
0
 public void Test_CountDistinctHandValues5()
 {
     for (int i = 0; i < (int)HandValue.Kind._Count + 1; ++i)
     {
         _uniqHandValues[i] = new HashSet <uint>();
     }
     CardEnum.Combin(StdDeck.Descriptor, 5, CardSet.Empty, CardSet.Empty, CountDistinctHandValues);
     Console.WriteLine("Number of unique 5-card combinations:");
     for (int i = 0; i < (int)HandValue.Kind._Count + 1; ++i)
     {
         Console.WriteLine("{0, 13}: {1,4}",
                           ((HandValue.Kind)i).ToString(),
                           _uniqHandValues[i].Count);
         Assert.AreEqual(_numberOfUnique5Combinations[i], _uniqHandValues[i].Count);
     }
 }
Пример #20
0
        public void Test_Preflop()
        {
            HeHsDeviation dev = new HeHsDeviation();

            // Generate some unlucky preflops.
            dev.ProcessHand(StdDeck.Descriptor.GetIndexes("7c 2d"));
            dev.ProcessHand(StdDeck.Descriptor.GetIndexes("3c 2d"));
            Assert.True(dev.AccDeviation[0] < 0);
            Assert.AreEqual(0, dev.AccDeviation[1], 0.0001);
            Assert.AreEqual(0, dev.AccDeviation[2], 0.0001);
            Assert.AreEqual(0, dev.AccDeviation[3], 0.0001);
            Assert.True(dev.AvDeviation[0] < 0);
            Assert.AreEqual(0, dev.AvDeviation[1], 1e-7);
            Assert.AreEqual(0, dev.AvDeviation[2], 1e-7);
            Assert.AreEqual(0, dev.AvDeviation[3], 1e-7);
            Assert.AreEqual(new int[] { 2, 0, 0, 0 }, dev.HandCount);
            dev.Reset();

            // Generate some lucky preflops.
            dev.ProcessHand(StdDeck.Descriptor.GetIndexes("Ac Ad"));
            dev.ProcessHand(StdDeck.Descriptor.GetIndexes("Kc Ac"));
            Assert.True(dev.AccDeviation[0] > 0);
            Assert.AreEqual(0, dev.AccDeviation[1], 0.0001);
            Assert.AreEqual(0, dev.AccDeviation[2], 0.0001);
            Assert.AreEqual(0, dev.AccDeviation[3], 0.0001);
            Assert.True(dev.AvDeviation[0] > 0);
            Assert.AreEqual(0, dev.AvDeviation[1], 1e-7);
            Assert.AreEqual(0, dev.AvDeviation[2], 1e-7);
            Assert.AreEqual(0, dev.AvDeviation[3], 1e-7);
            Assert.AreEqual(new int[] { 2, 0, 0, 0 }, dev.HandCount);
            dev.Reset();

            // Make sure that the deviation for all preflop hands is 0.
            dev.Reset();
            int[] hand = new int[2];
            CardEnum.Combin(StdDeck.Descriptor, 2, hand, 0, null, 0, OnCombinProcessHand, dev);
            Assert.AreEqual(0, dev.AccDeviation[0], 0.0001);
            Assert.AreEqual(0, dev.AccDeviation[1], 0.0001);
            Assert.AreEqual(0, dev.AccDeviation[2], 0.0001);
            Assert.AreEqual(0, dev.AccDeviation[3], 0.0001);
            Assert.AreEqual(0, dev.AvDeviation[0], 1e-7);
            Assert.AreEqual(0, dev.AvDeviation[1], 1e-7);
            Assert.AreEqual(0, dev.AvDeviation[2], 1e-7);
            Assert.AreEqual(0, dev.AvDeviation[3], 1e-7);
            Assert.AreEqual(new int[] { 1326, 0, 0, 0 }, dev.HandCount);
        }
Пример #21
0
        public void Holdem()
        {
            Reset();
            Console.WriteLine("Calculate number of chance nodes from 1 player perspective for Holdem");

            CardEnum.Combin(StdDeck.Descriptor, 2, CardSet.Empty, CardSet.Empty, SuitIsomorphismPreflopHoldem);
            Console.WriteLine("Preflop Chance Nodes: colored: {0}, color-isomorphic: {1} {2:0.##}%",
                              _pocketCount, _normPreflopCount, 100.0 * _normPreflopCount / _pocketCount);
            int flopCount = (int)(EnumAlgos.CountCombin(52, 2) * EnumAlgos.CountCombin(50, 3));

            Console.WriteLine("Flop Chance Nodes: colored: {0}, color-isomorphic: {1} {2:0.##}%",
                              flopCount, _normFlopCount, 100.0 * _normFlopCount / flopCount);
            Assert.AreEqual(EnumAlgos.CountCombin(52, 2), _pocketCount);
            Assert.AreEqual(169, _normPreflopCount);
            // Value calculated by this test by many different implementations.
            Assert.AreEqual(1348620, _normFlopCount);
        }
Пример #22
0
        private void SuitIsomorphismPreflopHoldem(ref CardSet pocket)
        {
            _pocketCount++;
            _normPocket = _sn.Convert(pocket);
            if (_maxNormPreflopPocket.bits < _normPocket.bits)
            {
                _normPreflopCount++;
                _maxNormPreflopPocket = _normPocket;

                _sn2.Reset();
                _sn2.Convert(_normPocket);
                _maxNormFlopPocket.Clear();

                CardEnum.Combin(StdDeck.Descriptor, 3, CardSet.Empty, _normPocket, SuitIsomorphismFlopHoldem);
            }
            _sn.Reset();
        }
Пример #23
0
        static HePocket()
        {
            int[] rangePos = new int[(int)HePocketKind.__Count];
            for (int p = 0; p < (int)HePocketKind.__Count; ++p)
            {
                HePocketKind kind       = (HePocketKind)p;
                string       name       = kind.ToString();
                string       kindString = name.Substring(1);

                _kindToString[p] = kindString;
                _stringToKind.Add(kindString, kind);

                string  c1        = name.Substring(1, 1);
                string  c2        = name.Substring(2, 1);
                string  type      = name.Length == 4 ? name.Substring(3, 1) : "";
                CardSet cs        = new CardSet();
                int     rangeSize = 6;
                if (type == "s")
                {
                    // Suited
                    cs        = StdDeck.Descriptor.GetCardSet(c1 + "c " + c2 + "c");
                    rangeSize = 4;
                }
                else if (type == "o")
                {
                    // Offsuit
                    cs        = StdDeck.Descriptor.GetCardSet(c1 + "c " + c2 + "d");
                    rangeSize = 12;
                }
                else
                {
                    // Pair
                    cs        = StdDeck.Descriptor.GetCardSet(c1 + "c " + c2 + "d");
                    rangeSize = 6;
                }

                _kindToSuitNormalizedCardset[p] = cs;
                _kindToHand[p]          = StdDeck.Descriptor.GetIndexesAscending(cs).ToArray();
                _cardSetToKind[cs]      = kind;
                _kindToRange[(int)kind] = new CardSet[rangeSize];
            }
            CardEnum.Combin(StdDeck.Descriptor, 2, CardSet.Empty, CardSet.Empty, AddPocket, rangePos);
        }
Пример #24
0
        public void Benchmark_CardSetToKind()
        {
            CardSet[] pockets     = CardEnum.Combin(StdDeck.Descriptor, 2, CardSet.Empty, CardSet.Empty);
            int       repetitions = 100;
            DateTime  startTime   = DateTime.Now;

            int checksum = 0;

            for (int r = 0; r < repetitions; ++r)
            {
                for (int p = 0; p < pockets.Length; ++p)
                {
                    checksum += (int)HePocket.CardSetToKind(pockets[p]);
                }
            }

            double runTime = (DateTime.Now - startTime).TotalSeconds;

            Console.WriteLine("Cardset to kind: count: {0:#,#}, {1:#,#} r/s, checksum: {2}",
                              repetitions * pockets.Length, repetitions * pockets.Length / runTime, checksum);

            startTime = DateTime.Now;

            CardSet checksum1 = CardSet.Empty;

            NormSuit ns = new NormSuit();

            for (int r = 0; r < repetitions; ++r)
            {
                for (int p = 0; p < pockets.Length; ++p)
                {
                    checksum1 |= ns.Convert(pockets[p]);
                    ns.Reset();
                }
            }

            runTime = (DateTime.Now - startTime).TotalSeconds;

            Console.WriteLine("To compare performance:");

            Console.WriteLine("Normalize suit : count: {0:#,#}, {1:#,#} r/s, checksum: {2}",
                              repetitions * pockets.Length, repetitions * pockets.Length / runTime, checksum1.bits);
        }
Пример #25
0
        void DealOppCardsAndCalculateGV()
        {
            _oppGv.Fill(0);
            _hands[_heroPos].CopyTo(_hands[1 - _heroPos], 0);
#if true // full enum
            CardEnum.Combin(GameDef.DeckDescr, _handSizes[0], _hands[1 - _heroPos], 0, _hands[_heroPos],
                            _hands[_heroPos].Length, OnOppDeal, 0);
#else    // Random deal
            List <int> restDeck = new List <int>(GameDef.DeckDescr.FullDeckIndexes);
            foreach (int c in _hands[_heroPos])
            {
                restDeck.Remove(c);
            }
            // Deal one random card to the opponent.
            int oppCard = _rng.Next(restDeck.Count);
            _hands[1 - _heroPos][0] = oppCard;
            OnOppDeal(_hands[1 - _heroPos], 0);
#endif
        }
Пример #26
0
        public void Test_Flop()
        {
            HeHsDeviation dev = new HeHsDeviation();

            // Generate some unlucky flops.
            dev.ProcessHand(StdDeck.Descriptor.GetIndexes("7c 6c Ah 5s 5d"));
            dev.ProcessHand(StdDeck.Descriptor.GetIndexes("7c 6c Ad Kd Qd"));
            Assert.True(dev.AccDeviation[1] < 0);
            Assert.True(dev.AvDeviation[1] < 0);
            Assert.AreEqual(new int[] { 2, 2, 0, 0 }, dev.HandCount);
            dev.Reset();

            // Generate some lucky flops.
            dev.ProcessHand(StdDeck.Descriptor.GetIndexes("7c 6c Ac 5c 4c"));
            dev.ProcessHand(StdDeck.Descriptor.GetIndexes("7c 6c Ah Kc Qc"));
            Assert.True(dev.AccDeviation[1] > 0);
            Assert.True(dev.AvDeviation[1] > 0);
            Assert.AreEqual(new int[] { 2, 2, 0, 0 }, dev.HandCount);
            dev.Reset();

            // Deal all flops for a pocket and make sure the luck is zero.
            dev.Reset();
            int[] hand = new int[5];
            hand[0] = StdDeck.Descriptor.GetIndex("Ac");
            hand[1] = StdDeck.Descriptor.GetIndex("Ad");
            CardEnum.Combin(StdDeck.Descriptor, 3, hand, 2, hand, 2, OnCombinProcessHand, dev);
            Assert.AreEqual(0, dev.AccDeviation[1], 0.002);
            Assert.AreEqual(0, dev.AvDeviation[1], 1e-7);
            int hc = (int)EnumAlgos.CountCombin(50, 3);

            Assert.AreEqual(new int[] { hc, hc, 0, 0 }, dev.HandCount);

            // Deal all pockets and all flops, and make sure the luck is zero.
            // Check only average deviation, the accumulated one is too big because of low precision.
            dev.Reset();
            hand = new int[5];
            CardEnum.Combin(StdDeck.Descriptor, 2, hand, 0, null, 0, OnCombinFlop, dev);
            Assert.AreEqual(0, dev.AvDeviation[0], 0.0001);
            Assert.AreEqual(0, dev.AvDeviation[1], 0.0001);
            hc = (int)EnumAlgos.CountCombin(52, 2) * (int)EnumAlgos.CountCombin(50, 3);
            Assert.AreEqual(new int[] { hc, hc, 0, 0 }, dev.HandCount);
        }
Пример #27
0
        public void Benchmark_CountCombinations_CardSet()
        {
            int      count;
            DateTime startTime;
            double   runTime;

            count     = 0;
            startTime = DateTime.Now;
            CardEnum.Combin(StdDeck.Descriptor, 7, CardSet.Empty, CardSet.Empty, (ref CardSet cs) => { count++; });
            runTime = (DateTime.Now - startTime).TotalSeconds;
            Console.WriteLine("Cardset (no parameters): {0:#,#} combinations, {1:0.0} s, {2:#,#} comb/s", count, runTime,
                              count / runTime);

            count     = 0;
            startTime = DateTime.Now;
            CardEnum.Combin(StdDeck.Descriptor, 7, CardSet.Empty, CardSet.Empty, (ref CardSet cs, CardEnum_Test t) => { count++; }, this);
            runTime = (DateTime.Now - startTime).TotalSeconds;
            Console.WriteLine("Cardset (object parameter): {0:#,#} combinations, {1:0.0} s, {2:#,#} comb/s", count, runTime,
                              count / runTime);
        }
Пример #28
0
        public double[] CalculateHsSd(int[] hand, int handLength, int finalHandSize)
        {
            Debug.Assert(handLength >= 2 && handLength <= 7);

            CardSet cs = StdDeck.Descriptor.GetCardSet(hand, 0, handLength);
            Params  p  = new Params {
                Hand = new int [7], HandLength = handLength
            };

            for (int i = 0; i < handLength; ++i)
            {
                p.Hand[i] = hand[i];
            }

            p.ExpHs = HandStrength.CalculateFast(hand, handLength);
            CardEnum.Combin <Params>(StdDeck.Descriptor, finalHandSize - handLength, CardSet.Empty, cs, OnDeal, p);
            Assert.AreEqual(p.ExpHs, p.SumHs / p.Count, 0.00001);
            double[] hssd = new double[2];
            hssd[0] = p.ExpHs;
            hssd[1] = Math.Sqrt(p.SumDiff / p.Count);
            return(hssd);
        }
Пример #29
0
        static List <Entry> Precalculate(int boardSize)
        {
            int POCKETS_COUNT = (int)HePocketKind.__Count;
            //POCKETS_COUNT = 1; // Test

            PrecalculationContext context = new PrecalculationContext();

            int[] listSize = new int[] { 169, -1, -1, 1361802, 15111642 };
            context.list = new List <Entry>(listSize[boardSize]);

            for (int p = 0; p < POCKETS_COUNT; ++p)
            {
                context.pocketKind = (HePocketKind)p;
                context.pocket     = HePocket.KindToCardSet((HePocketKind)p);
                context.pocketSei.Reset();
                context.pocketSei.Convert(context.pocket);
                Console.WriteLine("Calculating for board size {0}, pocket {1}", boardSize, context.pocket);
                CardEnum.Combin(StdDeck.Descriptor, boardSize, CardSet.Empty, context.pocket, OnPrecalculateBoard, context);
            }

            Debug.Assert(EnumAlgos.CountCombin(50, boardSize) * POCKETS_COUNT == context.count);
            return(context.list);
        }
Пример #30
0
        public static void Precalculate(int round)
        {
            if (round < 1 || round > 3)
            {
                throw new ApplicationException(string.Format("Wrong round: {0}", round));
            }
            Console.WriteLine("Generating LUT for round {0}...", round);

            string lutPath = GetLutPath(round);

            if (File.Exists(lutPath))
            {
                Console.WriteLine("LUT {0} already exists, won't overwrite. Delete to create a new LUT.", lutPath);
                return;
            }
            PrecalulateParam p = new PrecalulateParam();
            int boardSize      = HeHelper.RoundToHandSize[round] - 2;

            CardEnum.Combin(StdDeck.Descriptor, boardSize, CardSet.Empty, CardSet.Empty, OnPrecalculateBoard, p);
            Entry[] lut = p.Entries.ToArray();
            WriteLut(lut, lutPath);
            Console.WriteLine("LUT {0} created.", lutPath);
        }