Using the behavior tree (Behavior trees) to implement game AI

Source: Internet
Author: User

 using the behavior tree (Behavior trees) to implement game AI

Note: This article is copyright CSDN Akara All, here is purely reproduced, if you re-turn, please strictly according to the following way to display the original author and source, to show respect!!

Original topic: Using the behavior tree (Behavior trees) to implement game AI
Original Akara

Release Date: 2010-12-09

Author Bolg:http://blog.csdn.net/akara

Original source: http://blog.csdn.net/akara/archive/2010/12/19/6084786.aspx

Contact information: [email protected]

---------------------------------------------------------------------

When it comes to game AI, it is clear that the more knowledge items a smart body has, the more intelligent it becomes, but the maintenance
A huge number of knowledge items is a nightmare: using finite state machines (FSM), layered finite state machines (HFSM),
Decision Trees (decision tree) to achieve game AI always have a few.

Try Next-gen Ai's behavior tree (Behavior).

Although Next-gen AI, it has been proposed for about 10 years from its prototype, and the Microsoft Halo series estimates
It has been used for more than 8 years, and Spore and some famous games have already used the behavior tree as their AI structure.
If never contacted, that Wikipedia (Http://en.wikipedia.org/wiki/Behavior_Trees)
It's definitely a good source of entry.

---------------------------------------------------------------------

First to post the most valuable picture (color can take a lot of time)




For the appearance: BT was horizontally placed, node level was deliberately reduced, Dec was deliberately planted, cond was deliberately fabricated.
PS: In fact, the real efficient node group culling should add a layer of sequence node.

---------------------------------------------------------------------

The Behavior tree (Behavior trees) has the following characteristics:

It has only 4 major types of node:
* Composite Node
* Decorator Node
* Condition Node
* Action Node

After any node is executed, the execution result must be reported to its parent node: Success/failure.
This simple success/failure reporting principle is cleverly used to control the direction of decision-making throughout a tree.

---------------------------------------------------------------------

First look at composite Node, in fact, it can be subdivided into 3 kinds of composite properties:
* Selector Node
When this type of node is executed, it executes its own child node from begin to end iteration:
If a child node is encountered after execution returns true, that stops the iteration,
This node also returns true to its parent node, otherwise all child node returns false,
The node returns false to its parent node.

* Sequence Node
When this type of node is executed, it executes its own child node from begin to end iteration:
If you encounter a child node that returns false after execution, that stops the iteration,
This node also returns false to its parent node, otherwise all child node returns TRUE.
That this node returns true to its parent node.

* Parallel Node
Executes all of its child Node concurrently.
The value returned to parent node is related to the specific policy taken by parallel node:
Parallel Selector Node: A false returns false, full true to return true.
Parallel Sequence Node: One True returns True, full false to return false.
Parallel hybird node: The specified number of child node returns TRUE or False before the result is determined.

Parallel node provides concurrency and improves performance.
It is not necessary to pre-convict which child node should be placed before, as Selector/sequence,
Common scenarios are:
(1) For parallel multiple action subtree.
(2) Hang a subtrees tree under parallel node and hang multiple condition node,
To provide real-time and performance.
Parallel node adds performance and convenience while also increasing the complexity of implementation and maintenance.


PS: The above selector/sequence is accurate Liner selector/liner Sequence.
AI terminology is called Strictly-order: iteration in a given sequence of priorities.

Selector and sequence can further provide weighted random variants of nonlinear iterations.
Weight Random Selector provides the possibility of executing different first True child node each time.
The Weight Random sequence provides a different sequence of iterations each time.
Ai terminology, known as Partial-order, allows AI to avoid the total occurrence of predictable results.

---------------------------------------------------------------------

Looking at decorator node again, it functions as it literally means: it will execute its child node
After the returned result value is processed extra, it is returned to its parent Node. It's a bit of an AOP flavor.

For example Decorator not/decorator failutil/decorator counter/decorator time ...
More geek have Decorator log/decorator ani/decorator nothing ...

---------------------------------------------------------------------

It is then straightforward to condition Node, which returns true only if condition is satisfied.

---------------------------------------------------------------------

Finally look at Action Node, which completes the specific one (or step) behavior, depending on the demand return value.
When the behavior needs to be divided between step/node, Blackboard can be introduced to make simple data interaction.

---------------------------------------------------------------------

In the entire behavior tree, only condition node and action node can be leaf node, and
The only leaf node is the Node;composite node and decorator node that require special customization.
Used to control the direction of decisions in the behavior tree. (So some of the information is also referred to as condition node and action
node is behavior node, while composite node and decorator node are decider node. )

More powerful is the ability to join stimulus and impulse, precondition to determine the masks switch.

Almost all of the decision control can be achieved through the various nodes mentioned above: If, while, and, or,
Not, counter, time, random, weight random, util ...

---------------------------------------------------------------------

In general, the behavior tree has the following advantages, is really a tool to implement the AI framework, or even a
A versatile and maintainable complex process management tool:

> Static
The more complex the function the more needs the simple foundation, otherwise finally even oneself can not play over.

Static is a key point to using the behavior tree: Even if the system requires some "dynamic" nature.

In fact, the dynamic placement of node such as stimulus seems powerful,
But it destroys the static nature which is easy to understand, and does more harm than benefit.
One of the improvements to BT AI in Halo3 versus Halo2 is to remove the dynamics of stimulus.
Instead, use behavior Masks,encounter attitude,inhibitions.
The principle is to keep all node static, just to check if node is enabled based on the event and environment.

The immediate benefit of static is that the entire tree is planned to be dynamically adjusted when it is no longer operational, for many optimizations
and pre-editing are easy to bring.

> Intuitive
The behavior tree makes it easy to organize complex AI knowledge items very intuitively.
The default composite node iteration of child node from begin to end is like processing a
Pre-prioritized strategy queues are also very much in line with the normal thinking patterns of humans: first, best again.

The Behavior Tree Editor is also handy for good programmers.

> Re-usability
A variety of node, including leaf node, is highly reusable.
The personality difference of the NPC AI can even be achieved by a different location in a common behavior tree.
Placement of impulse to achieve the goal.

Of course, when NPC requires a completely different brain, such as a 70-level boss,
Instead of racking your brains in a common BT placement impulse, you might as well design a dedicated BT.

> Scalability
While the combination and collocation of the above node covers almost all AI requirements.
But it's also easy to tailor the new composite node or decorator node to the project.
You can also accumulate a project-related node Lib, which is valuable in the long run.

---------------------------------------------------------------------

Using the behavior tree (Behavior trees) to implement game AI

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.