Пример #1
0
        // HTS_Node_search: tree search
        public int SearchNode(string tString)
        {
            HTS_Node node = this.root;

            while (node != null)
            {
                if (node.quest == null)
                {
                    return(node.pdf);
                }

                if (node.quest.Match(tString) == true)
                {
                    if (node.yes.pdf > 0)
                    {
                        return(node.yes.pdf);
                    }
                    node = node.yes;
                }
                else
                {
                    if (node.no.pdf > 0)
                    {
                        return(node.no.pdf);
                    }
                    node = node.no;
                }
            }

            Debug.LogError("HTS_Tree_search_node: Cannot find node.");
            return(1);
        }
Пример #2
0
 private void Initialize()
 {
     this.head  = null;
     this.next  = null;
     this.root  = null;
     this.state = 0;
 }
Пример #3
0
 private void Initialize()
 {
     index = 0;
     pdf   = 0;
     yes   = null;
     no    = null;
     next  = null;
     quest = null;
 }
Пример #4
0
        // HTS_Node_find: find node for given number
        public static HTS_Node Find(HTS_Node node, int num)
        {
            for ( ; node != null; node = node.next)
            {
                if (node.index == num)
                {
                    return(node);
                }
            }

            return(null);
        }
Пример #5
0
        // HTS_Tree_load: load trees
        public bool Load(HTS_File fp, HTS_Question question)
        {
            string tToken;

            HTS_Node node, last_node;

            if (fp == null)
            {
                return(false);
            }

            tToken = fp.GetPatternToken();
            if (string.IsNullOrEmpty(tToken) == true)
            {
                Initialize();
                return(false);
            }

            node = new HTS_Node();

            this.root = last_node = node;

            if (tToken == "{")
            {
                int v;

                tToken = fp.GetPatternToken();
                while (string.IsNullOrEmpty(tToken) == false && tToken != "}")
                {
                    int.TryParse(tToken, out v);
                    node = HTS_Node.Find(last_node, v);
                    if (node == null)
                    {
                        Debug.LogError("HTS_Tree_load: Cannot find node " + v + " .");
                        Initialize();
                        return(false);
                    }

                    tToken = fp.GetPatternToken();
                    if (string.IsNullOrEmpty(tToken) == true)
                    {
                        Initialize();
                        return(false);
                    }

                    node.quest = HTS_Question.Find(question, tToken);
                    if (node.quest == null)
                    {
                        Debug.LogError("HTS_Tree_load: Cannot find question " + tToken + ".");
                        Initialize();
                        return(false);
                    }

                    node.yes = new HTS_Node();
                    node.no  = new HTS_Node();

                    tToken = fp.GetPatternToken();
                    if (string.IsNullOrEmpty(tToken) == true)
                    {
                        node.quest = null;
                        node.yes   = null;
                        node.no    = null;
                        Initialize();
                        return(false);
                    }

                    if (IsNum(tToken) == true)
                    {
                        int.TryParse(tToken, out v);
                        node.no.index = v;
                    }
                    else
                    {
                        node.no.pdf = Name2num(tToken);
                    }
                    node.no.next = last_node;
                    last_node    = node.no;

                    tToken = fp.GetPatternToken();
                    if (string.IsNullOrEmpty(tToken) == true)
                    {
                        node.quest = null;
                        node.yes   = null;
                        node.no    = null;
                        Initialize();
                        return(false);
                    }

                    if (IsNum(tToken) == true)
                    {
                        int.TryParse(tToken, out v);
                        node.yes.index = v;
                    }
                    else
                    {
                        node.yes.pdf = Name2num(tToken);
                    }
                    node.yes.next = last_node;
                    last_node     = node.yes;

                    // 最後
                    tToken = fp.GetPatternToken();
                }
            }
            else
            {
                node.pdf = Name2num(tToken);
            }

            return(true);
        }