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 #2
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);
        }