Esempio n. 1
0
        public void Test_CreateCt()
        {
            int oppCount = 2;
            var pockets  = PocketHelper.GetAllPockets();
            //var pockets = new HePocketKind[] { HePocketKind._AA, HePocketKind._76s, HePocketKind._72o };
            var pocketDist = PocketHelper.GetProbabDistr(pockets);

            double[,] ptPeMax = MultiplayerPocketProbability.ComputePreferenceMatrixPeMax(pockets);


            string     xmlAt = Props.Global.Expand("${bds.DataDir}ai.pkr.holdem.learn/nlpf-1.xml");
            ActionTree at    = XmlToActionTree.Convert(xmlAt);

            string[] actionLabels = CreateActionLabels(at, 0);
            Dictionary <string, int> actionLabelToId = new Dictionary <string, int>();

            for (int i = 0; i < actionLabels.Length; ++i)
            {
                actionLabelToId.Add(actionLabels[i], i);
            }

            double[]   oppDist = MultiplayerPocketProbability.Compute(oppCount, pocketDist, ptPeMax);
            ChanceTree ct      = PreflopStrategy.CreateCt(pockets, oppDist);


            //GameDefinition gd = XmlSerializerExt.Deserialize<GameDefinition>(Props.Global.Expand("${bds.DataDir}ai.pkr.metastrategy/${0}", "kuhn.gamedef.xml"));
            //at = CreateActionTreeByGameDef.Create(gd);
            //ct = CreateChanceTreeByGameDef.Create(gd);

            VisChanceTree.Show(ct, Path.Combine(_outDir, "ct.gv"));
            VisActionTree.Show(at, Path.Combine(_outDir, "at.gv"));

            StrategyTree[] st = SolveAndVerifyVerifySolution(at, ct, 0.001, false);

            double[,] fs = FlattenStrategy(st[0], 0, pockets.Length, actionLabelToId);

            Console.WriteLine("Result for opponent count: {0}", oppCount);
            Console.Write("{0,4}", oppCount);
            foreach (string al in actionLabels)
            {
                Console.Write("{0,20}", al);
            }
            Console.WriteLine();
            int raiseCount = 0;

            for (int c = 0; c < pockets.Length; ++c)
            {
                Console.Write("{0,4}", HePocket.KindToString(pockets[c]));
                for (int j = 0; j < actionLabels.Length; ++j)
                {
                    Console.Write("{0,20}", Math.Round(fs[c, j] * 100, 0));
                }
                if (fs[c, actionLabels.Length - 1] > 0.9)
                {
                    raiseCount += HePocket.KindToRange(pockets[c]).Length;
                }
                Console.WriteLine();
            }
            Console.WriteLine("Raise count: {0}", raiseCount);
        }
Esempio n. 2
0
        public void Test_1()
        {
            double[] cardProbabs = new double[] { 0.7, 0.3 };
            double[,] preferenceTable = new double[2, 2] {
                { 0.5, 0.1 }, { 0.9, 0.5 }
            };
            double[] result = MultiplayerPocketProbability.Compute(2, cardProbabs, preferenceTable);
            VerifyResult(cardProbabs.Length, result);
            Assert.AreEqual(result[0], 0.532, 1e-10);
            Assert.AreEqual(result[1], 0.468, 1e-10);

            cardProbabs     = new double[] { 0.3, 0.7 };
            preferenceTable = new double[2, 2] {
                { 0.5, 0.9 }, { 0.1, 0.5 }
            };
            result = MultiplayerPocketProbability.Compute(2, cardProbabs, preferenceTable);
            VerifyResult(cardProbabs.Length, result);
            Assert.AreEqual(result[1], 0.532, 1e-10);
            Assert.AreEqual(result[0], 0.468, 1e-10);
        }
Esempio n. 3
0
 public void Test_HePockets()
 {
     double[] cardProbabs = new double[169];
     for (int i = 0; i < 169; ++i)
     {
         cardProbabs[i] = HePocket.KindToRange((HePocketKind)i).Length / 1326.0;
     }
     double[,] ptEq  = MultiplayerPocketProbability.ComputePreferenceMatrixPe(PocketHelper.GetAllPockets());
     double[,] ptMax = MultiplayerPocketProbability.ComputePreferenceMatrixPeMax(PocketHelper.GetAllPockets());
     double[][] resEq  = new double[10][];
     double[][] resMax = new double[10][];
     for (int pc = 1; pc < 10; ++pc)
     {
         resEq[pc] = MultiplayerPocketProbability.Compute(pc, cardProbabs, ptEq);
         VerifyResult(169, resEq[pc]);
         resMax[pc] = MultiplayerPocketProbability.Compute(pc, cardProbabs, ptMax);
         VerifyResult(169, resMax[pc]);
     }
     Console.WriteLine();
     Console.Write("{0,3} ", "Poc");
     for (int pc = 1; pc < 10; ++pc)
     {
         Console.Write("{0,6} {1,6} ", pc.ToString() + " eq", pc.ToString() + " max");
     }
     Console.WriteLine();
     for (int i = 0; i < 169; ++i)
     {
         HePocketKind p = (HePocketKind)i;
         Console.Write("{0,3} ", HePocket.KindToString(p));
         for (int pc = 1; pc < 10; ++pc)
         {
             Console.Write("{0,6:0.00} {1,6:0.00} ", resEq[pc][i] * 100, resMax[pc][i] * 100);
         }
         Console.WriteLine();
     }
 }