public void TestSbr() { var sbr = new Sbr { HeadNumber = 1, SiteNumber = 1, }; TestRoundTripEquality(sbr); sbr.BinName = "Bob"; TestRoundTripEquality(sbr); }
private void WriteSbr(List <PartResult> list) { Sbr sbr; var groupBySite = list.GroupBy(x => x.SiteNumber); foreach (var colBySite in groupBySite) { List <PartResult> itemsBySite = colBySite.ToList <PartResult>(); var groupByBin = itemsBySite.GroupBy(x => x.SoftBin); foreach (var colByBin in groupByBin) { List <PartResult> itemsByBin = colByBin.ToList <PartResult>(); sbr = new Sbr(); sbr.HEAD_NUM = 1; sbr.SITE_NUM = colBySite.Key; sbr.RecordHeader.REC_LEN += 1; sbr.SBIN_NUM = colByBin.Key.BinNum; sbr.RecordHeader.REC_LEN += 2; sbr.SBIN_CNT = (uint)itemsByBin.Count; sbr.RecordHeader.REC_LEN += 4; sbr.SBIN_PF = (char)colByBin.Key.BinPF; sbr.SBIN_NAM = colByBin.Key.BinName; sbr.RecordHeader.REC_LEN += (ushort)sbr.SBIN_NAM.Length; sfw.WriteRecord(sbr); } } var group = list.GroupBy(x => x.SoftBin); foreach (var col in group) { List <PartResult> items = col.ToList <PartResult>(); sbr = new Sbr(); sbr.HEAD_NUM = 255; sbr.SITE_NUM = 0; sbr.RecordHeader.REC_LEN += 1; sbr.SBIN_NUM = col.Key.BinNum; sbr.RecordHeader.REC_LEN += 2; sbr.SBIN_CNT = (uint)items.Count; sbr.RecordHeader.REC_LEN += 4; sbr.SBIN_PF = (char)col.Key.BinPF; sbr.SBIN_NAM = col.Key.BinName; sbr.RecordHeader.REC_LEN += (ushort)sbr.SBIN_NAM.Length; sfw.WriteRecord(sbr); } }
private Sbr FindBestResponse(StrategyHelper strHelper, int pos, GameDefinition gd, Sbr.CreateRootGenNodeDelegate createRootGenNodeDelegate) { Sbr br = new Sbr(); br.GameDef = gd; br.HeroPosition = pos; if (createRootGenNodeDelegate != null) { br.CreateRootGenNode = createRootGenNodeDelegate; } strHelper.SetProbabilityOfOppAction(); br.SetOppStrategy(1 - pos, strHelper.OppStrategy.ToArray()); br.Calculate(); return(br); }
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]); } }
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]); } }