コード例 #1
0
        public static StrategyTree CreateStrategyTree(GameDefinition gd, int pos)
        {
            ChanceTree   ct  = CreateChanceTreeByGameDef.Create(gd);
            ChanceTree   pct = ExtractPlayerChanceTree.ExtractS(ct, 0);
            ActionTree   at  = CreateActionTreeByGameDef.Create(gd);
            StrategyTree st  = CreateStrategyTreeByChanceAndActionTrees.CreateS(pct, at);

            return(st);
        }
コード例 #2
0
            public OcfrParams(GameValue_Test test, string name, string gameDefFile, IChanceAbstraction[] abstractions, string[] ocfrFiles, double[] expectedResult, double epsilon)
            {
                Epsilon        = epsilon;
                ExpectedResult = expectedResult;

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

                Name = name;

                OcfrFiles = new string[GameDef.MinPlayers].Fill(i => Path.Combine(test._testResDir, ocfrFiles[i]));
                if (abstractions == null)
                {
                    ChanceTree = CreateChanceTreeByGameDef.Create(GameDef);
                }
                else
                {
                    ChanceTree = CreateChanceTreeByAbstraction.CreateS(GameDef, abstractions);
                }

                //VisChanceTree.Show(ChanceTree, Path.Combine(test._outDir, String.Format("{0}-c.gv", GameDef.Name)));

                ActionTree = CreateActionTreeByGameDef.Create(GameDef);

                StrategyTrees = new StrategyTree[GameDef.MinPlayers];

                for (int p = 0; p < GameDef.MinPlayers; ++p)
                {
                    ChanceTree pct = ExtractPlayerChanceTree.ExtractS(ChanceTree, p);
                    StrategyTrees[p] = CreateStrategyTreeByChanceAndActionTrees.CreateS(pct, ActionTree);


                    OpenCfrStrategyConverter conv = new OpenCfrStrategyConverter
                    {
                        GameDef           = GameDef,
                        HeroPosition      = p,
                        SourceFile        = OcfrFiles[p],
                        Strategy          = StrategyTrees[p],
                        ChanceAbstraction = abstractions == null ? null : abstractions[p]
                    };
                    conv.Convert();

                    //VisStrategyTree.Show(StrategyTrees[p], Path.Combine(test._outDir, String.Format("{0}-str-{1}.gv", GameDef.Name, p)));
                }
            }
コード例 #3
0
        public void Test_Leduc()
        {
            GameDefinition gd = XmlSerializerExt.Deserialize <GameDefinition>(
                Props.Global.Expand("${bds.DataDir}ai.pkr.metastrategy/leduc-he.gamedef.xml"));
            ActionTree at  = CreateActionTreeByGameDef.Create(gd);
            ChanceTree ct  = CreateChanceTreeByGameDef.Create(gd);
            ChanceTree pct = ExtractPlayerChanceTree.ExtractS(ct, 0);

            TestWalker tw = new TestWalker {
                ActionTree = at, PlayerChanceTree = pct
            };

            tw.Walk();
            Console.WriteLine("Begin: a:{0} c:{1} total:{2}", tw.BeginCount[0], tw.BeginCount[1], tw.BeginCount[0] + tw.BeginCount[1]);
            Assert.AreEqual(674, tw.BeginCount[0]);
            Assert.AreEqual(48, tw.BeginCount[1]);
            Assert.AreEqual(_leduc, tw.Text);
        }
コード例 #4
0
ファイル: EqReb_Test.cs プロジェクト: ivan-alles/poker-acpc
        public void Test_Kuhn()
        {
            GameDefinition gd = XmlSerializerExt.Deserialize <GameDefinition>(
                Props.Global.Expand("${bds.DataDir}ai.pkr.metastrategy/kuhn.gamedef.xml"));

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

            StrategyTree [] playerTrees = new StrategyTree[2];
            for (int p = 0; p < 2; ++p)
            {
                ChanceTree   pct = ExtractPlayerChanceTree.ExtractS(ct, p);
                StrategyTree st  = CreateStrategyTreeByChanceAndActionTrees.CreateS(pct, at);
                playerTrees[p] = st;

                VisStrategyTree.Show(st, Path.Combine(_outDir, string.Format("pt-{0}.gv", p)));
            }
        }
コード例 #5
0
        private void CreateAndVerifyPlayerTrees(GameDefinition gd, ChanceTree ct, double [] expectedProbabs)
        {
            for (int pos = 0; pos < gd.MinPlayers; ++pos)
            {
                ChanceTree pct = ExtractPlayerChanceTree.ExtractS(ct, pos);

                string fileName = string.Format("{0}-{1}.gv", gd.Name, pos);
                using (TextWriter w = new StreamWriter(File.Open(Path.Combine(_outDir, fileName), FileMode.Create)))
                {
                    VisChanceTree vis = new VisChanceTree {
                        Output = w, CardNames = gd.DeckDescr.CardNames
                    };
                    vis.Show(pct);
                }
                Assert.AreEqual(1, pct.PlayersCount);
                Assert.AreEqual(expectedProbabs.Length, pct.NodesCount);
                VerifyChanceTree.VerifyS(pct);
                for (int i = 0; i < expectedProbabs.Length; ++i)
                {
                    Assert.AreEqual(expectedProbabs[i], pct.Nodes[i].Probab, 0.00000000001, string.Format("Node {0}", i));
                }
            }
        }
コード例 #6
0
        private static bool ProcessStrategyTree()
        {
            StrategyTree tree;

            if (_cmdLine.Input != "")
            {
                if (_inputFormat == ".dat")
                {
                    tree = UFTree.Read <StrategyTree>(_cmdLine.Input);
                }
                else if (_inputFormat == ".txt")
                {
                    tree = DumpStrategyTree.FromTxt(_cmdLine.Input);
                }
                else
                {
                    Console.Error.WriteLine("Unsupported input format '{0}' for tree kind '{1}'", _inputFormat, _cmdLine.TreeKind);
                    return(false);
                }
            }
            else
            {
                ActionTree at  = CreateActionTreeByGameDef.Create(_gd);
                ChanceTree ct  = CreateChanceTreeByGameDef.Create(_gd);
                ChanceTree pct = ExtractPlayerChanceTree.ExtractS(ct, _cmdLine.Position);
                tree = CreateStrategyTreeByChanceAndActionTrees.CreateS(pct, at);
            }

            if (_outputFormat == ".gv")
            {
                using (TextWriter w = new StreamWriter(File.Open(_cmdLine.Output, FileMode.Create)))
                {
                    VisStrategyTree vis = new VisStrategyTree {
                        Output = w
                    };
                    if (_gd != null)
                    {
                        vis.CardNames = _gd.DeckDescr.CardNames;
                    }
                    if (_cmdLine.ClearExpr)
                    {
                        vis.ShowExpr.Clear();
                    }
                    vis.ShowExprFromString(_cmdLine.ShowExpr);
                    vis.PruneIfExt = (t, n, s, d) => s[d].Round > _cmdLine.MaxRound;
                    vis.MatchPath  = _cmdLine.MatchPath;
                    vis.Show(tree, _cmdLine.Root);
                }
            }
            else if (_outputFormat == ".xml")
            {
                using (TextWriter w = new StreamWriter(File.Open(_cmdLine.Output, FileMode.Create)))
                {
                    XmlWriterSettings settings = new XmlWriterSettings();
                    settings.Encoding = Encoding.ASCII;
                    settings.Indent   = true;
                    using (XmlWriter xmlWriter = XmlWriter.Create(w, settings))
                    {
                        StrategyTreeToXml xmlizer = new StrategyTreeToXml {
                            Output = xmlWriter
                        };
                        if (_cmdLine.ClearExpr)
                        {
                            xmlizer.ShowExpr.Clear();
                        }
                        xmlizer.ShowExprFromString(_cmdLine.ShowExpr);
                        xmlizer.Convert(tree);
                    }
                }
            }
            else if (_outputFormat == ".dat")
            {
                tree.Write(_cmdLine.Output);
            }
            else if (_outputFormat == ".txt")
            {
                DumpStrategyTree.ToTxt(tree, _cmdLine.Output);
            }
            else
            {
                Console.Error.WriteLine("Unsupported ouput format '{0}' for tree kind '{1}'", _outputFormat, _cmdLine.TreeKind);
                return(false);
            }
            return(true);
        }
コード例 #7
0
        private static bool ProcessChanceTree()
        {
            ChanceTree tree;

            if (_cmdLine.Input != "")
            {
                if (_inputFormat == ".dat")
                {
                    tree = UFTree.Read <ChanceTree>(_cmdLine.Input);
                }
                else if (_inputFormat == ".txt")
                {
                    tree = DumpChanceTree.FromTxt(_cmdLine.Input);
                }
                else
                {
                    Console.Error.WriteLine("Unsupported input format '{0}' for tree kind '{1}'", _inputFormat, _cmdLine.TreeKind);
                    return(false);
                }
            }
            else
            {
                tree = CreateChanceTreeByGameDef.Create(_gd);
                if (_cmdLine.TreeKind == "chance-player")
                {
                    ChanceTree pt = ExtractPlayerChanceTree.ExtractS(tree, _cmdLine.Position);
                    tree = pt;
                }
            }

            if (_outputFormat == ".gv")
            {
                using (TextWriter w = new StreamWriter(File.Open(_cmdLine.Output, FileMode.Create)))
                {
                    VisChanceTree vis = new VisChanceTree {
                        Output = w
                    };
                    if (_gd != null)
                    {
                        vis.CardNames = _gd.DeckDescr.CardNames;
                    }
                    if (_cmdLine.ClearExpr)
                    {
                        vis.ShowExpr.Clear();
                    }
                    vis.ShowExprFromString(_cmdLine.ShowExpr);
                    vis.PruneIfExt = (t, n, s, d) => s[d].Round > _cmdLine.MaxRound;
                    vis.MatchPath  = _cmdLine.MatchPath;
                    vis.Show(tree);
                }
            }
            else if (_outputFormat == ".dat")
            {
                tree.Write(_cmdLine.Output);
            }
            else if (_outputFormat == ".txt")
            {
                DumpChanceTree.ToTxt(tree, _cmdLine.Output);
            }
            else
            {
                Console.Error.WriteLine("Unsupported output format '{0}' for tree kind '{1}'", _outputFormat, _cmdLine.TreeKind);
                return(false);
            }
            return(true);
        }