Long knowledge of games ------ game AI Based on Behavior tree and state machine (I), ------ ai

Source: Internet
Author: User

Long knowledge of games ------ game AI Based on Behavior tree and state machine (I), ------ ai

Sun Guangdong 2014.6.30


AI. Our first impression may be robots, which are mainly about applications in games.

Modern computer games have already incorporated a large number of AI elements. The interactions we make when playing games are done by AI. For example, the NPC appearing in RPG games is actually a carrier of AI. They have the most common judgment and data processing capabilities for specific scenarios. Judgment, also known as analysis. A large amount of analysis, that is, logic. Logic, that is, AI.

The most vivid example should be the attacking monsters in the game. When they see players (or are attacked by players, monsters may follow players within a specified range or period of time and attempt to fight back. However, when the player leaves the monster's field of view or exceeds the monster's tracking time, the monster will automatically return to the original place. When a player appears in the view of the same monster next time, the monster will still make the same action. However, this does not mean that monsters have the ability to remember, because they can only judge specific external Scenes Based on simple programs for corresponding processing. This is purely artificial intelligence based on digital storage devices and state machines. If we optimize it on this basis, the monsters will be able to remember: When we see players again, the monsters will be angry, and the attack capabilities will become stronger and more interesting, this is close to the emotional characteristics of humans.

Behavior Tree)

According to the features of the AI carrier described above, assuming that the amount of knowledge carried by an AI carrier is too large, it brings a lot of trouble to maintenance. Only if we want to implement a more intelligent AI carrier, a large knowledge base and behavioral characteristics are necessary.

The Behavior Tree is a prototype proposed by Next-Gen AI. It graphically shows the structure of the AI system. (1-1 ):


The above defines the basic AI behavior tree of ordinary game monsters. A tree contains a root node, a branch node, and a leaf node. You may have noticed that the behavior tree in the figure has nodes with different characteristics, and these nodes seem to be assembled into a tree based on certain rules.

Behavior Tree Nodes ):


· Selector: executes the subnode sequentially. If one of its subnodes returns true, true is returned for the entire branch. Otherwise, false is returned, similar to the logic OR (OR) in the program ).
· Sequence: if one of its subnodes returns false, the entire branch returns false, AND vice versa, similar to the logic AND (AND) in the program ).
· Condition: it is a leaf node that does not allow any subnodes. It is used to describe whether a Condition is true.
· Action: it is a leaf node (this node cannot have any subnodes) used to describe a final Action. Generally, true is returned.

Select a node (Selector). All the ordered nodes belong to the combined node. A combined node is a classification concept, not an instance of a node.

The monsters in the behavior tree have three actions: [attacking players], [patrol], and [self-defense]. These three actions do not refer to the final decisions of monsters, instead, Monsters may start from these three actions. The [Attacker] may have two methods. One of them is a [conventional attack] of ordered nodes. It must meet three conditions. Another [revenge attack], the difference is that there is an additional condition node [the monster is in a mad State].

By understanding the meaning of different nodes, you will find your ideas become clearer. All the features and logical directions of the entire tree are at your bottom. The traditional way of describing AI in words is not low-carbon, because a large number of words are not conducive to the team's understanding of planning ideas, but the relationship between conditions and actions can be clearly expressed through the behavior tree.

If the behavior tree is a good way for a unified team to understand consistency, how can this tree be implemented?

State Machine)

Many programmers may be quite familiar with the concept of state machines. Taking the above behavior tree as an example, it only describes the AI of a monster, but it involves many States. In traditional design ideas, when a player enters the view of a monster, the status of the monster will change immediately and attack the player actively.

State refers to some form of object, which may have different behaviors and attributes in the current form. A State Machine is a manager that controls the State of an object. The state of an object will not change without the end. It must be changed under certain conditions. For example, the [patrol] behavior defined in the behavior tree above sets the state of change only when the target cannot be found in the view of the monster. Once a player enters its field of view, it will immediately switch to the attack state. All in all, the status changes after an event is triggered. Different States may also determine different attributes and behaviors of objects.

Next-Gen AI's behavior tree is definitely a good thing. I believe that after the introduction above, we also know a little about the characteristics of the behavior tree. Enlightened readers may have realized that, since there is a behavior tree, does it mean that an auxiliary tool can be used to generate this tree and then embed it into a fixed AI framework, then, will the prototype of the game logic be automatically generated? This is completely possible. If the script mechanism is added on the basis of the behavior tree, the realization of game AI will be more flexible and clear.

The current AssetStore behavior tree plug-ins in Unity include:Behavior Designer,AI BehaviorBehaviour Machine Pro

The following State Machine plug-ins are available:Playmaker (INS that apply state machines) and many AI INS

References

AI Game Engine Programming-(us) Brian Schwab

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.