예제 #1
0
        public void Test_GenerateFiles()
        {
            XmlStrategyHelper strHelper = new XmlStrategyHelper();

            string dataDir    = Props.Global.Get("bds.DataDir");
            string workingDir = Directory.GetCurrentDirectory() + @"..\..\..\..\";

            GameDefinition gd = XmlSerializerExt.Deserialize <GameDefinition>(
                Path.Combine(dataDir, "ai.pkr.metastrategy.kuhn.gamedef.1.xml"));

            bool[] normSuits = new bool[] { false, true };

            int pos = 0;

            strHelper.HeroPosition = pos;

            strHelper.StrategyFiles = new string[] { null, Path.Combine(workingDir, "kuhn-s-1-eq.xml") };
            strHelper.LoadStrategies();
            Sbr brEq = FindBestResponse(strHelper, pos, gd, null);

            Assert.AreEqual(-1.0 / 18, brEq.PlayerTrees[pos].Value, 0.00000001);
            Assert.AreEqual(1.0, brEq.PlayerTrees[pos].Probab, 0.00000001);

            // Nodes 3 and 8 have equal values, but we would prefer to chose node 3 for this
            // demonstration.
            brEq.PlayerTrees[pos].Children[0].Children[0].BestActionIndex = 0;

            using (TextWriter tw = new StreamWriter(Path.Combine(workingDir, "br-eq-p0.gv")))
            {
                VisBr visBr = new VisBr {
                    Output = tw
                };
                SetVisAttributes(visBr);
                //visBr.NodeAttributes.margin = "0.001,0.005";
                visBr.ShowExpr.Add(new ExprFormatter("s[d].Node.Id", "id:{1}"));
                visBr.ShowExpr.Add(new ExprFormatter("-s[d].Node.Value", "\\nv:{1:0.000}"));
                visBr.Walk(brEq.PlayerTrees[pos]);
            }
        }
예제 #2
0
        public void Test_GenerateFiles()
        {
            XmlStrategyHelper strHelper = new XmlStrategyHelper();

            string dataDir    = Props.Global.Get("bds.DataDir");
            string workingDir = Directory.GetCurrentDirectory() + @"..\..\..\..\";

            GameDefinition gd = XmlSerializerExt.Deserialize <GameDefinition>(
                Path.Combine(dataDir, "ai.pkr.metastrategy.kuhn.gamedef.1.xml"));

            bool[] normSuits = new bool[] { false, true };

            int pos = 0;

            strHelper.HeroPosition = pos;

            strHelper.StrategyFiles = new string[] { null, Path.Combine(workingDir, "kuhn-s-1-eq.xml") };
            strHelper.LoadStrategies();
            Sbr brEq = FindBestResponse(strHelper, pos, gd, null);

            Assert.AreEqual(-1.0 / 18, brEq.PlayerTrees[pos].Value, 0.00000001);
            Assert.AreEqual(1.0, brEq.PlayerTrees[pos].Probab, 0.00000001);

            using (TextWriter tw = new StreamWriter(Path.Combine(workingDir, "str-eq-p1.gv")))
            {
                Sbr.Visualizer vis = new VisStr {
                    Output = tw
                };
                SetVisAttributes(vis);
                vis.NodeAttributes.fontsize = 10;
                vis.ShowExpr.Add(new ExprFormatter("s[d].Node.Id", "id:{1}"));
                vis.ShowExpr.Add(new ExprFormatter("s[d].Node.StrategicProbab", "\\nsp:{1:0.###}        "));
                vis.Walk(brEq.PlayerTrees[1 - pos]);
            }

            using (TextWriter tw = new StreamWriter(Path.Combine(workingDir, "br-eq-p0.gv")))
            {
                VisBr visBr = new VisBr {
                    Output = tw
                };
                // visBr.SetDefaultAttrbutes(brEq, perspective);
                SetVisAttributes(visBr);
                visBr.ShowExpr.Add(new ExprFormatter("s[d].Node.Id", "id:{1}"));
                visBr.ShowExpr.Add(new ExprFormatter("-s[d].Node.Value", "\\nv:{1:0.0000}    "));
                visBr.Walk(brEq.PlayerTrees[pos]);
            }

            strHelper.StrategyFiles = new string[] { null, Path.Combine(workingDir, "kuhn-s-1-qf-.xml") };
            strHelper.LoadStrategies();
            brEq = FindBestResponse(strHelper, pos, gd, null);

            Assert.AreEqual(1.0, brEq.PlayerTrees[pos].Probab, 0.00000001);

            using (TextWriter tw = new StreamWriter(Path.Combine(workingDir, "br-qf--p0.gv")))
            {
                VisBr visBr = new VisBrNoEq {
                    Output = tw
                };
                // visBr.SetDefaultAttrbutes(brEq, perspective);
                SetVisAttributes(visBr);
                visBr.ShowExpr.Add(new ExprFormatter("s[d].Node.Id", "id:{1}"));
                visBr.ShowExpr.Add(new ExprFormatter("-s[d].Node.Value", "\\nv:{1:0.0000}    "));
                visBr.Walk(brEq.PlayerTrees[pos]);
            }

            strHelper.StrategyFiles = new string[] { null, Path.Combine(workingDir, "kuhn-s-1-qf+.xml") };
            strHelper.LoadStrategies();
            brEq = FindBestResponse(strHelper, pos, gd, null);

            Assert.AreEqual(1.0, brEq.PlayerTrees[pos].Probab, 0.00000001);

            using (TextWriter tw = new StreamWriter(Path.Combine(workingDir, "br-qf+-p0.gv")))
            {
                VisBr visBr = new VisBrNoEq {
                    Output = tw
                };
                // visBr.SetDefaultAttrbutes(brEq, perspective);
                SetVisAttributes(visBr);
                visBr.ShowExpr.Add(new ExprFormatter("s[d].Node.Id", "id:{1}"));
                visBr.ShowExpr.Add(new ExprFormatter("-s[d].Node.Value", "\\nv:{1:0.0000}    "));
                visBr.Walk(brEq.PlayerTrees[pos]);
            }
        }