public void Test_Leduc()
        {
            GameDefinition gd = XmlSerializerExt.Deserialize <GameDefinition>(
                Props.Global.Expand("${bds.DataDir}ai.pkr.metastrategy/leduc-he.gamedef.xml"));

            string[] strategyFilesRel = new string[] { "eq-LeducHe-0-s.xml", "eq-LeducHe-1-s.xml" };
            string[] StrategyFilesAbs = new string[gd.MinPlayers].Fill(i => Path.Combine(_testResDir, strategyFilesRel[i]));

            StrategyTree[] strategiesOrig = new StrategyTree[gd.MinPlayers].Fill(i =>
                                                                                 XmlToStrategyTree.Convert(StrategyFilesAbs[i], gd.DeckDescr));

            ChanceTree ct = CreateChanceTreeByGameDef.Create(gd);
            ActionTree at = CreateActionTreeByGameDef.Create(gd);

            GameValue gv1 = new GameValue {
                ActionTree = at, ChanceTree = ct, Strategies = strategiesOrig
            };

            gv1.Solve();

            for (int p = 0; p < gd.MinPlayers; ++p)
            {
                StrategyTree[] strategiesMerged = new StrategyTree[gd.MinPlayers].Fill(i =>
                                                                                       XmlToStrategyTree.Convert(StrategyFilesAbs[i], gd.DeckDescr));

                // Merge strategy to the stategy at postion p.
                for (int pSrc = 0; pSrc < gd.MinPlayers; ++pSrc)
                {
                    if (p == pSrc)
                    {
                        continue;
                    }
                    MergeStrategies.Merge(strategiesMerged[p], strategiesMerged[pSrc], pSrc);
                }
                // Copy strategy at position p to the other positions
                for (int pCopy = 0; pCopy < gd.MinPlayers; ++pCopy)
                {
                    strategiesMerged[pCopy] = strategiesMerged[p];
                }

                GameValue gv2 = new GameValue {
                    ActionTree = at, ChanceTree = ct, Strategies = strategiesMerged
                };
                gv2.Solve();
                Assert.AreEqual(gv1.Values, gv2.Values);
            }
        }
        public void Test_Compare()
        {
            GameDefinition gd = XmlSerializerExt.Deserialize <GameDefinition>(
                Props.Global.Expand("${bds.DataDir}ai.pkr.metastrategy/kuhn.gamedef.xml"));

            string testDir = UTHelper.GetTestResourceDir(Assembly.GetExecutingAssembly());
            string strFile = Path.Combine(testDir, "eq-KunhPoker-0-s.xml");


            StrategyTree st0 = XmlToStrategyTree.Convert(strFile, gd.DeckDescr);
            StrategyTree st1 = XmlToStrategyTree.Convert(strFile, gd.DeckDescr);

            CompareStrategyTrees comparer = new CompareStrategyTrees
            {
                IsVerbose = true
            };

            comparer.Compare(st0, st1);
            for (int p = 0; p < 2; ++p)
            {
                Assert.AreEqual(0, comparer.SumProbabDiff[p]);
                Assert.AreEqual(0, comparer.MaxProbabDiff[p]);
                Assert.AreEqual(0, comparer.AverageProbabDiff[p]);
                Assert.AreEqual(13, comparer.PlayerNodesCount[p]);
            }

            // Now change a probability

            Assert.IsTrue(st0.Nodes[4].Probab <= 0.9);
            Assert.IsTrue(st0.Nodes[9].Probab >= 0.1);
            st0.Nodes[4].Probab += 0.1;
            st0.Nodes[9].Probab -= 0.1;

            comparer.Compare(st0, st1);
            Assert.AreEqual(0.2, comparer.SumProbabDiff[0], 1e-8);
            Assert.AreEqual(0.1, comparer.MaxProbabDiff[0], 1e-8);
            Assert.AreEqual(0.2 / 13, comparer.AverageProbabDiff[0], 1e-8);
            Assert.AreEqual(13, comparer.PlayerNodesCount[0]);

            Assert.AreEqual(0, comparer.SumProbabDiff[1]);
            Assert.AreEqual(0, comparer.MaxProbabDiff[1]);
            Assert.AreEqual(0, comparer.AverageProbabDiff[1]);
            Assert.AreEqual(13, comparer.PlayerNodesCount[1]);
        }
        public void Test_AnalyzeS()
        {
            GameDefinition gd = XmlSerializerExt.Deserialize <GameDefinition>(
                Props.Global.Expand("${bds.DataDir}ai.pkr.metastrategy/kuhn.gamedef.xml"));

            string[] strategyFiles = new string[] { "eq-KunhPoker-0-s.xml", "eq-KunhPoker-1-s.xml" };
            for (int pos = 0; pos < 2; ++pos)
            {
                string       strFile = Path.Combine(_testResDir, strategyFiles[pos]);
                StrategyTree st      = XmlToStrategyTree.Convert(strFile, gd.DeckDescr);
                VisStrategyTree.Show(st, Path.Combine(_outDir, string.Format("{0}-{1}.gv", gd.Name, pos)));
                AnalyzeStrategyTree an = new AnalyzeStrategyTree
                {
                    StrategyTree = st,
                    IsAbsolute   = true,
                    HeroPosition = pos,
                    IsVerbose    = true
                };
                an.Analyze();
                Assert.AreEqual(15, an.LeavesCount);
                if (pos == 0)
                {
                    Assert.AreEqual(12, an.MovesCount);
                    Assert.AreEqual(5, an.ZaspMovesCount);
                    Assert.AreEqual(3, an.ZaspLeavesCount);
                    Assert.AreEqual(1, an.Statistics.Count);
                    Assert.AreEqual(5, an.Statistics[0].NZaspMovesCount);
                    Assert.AreEqual(1 + 0.33333, an.Statistics[0].SumNZaspFold, 0.00001);
                    Assert.AreEqual(0.66667 + 1 + 0.66667, an.Statistics[0].SumNZaspCall, 0.00001);
                    Assert.AreEqual(0.33333 + 1, an.Statistics[0].SumNZaspRaise, 0.00001);
                }
                else
                {
                    Assert.AreEqual(12, an.MovesCount);
                    Assert.AreEqual(4, an.ZaspMovesCount);
                    Assert.AreEqual(3, an.ZaspLeavesCount);
                    Assert.AreEqual(1, an.Statistics.Count);
                    Assert.AreEqual(6, an.Statistics[0].NZaspMovesCount);
                    Assert.AreEqual(1 + 0.66667, an.Statistics[0].SumNZaspFold, 0.00001);
                    Assert.AreEqual(0.66667 + 1 + 0.33333 + 1, an.Statistics[0].SumNZaspCall, 0.00001);
                    Assert.AreEqual(0.33333 + 1, an.Statistics[0].SumNZaspRaise, 0.00001);
                }
            }
        }
        public void Test_Convert()
        {
            GameDefinition gd = XmlSerializerExt.Deserialize <GameDefinition>(
                Props.Global.Expand("${bds.DataDir}ai.pkr.metastrategy/kuhn.gamedef.xml"));

            string testDir = UTHelper.GetTestResourceDir(Assembly.GetExecutingAssembly());
            string xmlFile = Path.Combine(testDir, "eq-KunhPoker-0-s.xml");

            StrategyTree st1 = XmlToStrategyTree.Convert(xmlFile, gd.DeckDescr);
            //StrategyTreeDump.ToTxt(st1, Console.Out);

            MemoryStream ms = new MemoryStream();

            using (TextWriter tw = new StreamWriter(ms))
            {
                DumpStrategyTree.ToTxt(st1, tw);
            }
            byte[] buf = ms.ToArray();
            ms = new MemoryStream(buf);
            StrategyTree st2;

            using (TextReader tr = new StreamReader(ms))
            {
                st2 = DumpStrategyTree.FromTxt(tr);
            }
            Assert.AreEqual(st1.Version, st2.Version);
            Assert.AreEqual(st1.NodesCount, st2.NodesCount);
            for (Int64 n = 0; n < st2.NodesCount; ++n)
            {
                Assert.AreEqual(st1.GetDepth(n), st2.GetDepth(n));
                Assert.AreEqual(st1.Nodes[n].Position, st2.Nodes[n].Position);
                Assert.AreEqual(st1.Nodes[n].IsDealerAction, st2.Nodes[n].IsDealerAction);
                if (st1.Nodes[n].IsDealerAction)
                {
                    Assert.AreEqual(st1.Nodes[n].Card, st2.Nodes[n].Card);
                }
                else
                {
                    Assert.AreEqual(st1.Nodes[n].Amount, st2.Nodes[n].Amount);
                    Assert.AreEqual(st1.Nodes[n].Probab, st2.Nodes[n].Probab);
                }
            }
        }
Beispiel #5
0
            public GameDefParams(GameValue_Test test, string gameDefFile, string[] strategyFiles, double[] expectedResult, double epsilon)
            {
                Epsilon        = epsilon;
                ExpectedResult = expectedResult;

                GameDef = XmlSerializerExt.Deserialize <GameDefinition>(
                    Props.Global.Expand("${bds.DataDir}ai.pkr.metastrategy/${0}",
                                        gameDefFile));

                Name = GameDef.Name;

                StrategyFiles = new string[GameDef.MinPlayers].Fill(i => Path.Combine(test._testResDir, strategyFiles[i]));

                StrategyTrees = new StrategyTree[GameDef.MinPlayers].Fill(i =>
                                                                          XmlToStrategyTree.Convert(StrategyFiles[i], GameDef.DeckDescr));

                ChanceTree = CreateChanceTreeByGameDef.Create(GameDef);
                ActionTree = CreateActionTreeByGameDef.Create(GameDef);
            }
Beispiel #6
0
        public void Test_Verify()
        {
            string [] strFiles = new string[] { "eq-KunhPoker-0-s.xml", "eq-KunhPoker-1-s.xml" };

            GameDefinition gd = XmlSerializerExt.Deserialize <GameDefinition>(
                Props.Global.Expand("${bds.DataDir}ai.pkr.metastrategy/kuhn.gamedef.xml"));

            StrategyTree[] st = new StrategyTree[gd.MinPlayers];
            for (int i = 0; i < gd.MinPlayers; ++i)
            {
                string strPath = Path.Combine(_testResDir, strFiles[i]);
                st[i] = XmlToStrategyTree.Convert(strPath, gd.DeckDescr);
            }
            ActionTree at = CreateActionTreeByGameDef.Create(gd);
            ChanceTree ct = CreateChanceTreeByGameDef.Create(gd);
            string     error;

            Assert.IsTrue(VerifyEq.Verify(at, ct, st, 0.0000001, out error), error);
            // Now modify the strategy (with a J: not always fold to a r)
            st[1].Nodes[10].Probab = 0.5;
            st[1].Nodes[11].Probab = 0.5;
            Assert.IsFalse(VerifyEq.Verify(at, ct, st, 0.0000001, out error));
        }
Beispiel #7
0
        public void Test_Kuhn()
        {
            GameDefinition gd = XmlSerializerExt.Deserialize <GameDefinition>(
                Props.Global.Expand("${bds.DataDir}ai.pkr.metastrategy/kuhn.gamedef.xml"));

            string testDir = UTHelper.GetTestResourceDir(Assembly.GetExecutingAssembly());
            string xmlFile = Path.Combine(testDir, "eq-KunhPoker-0-s.xml");

            StrategyTree st = XmlToStrategyTree.Convert(xmlFile, gd.DeckDescr);

            // Do some random checks
            Assert.AreEqual(false, st.Nodes[4].IsDealerAction);
            Assert.AreEqual(0, st.Nodes[4].Position);
            Assert.AreEqual(0.666666666666667, st.Nodes[4].Probab);

            Assert.AreEqual(false, st.Nodes[6].IsDealerAction);
            Assert.AreEqual(1, st.Nodes[6].Position);
            Assert.AreEqual(1, st.Nodes[6].Amount);

            Assert.AreEqual(true, st.Nodes[12].IsDealerAction);
            Assert.AreEqual(0, st.Nodes[12].Position);
            Assert.AreEqual(1, st.Nodes[12].Card);
        }