/// <summary>
        /// Computes a preference matrix with preference probability based on maximum of pocket equity
        /// for given pairs (0 or 1). Pocket equity is given by PocketEquity class.
        /// </summary>
        public static double[,] ComputePreferenceMatrixPeMax(HePocketKind [] pockets)
        {
            int n = pockets.Length;

            double[] cardProbabs = PocketHelper.GetProbabDistr(pockets);
            double[,] ptMax = new double[n, n];
            for (int i = 0; i < n; ++i)
            {
                HePocketKind p1 = pockets[i];
                for (int j = 0; j <= i; ++j)
                {
                    HePocketKind        p2 = pockets[j];
                    PocketEquity.Result r  = PocketEquity.CalculateFast(p1, p2);
                    if (i == j || r.Equity == 0.5)
                    {
                        ptMax[i, j] = 0.5;
                    }
                    else
                    {
                        ptMax[i, j] = r.Equity > 0.5 ? 1 : 0;
                    }
                    ptMax[j, i] = 1 - ptMax[i, j];
                }
            }
            return(ptMax);
        }
Пример #2
0
        public void Test_Calculate_Range()
        {
            DeckDescriptor d = StdDeck.Descriptor;
            CardSet[] range1 = new CardSet[] { d.GetCardSet("Ac Ah"), d.GetCardSet("Kc Kd") };
            CardSet[] range2 = new CardSet[] { d.GetCardSet("7h 6h"), d.GetCardSet("5c 4d") };

            PocketEquity.Result r = PocketEquity.Calculate(range1, range2);
            Assert.AreEqual(0.79960, r.Equity, 0.000005);
            Assert.AreEqual(4, r.Count);
        }
Пример #3
0
 public double Equity(int[] range1, int[] range2)
 {
     HePocketKind [] prange1 = new HePocketKind[range1.Length];
     HePocketKind [] prange2 = new HePocketKind[range2.Length];
     for (int i = 0; i < range1.Length; ++i)
     {
         prange1[i] = (HePocketKind)range1[i];
     }
     for (int i = 0; i < range2.Length; ++i)
     {
         prange2[i] = (HePocketKind)range2[i];
     }
     PocketEquity.Result r = PocketEquity.CalculateFast(prange1, prange2);
     return(r.Equity);
 }
Пример #4
0
        public void Test_CalculateFast_Array()
        {
            HePocketKind[] pockets1 = new HePocketKind[] { HePocketKind._55, HePocketKind._66 };
            HePocketKind[] pockets2 = new HePocketKind[] { HePocketKind._76s, HePocketKind._76o };

            PocketEquity.Result r = PocketEquity.CalculateFast(pockets1, pockets2);
            Assert.AreEqual(0.56058, r.Equity, 0.000005);
            Assert.AreEqual(246571776L / EnumAlgos.CountCombin(48,5), r.Count);

            pockets1 = new HePocketKind[] { HePocketKind._AKs, HePocketKind._AQs };
            pockets2 = new HePocketKind[] { HePocketKind._88, HePocketKind._77 };

            r = PocketEquity.CalculateFast(pockets1, pockets2);
            Assert.AreEqual(0.47681, r.Equity, 0.000005);
            Assert.AreEqual(164381184L / EnumAlgos.CountCombin(48, 5), r.Count);
        }
Пример #5
0
 public void Test_CalculateFast_VerifyAll()
 {
     double totalEquity = 0;
     uint totalCount = 0;
     int matchupsCount = 0;
     for (int pk1 = 0; pk1 < HePocket.Count; pk1++)
     {
         for (int pk2 = 0; pk2 < HePocket.Count; pk2++)
         {
             PocketEquity.Result r = PocketEquity.CalculateFast((HePocketKind)pk1, (HePocketKind)pk2);
             totalEquity += r.Equity;
             totalCount += r.Count;
             matchupsCount++;
         }
     }
     int expTotalCount = (int) (EnumAlgos.CountCombin(52, 2)*EnumAlgos.CountCombin(50, 2));
     Assert.AreEqual(totalCount, expTotalCount);
     Assert.AreEqual((double)169*169/2, totalEquity, 0.00001);
 }
        /// <summary>
        /// Computes a preference matrix with preference probability based on pocket equity
        /// given by PocketEquity class.
        /// </summary>
        public static double[,] ComputePreferenceMatrixPe(HePocketKind[] pockets)
        {
            int n = pockets.Length;

            double[] cardProbabs = PocketHelper.GetProbabDistr(pockets);
            double[,] ptEq = new double[n, n];
            for (int i = 0; i < n; ++i)
            {
                HePocketKind p1 = pockets[i];
                for (int j = 0; j <= i; ++j)
                {
                    HePocketKind        p2 = pockets[j];
                    PocketEquity.Result r  = PocketEquity.CalculateFast(p1, p2);
                    ptEq[i, j] = r.Equity;
                    ptEq[j, i] = 1 - ptEq[i, j];
                }
            }
            return(ptEq);
        }
Пример #7
0
        private ChanceTree CreateCt(HePocketKind[] sbCards, HePocketKind[] bbCards)
        {
            int        nodeCount = 1 + sbCards.Length + sbCards.Length * bbCards.Length;
            ChanceTree ct        = new ChanceTree(nodeCount);

            ct.PlayersCount    = 2;
            ct.Nodes[0].Probab = 1;
            ct.SetDepth(0, 0);

            int totalCombSB = 0;

            foreach (HePocketKind p in sbCards)
            {
                totalCombSB += HePocket.KindToRange(p).Length;
            }

            for (int c0 = 0; c0 < sbCards.Length; ++c0)
            {
                int          sbNode   = 1 + c0 * (bbCards.Length + 1);
                HePocketKind sbPocket = sbCards[c0];
                ct.SetDepth(sbNode, 1);
                ct.Nodes[sbNode].Position = 0;
                ct.Nodes[sbNode].Probab   = (double)HePocket.KindToRange(sbPocket).Length / totalCombSB;
                ct.Nodes[sbNode].Card     = c0;

                double[] oppDealProbabCond = PocketHelper.GetProbabDistr(bbCards, HePocket.KindToCardSet(sbPocket));

                for (int c1 = 0; c1 < bbCards.Length; ++c1)
                {
                    int bbNode = sbNode + 1 + c1;
                    ct.SetDepth(bbNode, 2);
                    ct.Nodes[bbNode].Position = 1;
                    ct.Nodes[bbNode].Probab   = ct.Nodes[sbNode].Probab * oppDealProbabCond[c1];
                    ct.Nodes[bbNode].Card     = c1;
                    PocketEquity.Result pe = PocketEquity.CalculateFast(sbPocket, bbCards[c1]);
                    var potShare           = new double[] { pe.Equity, 1 - pe.Equity };
                    ct.Nodes[bbNode].SetPotShare(3, potShare);
                }
            }
            VerifyChanceTree.VerifyS(ct, 1e-5);
            return(ct);
        }
Пример #8
0
        public static ChanceTree CreateCt(HePocketKind [] pockets, double [] oppCardProbab)
        {
            int n = pockets.Count();

            double[] dealProbab = PocketHelper.GetProbabDistr(pockets);

            int        nodeCount = 1 + n + n * n;
            ChanceTree ct        = new ChanceTree(nodeCount);

            ct.PlayersCount    = 2;
            ct.Nodes[0].Probab = 1;
            ct.SetDepth(0, 0);
            for (int c0 = 0; c0 < n; ++c0)
            {
                int heroNode = 1 + c0 * (n + 1);
                ct.SetDepth(heroNode, 1);
                ct.Nodes[heroNode].Position = 0;
                ct.Nodes[heroNode].Probab   = dealProbab[c0];
                ct.Nodes[heroNode].Card     = c0;

                double[] corrOppProbab = CorrectOpponentProbab(pockets, c0, dealProbab, oppCardProbab);

                for (int c1 = 0; c1 < n; ++c1)
                {
                    int oppNode = heroNode + 1 + c1;
                    ct.SetDepth(oppNode, 2);
                    ct.Nodes[oppNode].Position = 1;
                    ct.Nodes[oppNode].Probab   = ct.Nodes[heroNode].Probab * corrOppProbab[c1];
                    ct.Nodes[oppNode].Card     = c1;
                    PocketEquity.Result pe = PocketEquity.CalculateFast(pockets[c0], pockets[c1]);
                    var potShare           = new double[] { pe.Equity, 1 - pe.Equity };
                    ct.Nodes[oppNode].SetPotShare(3, potShare);
                }
            }
            VerifyChanceTree.VerifyS(ct, 1e-5);
            return(ct);
        }