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

            string testDir = UTHelper.GetTestResourceDir(Assembly.GetExecutingAssembly());

            ChanceTree ct1 = CreateChanceTreeByGameDef.Create(gd);
            // DumpChanceTree.ToTxt(ct1, Console.Out);

            MemoryStream ms = new MemoryStream();

            using (TextWriter tw = new StreamWriter(ms))
            {
                DumpChanceTree.ToTxt(ct1, tw);
            }
            byte[] buf = ms.ToArray();
            ms = new MemoryStream(buf);
            ChanceTree ct2;

            using (TextReader tr = new StreamReader(ms))
            {
                ct2 = DumpChanceTree.FromTxt(tr);
            }
            Assert.AreEqual(ct1.Version, ct2.Version);
            Assert.AreEqual(ct1.NodesCount, ct2.NodesCount);
            int roundsCount = ct1.CalculateRoundsCount();

            double[] potShare1 = new double[ct1.PlayersCount];
            double[] potShare2 = new double[ct1.PlayersCount];
            for (Int64 n = 0; n < ct2.NodesCount; ++n)
            {
                Assert.AreEqual(ct1.GetDepth(n), ct2.GetDepth(n));
                Assert.AreEqual(ct1.Nodes[n].Position, ct2.Nodes[n].Position);
                Assert.AreEqual(ct1.Nodes[n].Card, ct2.Nodes[n].Card);
                Assert.AreEqual(ct1.Nodes[n].Probab, ct2.Nodes[n].Probab);
                if (ct1.GetDepth(n) == ct1.PlayersCount * roundsCount)
                {
                    UInt16 [] activePlayerMasks = ActivePlayers.Get(ct1.PlayersCount, 2, ct1.PlayersCount);
                    foreach (UInt16 ap in activePlayerMasks)
                    {
                        ct1.Nodes[n].GetPotShare(ap, potShare1);
                        ct2.Nodes[n].GetPotShare(ap, potShare2);
                        Assert.AreEqual(potShare1, potShare2);
                    }
                }
            }
        }
Example #2
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);
        }