/// <summary> /// Set initial strategy. /// </summary> private void SetInitialStrategy(int pos) { IterationCounts[pos]++; WalkUFTreePP <StrategyTree, SetInitialStrategyContext> wt = new WalkUFTreePP <StrategyTree, SetInitialStrategyContext>(); wt.OnNodeBegin = (t, s, d) => { Int64 n = s[d].NodeIdx; s[d].HeroChildren.Clear(); if (d > 0) { s[d].Probab = s[d - 1].Probab; } if (d > _playersCount) { if (t.Nodes[n].IsPlayerAction(pos)) { s[d - 1].HeroChildren.Add(n); #if false // Pure strategy if (s[d].Probab > 0) { t.Nodes[n].Probab = s[d - 1].ChildrenCount == 1 ? 1 : 0; } s[d].Probab = t.Nodes[n].Probab; #endif } } }; wt.OnNodeEnd = (t, s, d) => { Int64 n = s[d].NodeIdx; if (s[d].HeroChildren.Count > 0) { #if true // Mixed strategy double condProbab = 1.0 / s[d].HeroChildren.Count; foreach (long ch in s[d].HeroChildren) { t.Nodes[ch].Probab = condProbab; } #endif } }; wt.Walk(_pt); ConvertCondToAbs.Convert(_pt, pos); string error; if (!VerifyAbsStrategy.Verify(_pt, pos, out error)) { throw new ApplicationException(String.Format("Initial strategy inconsistent: {0}", error)); } }
public void Test_Convert() { GameDefinition gd = XmlSerializerExt.Deserialize <GameDefinition>( Props.Global.Expand("${bds.DataDir}ai.pkr.metastrategy/kuhn.gamedef.xml")); StrategyTree st = TreeHelper.CreateStrategyTree(gd, 0); st.Nodes[4].Probab = 0.4; st.Nodes[9].Probab = 0.6; st.Nodes[7].Probab = 0.3; st.Nodes[8].Probab = 0.7; st.Nodes[13].Probab = 0.5; st.Nodes[18].Probab = 0.5; st.Nodes[16].Probab = 0.1; st.Nodes[17].Probab = 0.9; st.Nodes[22].Probab = 0.2; st.Nodes[27].Probab = 0.8; st.Nodes[25].Probab = 0.5; st.Nodes[26].Probab = 0.5; string error; Assert.IsTrue(VerifyCondStrategy.Verify(st, 0, out error), error); ConvertCondToAbs.Convert(st, 0); Assert.IsTrue(VerifyAbsStrategy.Verify(st, 0, 1e-7, out error), error); Assert.AreEqual(0.4, st.Nodes[4].Probab, 1e-7); Assert.AreEqual(0.6, st.Nodes[9].Probab, 1e-7); Assert.AreEqual(0.12, st.Nodes[7].Probab, 1e-7); Assert.AreEqual(0.28, st.Nodes[8].Probab, 1e-7); Assert.AreEqual(0.5, st.Nodes[13].Probab, 1e-7); Assert.AreEqual(0.5, st.Nodes[18].Probab, 1e-7); Assert.AreEqual(0.05, st.Nodes[16].Probab, 1e-7); Assert.AreEqual(0.45, st.Nodes[17].Probab, 1e-7); Assert.AreEqual(0.2, st.Nodes[22].Probab, 1e-7); Assert.AreEqual(0.8, st.Nodes[27].Probab, 1e-7); Assert.AreEqual(0.1, st.Nodes[25].Probab, 1e-7); Assert.AreEqual(0.1, st.Nodes[26].Probab, 1e-7); }
public void Convert() { LoadStrategy(); ConvertCondToAbs.Convert(Strategy, HeroPosition); }