Пример #1
0
        public static void ToTxt(StrategyTree t, TextWriter w)
        {
            w.WriteLine("SeralizationFormat {0}", SERIALIZATION_FORMAT);
            XmlWriterSettings s = new XmlWriterSettings {
                Indent = false, NewLineChars = ""
            };

            w.Write("Version ");
            XmlSerializerExt.Serialize(t.Version, w, s);
            w.WriteLine();
            w.WriteLine("NodesCount {0}", t.NodesCount);
            for (Int64 n = 0; n < t.NodesCount; ++n)
            {
                w.WriteLine("Id {0}", n);
                w.WriteLine("D {0}", t.GetDepth(n));
                w.WriteLine("P {0}", t.Nodes[n].Position);
                if (t.Nodes[n].IsDealerAction)
                {
                    w.WriteLine("C {0}", t.Nodes[n].Card);
                }
                else
                {
                    w.WriteLine("A {0}", TextDumpHelper.DoubleToBinString(t.Nodes[n].Amount));
                    w.WriteLine("Pr {0}", TextDumpHelper.DoubleToBinString(t.Nodes[n].Probab));
                }
            }
        }
        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);
                }
            }
        }