Exemplo n.º 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));
                }
            }
        }
Exemplo n.º 2
0
        static void SaveActionTree()
        {
            Console.WriteLine("Writing opponent action tree to {0} ...", _cmdLine.oppActionTreeFile);

            XmlWriterSettings xws = new XmlWriterSettings();

            xws.Indent = false;
            XmlSerializerExt.Serialize(_oppActionTree, _cmdLine.oppActionTreeFile, xws);
        }
Exemplo n.º 3
0
        public void Test_XmlSerialize()
        {
            // Just print xml to console, no checks for now.
            Props p = new Props();

            p.Set("p1", "val1");
            XmlSerializerExt.Serialize(p, Console.Out);
            p.XmlMergeWithGlobal = false;
            Console.WriteLine();
            XmlSerializerExt.Serialize(p, Console.Out);
        }
Exemplo n.º 4
0
        public static void ToTxt(ChanceTree t, TextWriter w)
        {
            int roundsCount = t.CalculateRoundsCount();

            if (t.PlayersCount != 2)
            {
                throw new ApplicationException("Only 2 players are supported");
            }
            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);
            w.WriteLine("RoundsCount {0}", roundsCount);
            double [] potShare = new double[t.PlayersCount];
            for (Int64 n = 0; n < t.NodesCount; ++n)
            {
                w.WriteLine("Id {0}", n);
                byte depth = t.GetDepth(n);
                w.WriteLine("D {0}", depth);
                w.WriteLine("P {0}", t.Nodes[n].Position);
                w.WriteLine("C {0}", t.Nodes[n].Card);
                w.WriteLine("Pr {0}", TextDumpHelper.DoubleToBinString(t.Nodes[n].Probab));
                if (depth == roundsCount * t.PlayersCount)
                {
                    UInt16 [] activePlayerMasks = ActivePlayers.Get(t.PlayersCount, 2, t.PlayersCount);
                    foreach (UInt16 ap in activePlayerMasks)
                    {
                        t.Nodes[n].GetPotShare(ap, potShare);
                        w.Write("Ps {0:X}", ap);
                        foreach (double ps in potShare)
                        {
                            w.Write(" {0}", TextDumpHelper.DoubleToBinString(ps));
                        }
                        w.WriteLine();
                    }
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Creates files for each chance abstraction based on the template file.
        /// Tries to reuse the same chance abstration if buckets strings are the same
        /// to test Patience in this mode.
        /// </summary>
        /// <param name="runDir"></param>
        /// <param name="bucketizerStrings"></param>
        /// <returns></returns>
        private IChanceAbstraction[] PrepareConfigsAndChanceAbstractions(string runDir, string[] bucketizerStrings)
        {
            string botPropsFile = Path.Combine(runDir, "props.xml");
            Props  botProps     = XmlSerializerExt.Deserialize <Props>(botPropsFile);

            IChanceAbstraction[] chanceAbstractions = new IChanceAbstraction[bucketizerStrings.Length];

            string caPropsTemplateFile = Path.Combine(runDir, "chance-abstraction-props-template.xml");

            for (int p = 0; p < bucketizerStrings.Length; ++p)
            {
                for (int p1 = 0; p1 < p; ++p1)
                {
                    // Try to reuse the same chance abstraction.
                    if (bucketizerStrings[p1] == bucketizerStrings[p])
                    {
                        botProps.Set(string.Format("ChanceAbstraction-{0}", p),
                                     string.Format("chance-abstraction-props-{0}.xml", p1));
                        botProps.Set(string.Format("Strategy-{0}", p), string.Format("strategy-{0}.dat", p1));
                        chanceAbstractions[p] = chanceAbstractions[p1];
                        goto next;
                    }
                }

                Props caProps = XmlSerializerExt.Deserialize <Props>(caPropsTemplateFile);
                caProps.Set("BucketsString", bucketizerStrings[p]);
                botProps.Set(string.Format("ChanceAbstraction-{0}", p),
                             string.Format("chance-abstraction-props-{0}.xml", p));

                string caPropsFileRel = string.Format("chance-abstraction-props-{0}.xml", p);
                string caPropsFileAbs = Path.Combine(runDir, caPropsFileRel);
                XmlSerializerExt.Serialize(caProps, caPropsFileAbs);
                botProps.Set(string.Format("ChanceAbstraction-{0}", p), caPropsFileRel);
                botProps.Set(string.Format("Strategy-{0}", p), string.Format("strategy-{0}.dat", p));

                chanceAbstractions[p] = ChanceAbstractionHelper.CreateFromProps(caProps);

                next :;
            }
            XmlSerializerExt.Serialize(botProps, botPropsFile);
            File.Delete(caPropsTemplateFile);
            return(chanceAbstractions);
        }