Go Behavour TREE2

Source: Internet
Author: User

The last mention of some of the basic concepts of behavior trees, including behavior nodes, control nodes (selection, sequence, parallel), this time come more, more in-depth discussion of some things in the behavior tree, if the behavior tree is not very understanding, please see here.

I. Discussion on selection of nodes

We said that the definition of the choice node is to select a node execution by judging the precondition of the child node, which involves the question of the Order of judgment, from left to right, or random selection, or some other rules, etc., thus extending a variety of selection nodes.

    • Select node with priority Selector: This selection node is selected each time from left to right, and then stops searching for subsequent child nodes after finding an executable child node. This way of choosing, there is a priority problem, that is, the leftmost node has the highest priority, because it is the first to be judged. For this choice of nodes, its child nodes of the premise set, must be "from narrow to wide" way, otherwise the subsequent nodes will be "starved" situation, that is never to be executed to, in order to more clearly explain, see the first picture below, these three sub-nodes in a priority selection node , their premises will be judged sequentially, you can see the premise of this three sub-node from left to right, a more strict than a, if we now a is 9, according to the definition will execute the first child node, if a is 7, then the second child node will be executed, if a=11, then the third child node will be executed. The second diagram below shows a node "starved" (starvation), we see the premise of the first child node, more broadly than the second child node, as long as the a<10, that from left to right judgment, will always enter the first node, so, if you want to use the priority of the selection node , you must check the premises of each child node to prevent the node from starving to death.

    • selection node without priority (Non-priority Selector): The selection order of this selection node is selected from the last child node that was executed, and if the precondition is met, the node is resumed, and if the condition is not met, the node begins The premise of each child node is determined in turn, and when a child node satisfies the condition is found, the node is executed. This approach is based on a hypothesis called "persistence", because in the game, a behavior is generally not end in a frame, but it will last for a period of time, so sometimes for the purpose of optimization, we can prioritize the previous execution of the node, when its condition is not satisfied, and then look for the next executable node. This search method does not exist which node is the first to judge the problem, so the premise of the setting requirements, is to ensure "mutual exclusion" (exclusion). If we use the first diagram above to illustrate, if we change the control node to a choice node without priority , we can see that when a=3, the second child node will be executed, the next time a becomes 9 o'clock, because it is not from the beginning to judge the premise, so we will still choose the second node, Rather than the first node we might expect. In the right way, note that the premise of each sub-node is "mutually exclusive". So for a selection node without a priority, the order of its child nodes is not so important that it can be arranged arbitrarily.

    • selection node with weights (Weighted Selector): For this selection node, we will pre-label each branch a "weight" (Weight value), and then when we choose, random selection of the way to choose, Random will refer to the weights, and ensure that the nodes that have been tested will not be tested again until the premise of a node is satisfied, or all nodes are tested. the choice node with weights for the sub-node premise due to the existence of random, so the premise of the child node can be arbitrary, without the "starved" situation, generally speaking, we usually set the premise of the child node is the same, in order to better show the weight of the probability of the effect of the result. When the weights of all the child nodes are the same, this choice node becomes the random selection node (randomly Selector), and the selection node with weights is very suitable for the place where the AI behavior needs to be enriched, such as the formation of the game, the puppy is happy, There may be a variety of performance, we can use this choice node, add a variety of child node behavior to achieve.

These are the common choice of node types, we can define more choice of node selection behavior as needed, in fact, we can see that the different choice behavior for the sub-node premise requirements will be slightly different, this is the time we build the behavior tree need to pay attention to the place.

Two. Discussion on the end condition of parallel nodes

Each of our nodes will have a running state to indicate whether the current behavior is over. For the control node, its running state is the running state of its child nodes, the selection node and the sequence node is better handled, because for the two control nodes, every moment, only one child node is running, as long as the state of the child node running is returned. But for a parallel node, it will have more than one node running at a time, so how can we handle the running state of the parallel node? There are generally two kinds:

    • With: Only all child nodes are run to the end before the end is returned.
    • Or: The end is returned as soon as a child node is run.

Why do you need to have a node running state?

    • In the Sequence control node, it is necessary to use the running state to control the execution of the sequence
    • The outside world needs to understand the operational state of the behavior to decide whether to update the decision (if the behavior tree is at the decision-making level)/request (if the behavior tree is in the behavior layer), refer to the AI hierarchy here

For the 2nd, for example, we have a behavior is "go to a point", assuming that the behavior is not interrupted, when we go to point A, the behavior of the tree is "executing", when reaching point A, the behavior tree will return to "completed", so, for the outside, When we see that the behavior tree is "executing", we do not need to do anything new (for optimization, or for behavior jitter, etc.) and when we see "done" we can make new decisions or actions. Such a running state also helps us to detect the state of the behavior tree and help with debugging.

Three. Discussion on concrete implementation

The implementation of the behavior tree can be varied, and here are some suggestions, in general, the behavior tree each node needs to have enter (enter), leave (exit), run (Execute) and other parts, need to have the behavior node (actionnode), Control node (controlnode) , the premise (precondition) and other base classes, then, also need to define the behavior tree input (Inputparam) and output (Outputparam), in general, we want the behavior tree is a black box, that is, it depends only on the predefined input. The input can be a data structure such as a blackboard (Blackboard), a working pool (working Memory), and so on, the output can be request, or other custom data structures, such as:

Code words, do not write, because the blog does not have code plug-ins, write code effect is not very good, later I will publish a behavior tree in the Tsiu version of the library.

Four. Discussion on drawing and commissioning

After seeing the definition of the behavior tree, as a programmer's intuition, we naturally think that it should be possible to do a tool to assist the creation and debugging of the behavior tree, we can put the pre-defined premise and node, in a visual editor built into the behavior tree, and then exported to the game with the data. For debugging, we can let the tool and the game communicate, and then real-time detection of the behavior of the tree's health, such as the current in which branch and so on. Because the logic of the behavior tree is visible and static, so we look at the path of its choice, we can see why the AI makes such a decision. When I first approached the behavior tree, I wanted to do such an editor, but under the pressure of the project, have no time to do (the workload is quite large), interested, have time friends, can consider to do one. By the way, I am now the construction of the behavior tree is done in the code, although no data-driven so "advanced", but through the macro definition, typesetting and other ways, or can be very clear representation of the overall structure of the tree.

About the behavior tree, I think this series is here. In the process of using the behavior tree, may also encounter such and such problems, including my own experience in the practice, I think it is not included in this series, and then alone to come out to chat, this series as the introduction of the behavior tree, I hope to be helpful to everyone, welcome advice and discussion.

————————————————————————
Finney
Blog:ai Sharing Station (http://www.aisharing.com/)
Email:[email protected]
This article welcomes the reprint and quote, please retain this note and indicate the source
————————————————————————

9

Go Behavour TREE2

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.