Ejemplo n.º 1
0
 private bool HandleHintInPathTo(NonLeafNode root, string nodeName, Common.HintType hint)
 {
     if (root.NodeName == nodeName)
     {
         return true;
     }
     else
     {
         Node[] children = root.Children;
         for (byte i = 0; i < children.Length; i++)
         {
             if (children[i] is NonLeafNode)
             {
                 bool has = HandleHintInPathTo((NonLeafNode)children[i], nodeName, hint);
                 // we find it at this hinted selector's child
                 if (has && root is HintedSelectorNode)
                 {
                     (root as HintedSelectorNode).Hinted(i, hint);
                 }
                 return true;
             }
             else if (children[i].NodeName == nodeName)
             {
                 // we find it at this hinted selector's child
                 if (root is HintedSelectorNode)
                 {
                     (root as HintedSelectorNode).Hinted(i, hint);
                 }
                 return true;
             }
         }
         return false;
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Search blackboard at parent
        /// </summary>
        private Blackboard FindParentBlackboard(NonLeafNode nonLeafNode)
        {
            if (nonLeafNode.Parent != null)
            {
                if (nonLeafNode.Parent.privateBlackboard != null)
                {
                    return nonLeafNode.Parent.privateBlackboard;
                }
                return FindParentBlackboard(nonLeafNode.Parent);
            }

            return null;
        }
Ejemplo n.º 3
0
 public HintedBehaviourTree CreateBT(NonLeafNode root)
 {
     return new HintedBehaviourTree(root);
 }
Ejemplo n.º 4
0
 internal HintedBehaviourTree(NonLeafNode root)
 {
     m_root = root;
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Completing the creation and allocate IDs
        /// </summary>
        public void Complete(NonLeafNode root, byte id = 1)
        {
            // bfs
            Queue<Node> nodeQueue = new Queue<Node>();
            byte l = 1;
            nodeQueue.Enqueue(root);
            while (l > 0)
            {
                Node node = nodeQueue.Dequeue();
                l -= 1;

                // allocate ids via bread-first-search
                node.ID = id;
                id += 1;

                if (node is NonLeafNode)
                {
                    NonLeafNode nonLeafNode = (node as NonLeafNode);

                    if (nonLeafNode is CompositeNode)
                    {
                        (nonLeafNode as CompositeNode).Complete();
                    }

                    // Client can set the parents also.
                    // nonLeafNode.blackboard.Parent = FindParentBlackboard(nonLeafNode);

                    int childNumber = nonLeafNode.Children.Length;
                    for (int i = 0; i < childNumber; i++)
                    {
                        nodeQueue.Enqueue(nonLeafNode.Children[i]);
                        l += 1;
                    }
                }
            }
        }