Пример #1
0
        public void Test_Calculate_Regr()
        {
            // Values are verified by an old version of this algo
            Assert.AreEqual(0.847630, HandStrength.Calculate(_deck.GetIndexes("Ac Ad Tc Qc Jc")), 0.0000005);
            Assert.AreEqual(0.999972, HandStrength.Calculate(_deck.GetIndexes("Ac Ad As Ah 2c")), 0.0000005);
            Assert.AreEqual(0.964859, HandStrength.Calculate(_deck.GetIndexes("Ad As Ac 7d 3h")), 0.0000005);
            Assert.AreEqual(0.994699, HandStrength.Calculate(_deck.GetIndexes("Ad As Ac 3c 3h")), 0.0000005);
            Assert.AreEqual(0.945037, HandStrength.Calculate(_deck.GetIndexes("Ad Ac 3d 3c 3h")), 0.0000005);
            Assert.AreEqual(0.964861, HandStrength.Calculate(_deck.GetIndexes("Ah As Ac 7d 3h")), 0.0000005);
            Assert.AreEqual(0.816541, HandStrength.Calculate(_deck.GetIndexes("Ac Ah Qs 7d 6d")), 0.0000005);
            Assert.AreEqual(0.914273, HandStrength.Calculate(_deck.GetIndexes("Ad Ah Ac 7d 3h 5h")), 0.0000005);
            Assert.AreEqual(0.998990, HandStrength.Calculate(_deck.GetIndexes("Ad Ah Ac 7d 3h 5h 5d")), 0.0000005);
            Assert.AreEqual(0.870202, HandStrength.Calculate(_deck.GetIndexes("As Ah 5c 7d 3h 9h 5d")), 0.0000005);

            // Some obvious results. They do a good coverage because the test both win and tie.
            Assert.AreEqual(1, HandStrength.Calculate(_deck.GetIndexes("Ac Kc Qc Jc Tc")));
            Assert.AreEqual(1, HandStrength.Calculate(_deck.GetIndexes("Ac Kc Qc Jc Tc 9c")));
            Assert.AreEqual(1, HandStrength.Calculate(_deck.GetIndexes("Ac Kc Qc Jc Tc 9c 8c")));
            Assert.AreEqual(1, HandStrength.Calculate(_deck.GetIndexes("5c 5d 5h 5s 2c 3d")));
            Assert.AreEqual(1, HandStrength.Calculate(_deck.GetIndexes("5c 5d 5h 5s 2c 3d 4h")));
            Assert.AreEqual(0.5, HandStrength.Calculate(_deck.GetIndexes("7c 2d Ac Kc Qc Jc Tc")));

            // Values are verified with Poker Academy. This runs very slow.
            Assert.AreEqual(0.8520, HandStrength.Calculate(_deck.GetIndexes("Ac Ad")), 0.0005);
            Assert.AreEqual(0.5085, HandStrength.Calculate(_deck.GetIndexes("9c 8c")), 0.0005);
        }
Пример #2
0
        /// <summary>
        /// Calculate LUTs for class HandStrength.
        /// It takes a long time (~ 10 hours) to run.
        /// </summary>
        static int Main(string[] args)
        {
            if (!Parser.ParseArgumentsWithUsage(args, _cmdLine))
            {
                Console.WriteLine("You may need to overwrite the root directory -d:ai.Root=<root-dir> ");
                return(1);
            }

            if (_cmdLine.DebuggerLaunch)
            {
                Debugger.Launch();
            }

            string dataDir = _cmdLine.OutputDir.Get(Props.Global);

            Console.WriteLine("Create LUTs in directory {0}", dataDir);
            Directory.CreateDirectory(dataDir);

            DateTime startTime = DateTime.Now;

            Console.WriteLine("Start time {0}, will take some hours to finish.", startTime);
            HandStrength.PrecalcuateTables(dataDir, -1);
            TimeSpan time = DateTime.Now - startTime;

            Console.WriteLine("Calculated in {0} s", time.TotalSeconds);

            return(0);
        }
Пример #3
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);
        }
Пример #4
0
        void OnCombinProofOfConcept(ref CardSet hand, ProofOfConceptParam param)
        {
            double hs = HandStrength.CalculateFast(StdDeck.Descriptor.GetIndexesAscending(hand).ToArray());

            param.SumHs  += hs;
            param.SumDev += hs - 0.5;
            param.Count++;
        }
Пример #5
0
        public void Benchmark_CaluclateFast()
        {
            HandStrength.LoadPrecalculationTables();

            DoBenchmarkFast(_deck.GetIndexes("7c 2d"), 5000000);
            DoBenchmarkFast(_deck.GetIndexes("Ac Ad Td Ah Js"), 5000000);
            DoBenchmarkFast(_deck.GetIndexes("Ac Ad Td Ah Js 4s"), 5000000);
            DoBenchmarkFast(_deck.GetIndexes("Ac Ad Td Ah Js 4s 9c"), 500000);
        }
Пример #6
0
 public void Test_Bounds()
 {
     for (int r = 0; r < 4; ++r)
     {
         float min, max;
         HandStrength.CalculateBounds(r, out min, out max);
         Console.WriteLine("Round {0}: hand strength min {1}, max {2}", r, min, max);
     }
 }
Пример #7
0
        static void OnDeal(int [] hand, Params p)
        {
            double hs = HandStrength.CalculateFast(p.Hand, p.Hand.Length);
            double d  = hs - p.Hs;

            p.SumDiff += d * d;
            p.SumHs   += hs;
            p.Count++;
        }
Пример #8
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="HandPlayer"></param>
 public HandEvaluator(Card[] HandPlayer)
 {
     _playerCards  = HandPlayer.OrderByDescending(c => (int)c.Value).ToArray();
     _handStrength = new HandStrength();
     InitNbOccurencesSuit();
     InitFlushList();
     InitNbOccurencesValue();
     InitStraightList();
     InitComboMethods();
 }
Пример #9
0
        public void Test_CalculateFast()
        {
            DeckDescriptor dd = StdDeck.Descriptor;

            int[]   hand;
            float[] hssd;

            // Compare with values calculated by another implementation.

            hand = dd.GetIndexes("Kh Kd");
            hssd = HsSd.CalculateFast(hand, HsSd.SdKind.SdPlus1);
            Assert.AreEqual(HandStrength.CalculateFast(hand), hssd[0], 0.00005);
            Assert.AreEqual(0.0620, hssd[1], 0.00005);

            hand = dd.GetIndexes("4s 3s");
            hssd = HsSd.CalculateFast(hand, HsSd.SdKind.SdPlus1);
            Assert.AreEqual(HandStrength.CalculateFast(hand), hssd[0], 0.00005);
            Assert.AreEqual(0.2029, hssd[1], 0.00005);

            hand = dd.GetIndexes("Ac Ah");
            hssd = HsSd.CalculateFast(hand, HsSd.SdKind.Sd3);
            Assert.AreEqual(HandStrength.CalculateFast(hand), hssd[0], 0.00005);
            Assert.AreEqual(0.1060, hssd[1], 0.00005);

            hand = dd.GetIndexes("7c 6c 8c 5c Ad");
            hssd = HsSd.CalculateFast(hand, HsSd.SdKind.SdPlus1);
            Assert.AreEqual(HandStrength.CalculateFast(hand), hssd[0], 0.00005);
            Assert.AreEqual(0.2377, hssd[1], 0.00005);

            hand = dd.GetIndexes("7c 6c 8c 5c Ad");
            hssd = HsSd.CalculateFast(hand, HsSd.SdKind.Sd3);
            Assert.AreEqual(HandStrength.CalculateFast(hand), hssd[0], 0.00005);
            Assert.AreEqual(0.3908, hssd[1], 0.00005);

            hand = dd.GetIndexes("7c 6c 8c 5c Ad Qs");
            hssd = HsSd.CalculateFast(hand, HsSd.SdKind.Sd3);
            Assert.AreEqual(HandStrength.CalculateFast(hand), hssd[0], 0.00005);
            Assert.AreEqual(0.4038, hssd[1], 0.00005);

            hand = dd.GetIndexes("9d 9h 2c Qs Ah");
            hssd = HsSd.CalculateFast(hand, HsSd.SdKind.SdPlus1);
            Assert.AreEqual(HandStrength.CalculateFast(hand), hssd[0], 0.00005);
            Assert.AreEqual(0.0805, hssd[1], 0.00005);

            hand = dd.GetIndexes("9d 9h 2c Qs Ah");
            hssd = HsSd.CalculateFast(hand, HsSd.SdKind.Sd3);
            Assert.AreEqual(HandStrength.CalculateFast(hand), hssd[0], 0.00005);
            Assert.AreEqual(0.1273, hssd[1], 0.00005);

            hand = dd.GetIndexes("9d 9h 2c Qs Ah Ks");
            hssd = HsSd.CalculateFast(hand, HsSd.SdKind.SdPlus1);
            Assert.AreEqual(HandStrength.CalculateFast(hand), hssd[0], 0.00005);
            Assert.AreEqual(0.1125, hssd[1], 0.00005);
        }
Пример #10
0
        void OnDeal(ref CardSet cs, Params p)
        {
            int[] dealt = StdDeck.Descriptor.GetIndexesAscending(cs).ToArray();
            dealt.CopyTo(p.Hand, p.HandLength);

            double hs = HandStrength.CalculateFast(p.Hand, p.HandLength + dealt.Length);
            double d  = hs - p.ExpHs;

            p.SumDiff += d * d;
            p.SumHs   += hs;
            p.Count++;
        }
Пример #11
0
        public void Test_Caluclate_Preview()
        {
            String[] d = new String[]
            {
                "Ac Kc Tc Qc Jc",
                "3c 3d Ac 7d 3h",
                "7d 3d Ac 3c 3h",
                "Ac 7d 3d 3c 3h",
                "Ad Ah Ac 7d 3h",
                "Ac Ah Qs 7d 6d",
                "5d 4d Qs 7d 6d",
                "8d 9d Qs 7d 6d",
                "6c 7c 6h 2d 3s",                 // Top pair
                "6c 7c 6h 2d Ts",                 // Mid pair
                "6c 7c 6h Ad Ts",                 // Small pair
                "6c 7c 6h 7d Kd",                 // 2 pair
                "6c 7c 5h 4d Kd",                 // Straigh draw
                "6c 7c Tc 2c Kd",                 // Flush draw
                "6c 7c 5c 4d Kc",                 // Straight & flush draw
                "Ad Ah Ac 7d 3h 5h",
                "Ad Ah Ac 7d 3h 5h 5d",
                "5c 5s Ac 7d 3h 5h 5d",
                "3c 2d Kc Td 7h",
                "3c 2d Kc Td 7h 5h Qs",
                "Js Jd 7h 8h 9h",
                "Js Jd 7h 8h 9h Jc",
                "Js Jd 7h 8h 9h 6h",
                "2c 3d 4h 5d 7c 8s 9c",                 // Very close to 0
                "2c 3d 4c 5c 7c 8d 9d",                 // Very close to 0
                "Ac Ad As 7s Qs 5s 5d",                 // Flush-like board
                "Ac Ad Ah 7c Qd 5s 5d",                 // Same ranks, no flush possible
            };
            for (int i = 0; i < d.GetLength(0); ++i)
            {
                double s = HandStrength.Calculate(_deck.GetIndexes(d[i]));
                Console.WriteLine("Hand {0} has strength {1:0.0000}", d[i], s);
            }

#if true // This runs slow
            d = new string[]
            {
                "Ac Ad",
                "9s 8s",
                "7c 2d",
            };
            for (int i = 0; i < d.GetLength(0); ++i)
            {
                double s = HandStrength.Calculate(_deck.GetIndexes(d[i]));
                Console.WriteLine("Hand {0} has strength {1:0.0000}", d[i], s);
            }
#endif
        }
Пример #12
0
        private float VerifyCalculateFast(int [] hand)
        {
            float s1 = HandStrength.Calculate(hand);
            float s2 = HandStrength.CalculateFast(hand);

            Assert.AreEqual(s1, s2);
            CardSet pocket = StdDeck.Descriptor.GetCardSet(hand, 0, 2);
            CardSet board  = StdDeck.Descriptor.GetCardSet(hand, 2, hand.Length - 2);
            float   s3     = HandStrength.CalculateFast(pocket, board);

            Assert.AreEqual(s1, s3);
            return(s1);
        }
Пример #13
0
        /// <summary>
        /// Returns exclusive upper limits for ranges.
        /// </summary>
        float[] CalculateRanges(int round, McHand[] hands, out float[] values)
        {
            if (hands == null || hands.Length == 0)
            {
                if (IsVerbose)
                {
                    Console.WriteLine("Empty parent bucket");
                }
                values = new float[0];
                return(new float[] { float.PositiveInfinity });
            }
            values = new float[hands.Length];
            float min = float.MaxValue;
            float max = float.MinValue;

            for (int i = 0; i < hands.Length; ++i)
            {
                float value = HandStrength.CalculateFast(hands[i].Cards, hands[i].Length);
                if (_printHandValues)
                {
                    Console.WriteLine(value);
                }
                values[i] = value;
                if (value < min)
                {
                    min = value;
                }
                if (value > max)
                {
                    max = value;
                }
            }
            float delta = max - min;

            int rangesCount = (int)Math.Round(delta / ClusterSizes[round], 0);

            rangesCount = Math.Max(MinBucketCounts[round], rangesCount);
            rangesCount = Math.Min(MaxBucketCounts[round], rangesCount);

            float[] ranges = new float[rangesCount];
            float   step   = delta / rangesCount;

            for (int i = 0; i < rangesCount - 1; ++i)
            {
                ranges[i] = (i + 1) * step + min;
            }
            ranges[rangesCount - 1] = float.PositiveInfinity;

            return(ranges);
        }
Пример #14
0
        private void DoBenchmarkFast(int [] hand, int repetitions)
        {
            DateTime startTime = DateTime.Now;
            double   sum       = 0;

            for (int r = 0; r < repetitions; ++r)
            {
                double s = HandStrength.CalculateFast(hand);
                sum += s; // To prevent optimizing away.
            }
            TimeSpan time      = DateTime.Now - startTime;
            string   boardName = new string[] { "", "", "PREFLOP", "", "", "FLOP", "TURN", "RIVER" }[hand.Length];

            Console.WriteLine("Hand strength on {0} calculated {1} times in {2} s, {3:0,0} val/s",
                              boardName, repetitions, time.TotalSeconds, repetitions / time.TotalSeconds);
        }
Пример #15
0
        public void Test_GetBucket_Preview()
        {
            string            minBucketsCounts = "8 1 1 1";
            string            maxBucketsCounts = "8 7 6 5";
            HsRangeAdaptiveCa b = CalculateHsRangeCa(minBucketsCounts, maxBucketsCounts,
                                                     "0.1 0.1 0.1 0.1", new int[] { 0, 1000, 1000, 1000 }, false);

            Console.WriteLine("Bucket counts: {0}", maxBucketsCounts);

            string[] d = new string[]
            {
                "Ac Ad",
                "Ac Kc",
                "7c 2d",
                "3c 2d",
                "Tc 9c",
                "8c 7c",
                "Ac Kc Tc Qc Jc",
                "3c 3d Ac 7d 3h",
                "7d 3d Ac 3c 3h",
                "Ad Ah Ac 7d 3h",
                "Ac Ah Qs 7d 6d",
                "5d 4d Qs 7d 6d",
                "8d 9d Qs 7d 6d",
                "Ad Ah Ac 7d 3h 5h",
                "Ad Ah Ac 7d 3h 5h 5d",
                "5c 5s Ac 7d 3h 5h 5d",
                "3c 2d Kc Td 7h",
                "3c 2d Kc Td 7h 5h Qs",
                "Js Jd 7h 8h 9h",
                "Js Jd 7h 8h 9h Jc",
                "Js Jd 7h 8h 9h 6h",
                "8c 7c",
                "8c 7c Ad Qc Jd",
                "8c 7c Ad Qc Jd 6c",
                "8c 7c Ad Qc Jd 6c 5c",
            };

            for (int i = 0; i < d.Length; ++i)
            {
                int[]  hand   = StdDeck.Descriptor.GetIndexes(d[i]);
                int    bucket = b.GetAbstractCard(hand, hand.Length);
                double hs     = HandStrength.CalculateFast(hand);
                Console.WriteLine("Hand '{0}' has strength {1:0.0000}, bucket {2}", d[i], hs, bucket);
            }
        }
Пример #16
0
        public void ProcessHand(int [] hand, int length)
        {
            double exp = 0.5;

            for (int round = 0; round < 4; ++round)
            {
                int roundHandLength = HeHelper.RoundToHandSize[round];
                if (roundHandLength > length)
                {
                    break;
                }
                double actHs     = HandStrength.CalculateFast(hand, roundHandLength);
                double deviation = actHs - exp;
                _accDeviation[round] += deviation;
                _handCount[round]++;
                exp = actHs;
            }
        }
Пример #17
0
        public DealtHandDTO(IEnumerable <CardModel> cards, HandStrength strength)
        {
            foreach (CardModel card in cards)
            {
                Cards.Add(new CardDTO(card.Suit.ToString(), card.Value.ToString()));
            }

            foreach (HandStrength r in Enum.GetValues(typeof(HandStrength)))
            {
                var type       = r.GetType();
                var memberInfo = type.GetMember(r.ToString());
                var attr       = memberInfo[0].GetCustomAttributes(false).OfType <EnumMemberAttribute>().FirstOrDefault();
                var name       = attr != null ? attr.Value : r.ToString();

                HandStrengths.Add(new StrengthDTO(name, (int)r));
            }

            Strength = strength;
        }
Пример #18
0
        public int GetBucket(CardSet pocket, CardSet board, int round)
        {
            int bucket;

            if (round == 0)
            {
                // preflop
                bucket = (int)HePockets.CardSetToPocketKind(pocket);
            }
            else
            {
                float hs = HandStrength.CalculateFast(pocket, board);
                bucket = (int)(BucketCount[round] * hs);
                if (bucket == BucketCount[round])
                {
                    bucket--; // Special correction for a single HS value of 1.0
                }
            }
            return(bucket);
        }
Пример #19
0
        public int GetAbstractCard(int[] hand, int handLength)
        {
            int round     = HeHelper.HandSizeToRound[handLength];
            int abstrCard = GetPreflopAbstrCard(hand);

            if (round == 0)
            {
                return(abstrCard);
            }
            RangeNode rn = (RangeNode)_clusterTree.Root.GetChild(abstrCard);

            for (int r = 1; r <= round; ++r)
            {
                float hs = HandStrength.CalculateFast(hand, HeHelper.RoundToHandSize[r]);
                abstrCard = rn.FindChildByValue(hs);
                rn        = rn.Children[abstrCard];
            }
            Debug.Assert(abstrCard >= 0 && abstrCard < MaxBucketCounts[round]);
            return(abstrCard);
        }
Пример #20
0
        /// <summary>
        /// Returns exclusive upper limits for ranges.
        /// </summary>
        float[] CalculateRanges(int round, McHand[] hands, out float[] values)
        {
            if (hands == null || hands.Length == 0)
            {
                if (IsVerbose)
                {
                    Console.WriteLine("Empty parent bucket");
                }
                values = new float[0];
                return(new float[] { float.PositiveInfinity });
            }
            values = new float[hands.Length];
            float min = float.MaxValue;
            float max = float.MinValue;

            for (int i = 0; i < hands.Length; ++i)
            {
                float value = HandStrength.CalculateFast(hands[i].Cards, hands[i].Length);
                values[i] = value;
                if (value < min)
                {
                    min = value;
                }
                if (value > max)
                {
                    max = value;
                }
            }
            int rangesCount = BucketCounts[round];

            float[] ranges = new float[rangesCount];
            float   step   = (max - min) / rangesCount;

            for (int i = 0; i < rangesCount - 1; ++i)
            {
                ranges[i] = (i + 1) * step + min;
            }
            ranges[rangesCount - 1] = float.PositiveInfinity;

            return(ranges);
        }
Пример #21
0
 public virtual void OnSessionBegin(string sessionName, GameDefinition gameDef, lib.utils.PropertyMap sessionParameters)
 {
     // Debugger.Break();
     _gameDef = gameDef;
     if (!_isInitialized)
     {
         // Do initialization here instead of in OnCreate() to allow the server start-up faster.
         string sessionSuiteDir = Path.GetDirectoryName(_creationParams["pkr.SessionSuiteXmlFileName"]);
         string strategyPath    = PathResolver.Resolve(_creationParams["Strategy"], new string[] { sessionSuiteDir });
         XmlSerializerExt.Deserialize(out _strategy, strategyPath);
         HandStrength.LoadPrecalculationTables();
         string[] mcReps = _creationParams.GetValueDef("MonteCarloCount", "-1, 5000, 3000, 3000").Split(
             new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);
         _monteCarloRepetitions = new int[mcReps.Length];
         for (int i = 0; i < mcReps.Length; ++i)
         {
             _monteCarloRepetitions[i] = int.Parse(mcReps[i]);
         }
         _isInitialized = true;
     }
 }
Пример #22
0
        public void Test_Pockets_Overall()
        {
            Console.WriteLine("Pocket hand strengths:");
            int [] indexes      = new int[2];
            double weighedSumHs = 0;
            int    sumCount     = 0;

            for (int i = 0; i < (int)HePocketKind.__Count; ++i)
            {
                HePocketKind pk    = (HePocketKind)i;
                int[]        hand  = HePocket.KindToHand(pk);
                double       s     = HandStrength.CalculateFast(hand);
                int          count = HePocket.KindToRange(pk).Length;
                Console.WriteLine("{0}  {1:0.0000} {2}", HePocket.KindToString(pk), s, count);
                weighedSumHs += s * count;
                sumCount     += count;
            }
            Console.WriteLine("Weighed sum:  {0:0.0000} {1}", weighedSumHs, sumCount);
            Assert.AreEqual(1326, sumCount);
            Assert.AreEqual(1326 * 0, 5, weighedSumHs, "Overall result must be 0.5 (tie)");
        }
Пример #23
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);
        }
Пример #24
0
        public void Test_CalculateFast_Regr()
        {
            string[] d = new string[]
            {
                //"Ac Ad Tc Qc Jc",
                //"Ac Ad As Ah 2c",
                //"Ad As Ac 7d 3h",
                //"Ad As Ac 3c 3h",
                //"Ad Ac 3d 3c 3h",
                //"Ah As Ac 7d 3h",
                //"Ac Ah Qs 7d 6d",
                //"Ad Ah Ac 7d 3h 5h",
                "Ad Ah Ac 7d 3h 5h 5d",
                "As Ah 5c 7d 3h 9h 5d",
            };
            float s;

            for (int i = 0; i < d.GetLength(0); ++i)
            {
                s = VerifyCalculateFast(_deck.GetIndexes(d[i]));
                Console.WriteLine("Hand {0} has strength {1:0.000000}", d[i], s);
            }

            // For preflop the calculation is very slow, therefore use samples verified with Poker Academy
            Assert.AreEqual(0.8520, HandStrength.CalculateFast(_deck.GetIndexes("Ac Ad")), 0.005);
            Assert.AreEqual(0.8520, HandStrength.CalculateFast(_deck.GetIndexes("As Ah")), 0.005);
            Assert.AreEqual(0.5085, HandStrength.CalculateFast(_deck.GetIndexes("9c 8c")), 0.005);
            Assert.AreEqual(0.5085, HandStrength.CalculateFast(_deck.GetIndexes("9s 8s")), 0.005);
            Assert.AreEqual(0.3455, HandStrength.CalculateFast(_deck.GetIndexes("7c 2d")), 0.005);
            Assert.AreEqual(0.3455, HandStrength.CalculateFast(_deck.GetIndexes("7s 2h")), 0.005);
            Assert.AreEqual(0.4165, HandStrength.CalculateFast(_deck.GetIndexes("Tc 2d")), 0.005);
            Assert.AreEqual(0.4165, HandStrength.CalculateFast(_deck.GetIndexes("Ts 2h")), 0.005);
            Assert.AreEqual(0.6705, HandStrength.CalculateFast(_deck.GetIndexes("Ac Kc")), 0.005);
            Assert.AreEqual(0.6705, HandStrength.CalculateFast(_deck.GetIndexes("Ad Kd")), 0.005);
            Assert.AreEqual(0.3225, HandStrength.CalculateFast(_deck.GetIndexes("3c 2d")), 0.005);
        }
Пример #25
0
 void OnPocket(ref CardSet pocket, HandDistrParams param)
 {
     param.Distr.Add(new HandDistrEntry {
         Pocket = pocket, Hs = HandStrength.CalculateFast(pocket, param.Board)
     });
 }
Пример #26
0
 public void SetPower(HandStrength power)
 {
     this.Power = power;
 }
 public PlayerEconomy(HandStrength hero, ICollection <HandStrength> opponents)
 {
     this.hero      = hero;
     this.opponents = opponents.ToList().AsReadOnly();
 }
Пример #28
0
 protected override void CalculateValue(int[] hand, int handLength, double[] value)
 {
     value[0] = HandStrength.CalculateFast(hand, handLength);
 }
Пример #29
0
        public void finishHand()
        {
            if (_prevMatchState == null)
            {
                return;
            }

            Console.WriteLine("Ending preveous hand");
            var handStrengths = new List <int>();

            if (_prevMatchState.board.Count == 5)
            {
                for (int i = 0; i < _botGameState.getPlayers().Count; i++)
                {
                    var player          = _botGameState.getPlayers()[i];
                    var playerHoleCards = _prevMatchState.playerHoleCards(player.PreFlopPosition, _numPlayers);

                    if (playerHoleCards == null)
                    {
                        handStrengths.Add(0);
                        continue;
                    }

                    var handStrength   = HandStrength.calculateHandStrength(playerHoleCards, _prevMatchState.board);
                    var holeCardsGuess = (player.Range.getHoleCardsProb(playerHoleCards) * 100).ToString("f1") + "%";

                    var plNameAndAction = "";

                    if (player.StatusInHand != Status.Folded)
                    {
                        plNameAndAction = player.Name + " shows";
                    }
                    else
                    {
                        plNameAndAction = player.Name + " folded";
                    }

                    Console.WriteLine(plNameAndAction + " (" + playerHoleCards + "): " + handStrength + " [Guess: " + holeCardsGuess + "]");

                    handStrengths.Add(handStrength.Value());
                }
            }
            else
            {
                foreach (var player in _botGameState.getPlayers())
                {
                    handStrengths.Add(0);
                }
            }

            var winnings = Pot.calculateWinnings(_botGameState.getPlayers(), handStrengths);

            _botGameState.finishHand(winnings);

            for (int i = 0; i < _botGameState.getPlayers().Count; i++)
            {
                if (winnings[i] > 0)
                {
                    Console.WriteLine(_botGameState.getPlayers()[i].Name + " wins: " + winnings[i]);
                }
            }

            int thisHandSaldo = hero().Stack - _startStackSize;

            _totalSaldo += thisHandSaldo;

            Console.WriteLine("This hand saldo: {0}, Total saldo: {1}", thisHandSaldo, _totalSaldo);

            var startTime = DateTime.Now;

            _opponentModeling.addHand(_botGameState.getCurrentHand());

            Console.WriteLine("Opponent modelling added hand " + timeToString(DateTime.Now - startTime));
        }
Пример #30
0
        public static HandStrength evaluateHand(PlayerHand playerHand)
        {
            HandStrength strength = new HandStrength();

            return(strength);
        }
Пример #31
0
 public void Test_PrecalcuateTables()
 {
     HandStrength.PrecalcuateTables(".", -1);
 }