Exemple #1
0
        private static bool ProcessActionTree()
        {
            ActionTree tree;

            if (_cmdLine.Input != "")
            {
                tree = UFTree.Read <ActionTree>(_cmdLine.Input);
            }
            else
            {
                tree = CreateActionTreeByGameDef.Create(_gd);
            }

            if (_outputFormat == ".gv")
            {
                using (TextWriter w = new StreamWriter(File.Open(_cmdLine.Output, FileMode.Create)))
                {
                    VisActionTree vis = new VisActionTree {
                        Output = w
                    };
                    if (_cmdLine.ClearExpr)
                    {
                        vis.ShowExpr.Clear();
                    }
                    vis.ShowExprFromString(_cmdLine.ShowExpr);
                    vis.PruneIfExt = (t, n, s, d) => s[d].Round > _cmdLine.MaxRound;
                    vis.MatchPath  = _cmdLine.MatchPath;
                    vis.Show(tree);
                }
            }
            else if (_outputFormat == ".dat")
            {
                tree.Write(_cmdLine.Output);
            }
            else
            {
                Console.Error.WriteLine("Unsupported output format '{0}' for tree kind '{1}'", _outputFormat, _cmdLine.TreeKind);
                return(false);
            }
            return(true);
        }
Exemple #2
0
            bool SyncNodes(Node uniTree, object uniNode, byte uniDepth, int uniIt, UFTree ufTree, Int64 ufNode, object userData)
            {
                ChanceTree ct = (ChanceTree)ufTree;

                ct.SetDepth(ufNode, uniDepth);
                ct.Nodes[ufNode].Card     = uniDepth == 0 ? 0 : uniIt - 1;
                ct.Nodes[ufNode].Position = (uniDepth - 1) % PlayersCount;
                if (uniNode is LeafT)
                {
                    // This is a leaf
                    LeafT leaf = (LeafT)uniNode;

                    ct.Nodes[ufNode].Probab = (double)leaf.Count / SamplesCount;
                    double [] potShares = new double[2];
                    potShares[0] = 0.5 * leaf.Result / leaf.Count;
                    potShares[1] = 1 - potShares[0];
                    ct.Nodes[ufNode].SetPotShare(0x11, potShares);
                }
                else
                {
                    ct.Nodes[ufNode].Probab = 0;
                }
                return(true);
            }
        bool Sync(TestUniNode uniTree, TestUniNode uniNode, byte uniDepth, int uniIt, UFTree ufTree, Int64 ufNode, object userData)
        {
            Assert.AreEqual(uniDepth, ufTree.GetDepth(ufNode), String.Format("ufNode: {0}", ufNode));
            TestUfTree tufTree = (TestUfTree)ufTree;

            Assert.AreEqual(uniDepth == 0 ? 0 : uniNode.ChildIndex + 1, uniIt);
            Assert.AreEqual(uniNode.Id, tufTree.Nodes[ufNode].Id);
            Assert.AreEqual("bla", userData);
            return(true);
        }
Exemple #4
0
        private static bool ProcessStrategyTree()
        {
            StrategyTree tree;

            if (_cmdLine.Input != "")
            {
                if (_inputFormat == ".dat")
                {
                    tree = UFTree.Read <StrategyTree>(_cmdLine.Input);
                }
                else if (_inputFormat == ".txt")
                {
                    tree = DumpStrategyTree.FromTxt(_cmdLine.Input);
                }
                else
                {
                    Console.Error.WriteLine("Unsupported input format '{0}' for tree kind '{1}'", _inputFormat, _cmdLine.TreeKind);
                    return(false);
                }
            }
            else
            {
                ActionTree at  = CreateActionTreeByGameDef.Create(_gd);
                ChanceTree ct  = CreateChanceTreeByGameDef.Create(_gd);
                ChanceTree pct = ExtractPlayerChanceTree.ExtractS(ct, _cmdLine.Position);
                tree = CreateStrategyTreeByChanceAndActionTrees.CreateS(pct, at);
            }

            if (_outputFormat == ".gv")
            {
                using (TextWriter w = new StreamWriter(File.Open(_cmdLine.Output, FileMode.Create)))
                {
                    VisStrategyTree vis = new VisStrategyTree {
                        Output = w
                    };
                    if (_gd != null)
                    {
                        vis.CardNames = _gd.DeckDescr.CardNames;
                    }
                    if (_cmdLine.ClearExpr)
                    {
                        vis.ShowExpr.Clear();
                    }
                    vis.ShowExprFromString(_cmdLine.ShowExpr);
                    vis.PruneIfExt = (t, n, s, d) => s[d].Round > _cmdLine.MaxRound;
                    vis.MatchPath  = _cmdLine.MatchPath;
                    vis.Show(tree, _cmdLine.Root);
                }
            }
            else if (_outputFormat == ".xml")
            {
                using (TextWriter w = new StreamWriter(File.Open(_cmdLine.Output, FileMode.Create)))
                {
                    XmlWriterSettings settings = new XmlWriterSettings();
                    settings.Encoding = Encoding.ASCII;
                    settings.Indent   = true;
                    using (XmlWriter xmlWriter = XmlWriter.Create(w, settings))
                    {
                        StrategyTreeToXml xmlizer = new StrategyTreeToXml {
                            Output = xmlWriter
                        };
                        if (_cmdLine.ClearExpr)
                        {
                            xmlizer.ShowExpr.Clear();
                        }
                        xmlizer.ShowExprFromString(_cmdLine.ShowExpr);
                        xmlizer.Convert(tree);
                    }
                }
            }
            else if (_outputFormat == ".dat")
            {
                tree.Write(_cmdLine.Output);
            }
            else if (_outputFormat == ".txt")
            {
                DumpStrategyTree.ToTxt(tree, _cmdLine.Output);
            }
            else
            {
                Console.Error.WriteLine("Unsupported ouput format '{0}' for tree kind '{1}'", _outputFormat, _cmdLine.TreeKind);
                return(false);
            }
            return(true);
        }
Exemple #5
0
        private static bool ProcessChanceTree()
        {
            ChanceTree tree;

            if (_cmdLine.Input != "")
            {
                if (_inputFormat == ".dat")
                {
                    tree = UFTree.Read <ChanceTree>(_cmdLine.Input);
                }
                else if (_inputFormat == ".txt")
                {
                    tree = DumpChanceTree.FromTxt(_cmdLine.Input);
                }
                else
                {
                    Console.Error.WriteLine("Unsupported input format '{0}' for tree kind '{1}'", _inputFormat, _cmdLine.TreeKind);
                    return(false);
                }
            }
            else
            {
                tree = CreateChanceTreeByGameDef.Create(_gd);
                if (_cmdLine.TreeKind == "chance-player")
                {
                    ChanceTree pt = ExtractPlayerChanceTree.ExtractS(tree, _cmdLine.Position);
                    tree = pt;
                }
            }

            if (_outputFormat == ".gv")
            {
                using (TextWriter w = new StreamWriter(File.Open(_cmdLine.Output, FileMode.Create)))
                {
                    VisChanceTree vis = new VisChanceTree {
                        Output = w
                    };
                    if (_gd != null)
                    {
                        vis.CardNames = _gd.DeckDescr.CardNames;
                    }
                    if (_cmdLine.ClearExpr)
                    {
                        vis.ShowExpr.Clear();
                    }
                    vis.ShowExprFromString(_cmdLine.ShowExpr);
                    vis.PruneIfExt = (t, n, s, d) => s[d].Round > _cmdLine.MaxRound;
                    vis.MatchPath  = _cmdLine.MatchPath;
                    vis.Show(tree);
                }
            }
            else if (_outputFormat == ".dat")
            {
                tree.Write(_cmdLine.Output);
            }
            else if (_outputFormat == ".txt")
            {
                DumpChanceTree.ToTxt(tree, _cmdLine.Output);
            }
            else
            {
                Console.Error.WriteLine("Unsupported output format '{0}' for tree kind '{1}'", _outputFormat, _cmdLine.TreeKind);
                return(false);
            }
            return(true);
        }