private void VerifyWalk(TestTree tree, UFToUniAdapter adapter) { List <int> expectedPre = new List <int>(); List <int> expectedPost = new List <int>(); WalkUFTreePP <TestTree, WalkUFTreePPContext> wft = new WalkUFTreePP <TestTree, WalkUFTreePPContext>(); wft.OnNodeBegin = (t, s, d) => expectedPre.Add(tree.Nodes[s[d].NodeIdx].Value); wft.OnNodeEnd = (t, s, d) => expectedPost.Add(tree.Nodes[s[d].NodeIdx].Value); wft.Walk(tree); List <int> actualPre = new List <int>(); List <int> actualPost = new List <int>(); WalkTreePP <UFToUniAdapter, int, int, AdapterContext> wt = new WalkTreePP <UFToUniAdapter, int, int, AdapterContext>(); wt.OnNodeBegin = (t, n, s, d) => { actualPre.Add(tree.Nodes[n].Value); return(true); }; wt.OnNodeEnd = (t, n, s, d) => actualPost.Add(tree.Nodes[n].Value); wt.Walk(adapter, 0); Assert.AreEqual(expectedPre, actualPre); Assert.AreEqual(expectedPost, actualPost); int bi, cnt; adapter.GetChildrenBeginIdxAndCount(0, out bi, out cnt); Assert.AreEqual(4, cnt); }
/// <summary> /// Sets fields of the context. Override to customize view or call it in an overriden OnNodeBegin. /// </summary> protected virtual void SetContext(UFToUniAdapter aTree, int aNode, List <ContextT> stack, int depth) { ContextT context = stack[depth]; StrategyTree tree = (StrategyTree)(aTree.UfTree); context.Tree = tree; if (depth == 0) { context.Round = -1; } else { context.Round = stack[depth - 1].Round; } // Deal action => new round. if (tree.Nodes[aNode].IsDealerAction) { context.Round++; } context.Id = aNode.ToString(); context.IsDealerAction = tree.Nodes[aNode].IsDealerAction; context.Position = tree.Nodes[aNode].Position; context.Probab = tree.Nodes[aNode].IsDealerAction ? 0 : tree.Nodes[aNode].Probab; context.ActionLabel = depth == 0 ? "" : tree.Nodes[aNode].ToStrategicString(CardNames); }
protected override void OnTreeBeginFunc(UFToUniAdapter aTree, int aRoot) { StrategyTree tree = (StrategyTree)(aTree.UfTree); GraphAttributes.label = tree.Version.Description; GraphAttributes.fontsize = 20; base.OnTreeBeginFunc(aTree, aRoot); }
public void Test_Walk_FromFile() { int expectedNodesCount = 1 + 4 + 4 * 4;// +4 * 4 * 4; TestTree tree = new TestTree(expectedNodesCount); int idx = 0; CreateTestTree(tree, ref idx, 0, 2, 4); UFToUniAdapter adapter = new UFToUniAdapter(tree, Path.Combine(_outDir, "index.dat"), false); VerifyWalk(tree, adapter); }
protected override void CustomizeEdgeAttributes(UFToUniAdapter aTree, int n, int pn, List <Context> stack, int depth, Vis.EdgeAttributeMap attr) { base.CustomizeEdgeAttributes(aTree, n, pn, stack, depth, attr); StrategyTree tree = (StrategyTree)aTree.UfTree; if (!tree.Nodes[n].IsDealerAction && tree.Nodes[n].Position == Solver.HeroPosition && tree.Nodes[n].Probab == 1.0) { // Hero have chosen this edge - show thick attr.penwidth = 3.0; } }
public void Test_Walk_FromMemory() { int expectedNodesCount = 1 + 4 + 4 * 4;// +4 * 4 * 4; TestTree tree = new TestTree(expectedNodesCount); int idx = 0; CreateTestTree(tree, ref idx, 0, 2, 4); UFToUniAdapter adapter = new UFToUniAdapter(tree); VerifyWalk(tree, adapter); }
protected override void OnNodeEndFunc(UFToUniAdapter aTree, int aNode, List <Vis.Context> stack, int depth) { Context context = stack[depth]; StrategyTree tree = (StrategyTree)aTree.UfTree; if (depth > 0) { stack[depth - 1].Value += context.Value; } base.OnNodeEndFunc(aTree, aNode, stack, depth); }
public virtual string GetCardAttribute(UFToUniAdapter t, List <XmlizeTreeContext <int, int> > s, int d) { StrategyTree st = (StrategyTree)t.UfTree; if (!st.Nodes[s[d].Node].IsDealerAction) { return(""); } int card = st.Nodes[s[d].Node].Card; string cardText = DeckDescr != null ? DeckDescr.CardNames[card] : card.ToString(); return(cardText); }
protected override void CustomizeNodeAttributes(UFToUniAdapter aTree, int n, List <Context> stack, int depth, Vis.NodeAttributeMap attr) { base.CustomizeNodeAttributes(aTree, n, stack, depth, attr); StrategyTree tree = (StrategyTree)aTree.UfTree; if (!tree.Nodes[n].IsDealerAction && tree.Nodes[n].Position == Solver.HeroPosition && tree.Nodes[n].Probab != 1.0) { if (IsHtmlColor(attr.fillcolor)) { attr.fillcolor = GradientHtmlColor(attr.fillcolor, Color.FromArgb(255, 200, 200, 200), 0.4); } } }
protected override bool OnNodeBeginFunc(UFToUniAdapter aTree, int n, List <Context> stack, int depth) { Context context = stack[depth]; StrategyTree tree = (StrategyTree)aTree.UfTree; // Set default vis-fields SetContext(aTree, n, stack, depth); if (Solver._visGameValues != null) { context.Value = Solver._visGameValues[n]; } return(base.OnNodeBeginFunc(aTree, n, stack, depth)); }
protected override bool OnNodeBeginFunc(UFToUniAdapter aTree, int n, List <Context> stack, int depth) { Context context = stack[depth]; StrategyTree tree = (StrategyTree)aTree.UfTree; // Set default vis-fields SetContext(aTree, n, stack, depth); context.Value = 0; if (depth == 0) { context.ActionTreeIdx = 0; } else { context.ActionTreeIdx = stack[depth - 1].ActionTreeIdx; context.ChanceIdx = stack[depth - 1].ChanceIdx; if (tree.Nodes[n].IsDealerAction) { context.ChanceIdx += Solver.CalculateChanceOffset(context.Round, Position) * tree.Nodes[n].Card; } else { // Find the corresponding node in the action tree context.ActionTreeIdx = Solver.FindActionTreeNodeIdx(tree, n, context.ActionTreeIdx, stack[depth - 1].ChildrenIterator - 1); if (Solver._actionTreeIndex.GetChildrenCount(context.ActionTreeIdx) == 0) { // A leaf. context.Value = Solver._visLeaveValues[Position][context.ActionTreeIdx][context.ChanceIdx]; } } } return(base.OnNodeBeginFunc(aTree, n, stack, depth)); }
/// <summary> /// Converts a given tree. The convertion is controlled by the properties. /// </summary> /// <param name="t"></param> public void Convert(StrategyTree t) { UFToUniAdapter adapter = new UFToUniAdapter(t); Walk(adapter, 0); }
public virtual string GetPositionAttribute(UFToUniAdapter t, List <XmlizeTreeContext <int, int> > s, int d) { return(((StrategyTree)t.UfTree).Nodes[s[d].Node].Position.ToString()); }
public void Show(StrategyTree t, int root) { UFToUniAdapter adapter = new UFToUniAdapter(t); Walk(adapter, root); }
public virtual string GetProbabAttribute(UFToUniAdapter t, List <XmlizeTreeContext <int, int> > s, int d) { return(((StrategyTree)t.UfTree).Nodes[s[d].Node].IsDealerAction ? "" : ((StrategyTree)t.UfTree).Nodes[s[d].Node].Probab.ToString()); }
protected override bool OnNodeBeginFunc(UFToUniAdapter aTree, int aNode, List <ContextT> stack, int depth) { SetContext(aTree, aNode, stack, depth); return(base.OnNodeBeginFunc(aTree, aNode, stack, depth)); }
public virtual string GetNodeName(UFToUniAdapter t, List <XmlizeTreeContext <int, int> > s, int d) { return(((StrategyTree)t.UfTree).Nodes[s[d].Node].IsDealerAction ? "d" : "p"); }
protected override void OnTreeBeginFunc(UFToUniAdapter aTree, int root) { StrategyTree tree = (StrategyTree)aTree.UfTree; base.OnTreeBeginFunc(aTree, root); }