Artificial Intelligence (AI) and Behavior Tree Design for MMORPG Games

What is the AI ​​of MMORPG?

  Everyone who plays MMORPG knows that the AI ​​of MMORPG is really mentally retarded. Even in a top-level game like WOW, AI is limited, and most of the NPCs are like a wooden stake. Even a well-designed BOSS only has some combat AI. Although many people call things like animation, or automatic pathfinding, AI, we're not going to discuss this basic function. The AI ​​we're talking about refers to AI that can make NPCs behave as if they were real people. An NPC with such AI looks no longer a model with only health bars and attack power, but will give the player the feeling of a life with belief, desire and intention. In a broader sense, if the entire game world is "high AI", then the game world will be full of degrees of freedom. This means that players can "create" in the game unprecedented weapons, technology and even have the ability to change the appearance and civilization of the entire game world. If such an MMORPG really appears, it should not be surprising to win the screams of fans. The project "Lost Continent", which is being conceived by the Quality Control Center, is currently working in this direction, hoping to achieve a certain level of breakthrough.

  AI system

  A typical AI system includes a three-word system of perception, navigation and decision-making. For games, the perception system can be "bi", without the need for NPCs to "perceive" the world, the system can directly tell the NPC what the world is like. The navigation system is not part of today's discussion. The decision-making system is what makes NPCs seem to have their own intentions and beliefs, so we will mainly discuss the decision-making system next.

Artificial Intelligence (AI) and Behavior Tree Design for MMORPG Games...


  Common models of AI decision-making systems At the

  earliest, game AI decision-making systems were often written like this:

  1. switch(self){
  2.   case "sufficient health":
  3.   Daguai();
  4.   break;
  5.   case "to die":
  6.   blood();
  7.   break;
  8.   case "dead":
  9.   Game global->Gameover();
  10.   break;
  11.   }
copy code

  With the improvement of hardware, the CPU time that can be allocated to AI for execution is getting longer and longer, and the bosses' requirements for AI naturally increase. For example, the boss may come up with such a strategy: when the HP is 80, use magic to make up one Just make up, eat a small blood bottle when your blood is 60, eat a big blood bottle when your blood is 40, and run away when your blood is 20.

  So AI programmers need to find the switch above, and then modify the case inside. Imagine that if you encounter a Dota master as the boss, you have all kinds of NB killing strategies in your heart, and you need to judge which strategy to use at any time according to the environment. When there are more and more strategies, soon, a function with tens of thousands of lines of code is born! If you encounter a bug at this time, let alone fix it, you will probably have to vomit just by reading this function. . .

  There is no doubt that the above method will crash the code when it encounters a large number of states, but after countless efforts of predecessors and predecessors, they have helped us to propose one method after another to simplify the code. At present, the common AI models include FSM (finite state machine, including HFSM hierarchical finite state machine) and Behavior Tree (behavior tree).

  FSM (Finite State Machine)

  Compared with switch-case, FSM programming is similar to human thinking, so it is easy to sort out and more flexible. When each state is encapsulated, there is no longer a "central" function to control all the logic, and each state only needs to take care of itself. Such a complex decision-making system is divided into two subsystems, different states and transitions between states. The complexity of the two subsystems after splitting is greatly simplified compared with the original system, which makes the code maintainable. FSM is used in quite a few games, and even Unreal Engine's scripting language directly supports state programming.

  FSM is very effective when the NPC decision-making in the game is not too complicated. For example, in the game Half-Life, the AI ​​in it has been praised by the industry for a long time, and the AI ​​in it is realized through FSM.

  Let's take a look at FSM through a simple example.

  For example, an AI text expression is as follows:

  1) The usual state is patrol

  2) If you encounter the enemy, look at the enemy

  3) If the enemy is weaker than you,   then

  attack

, and then programmatically implement

Artificial Intelligence (AI) and Behavior Tree Design for MMORPG Games...


  Nodes with borders represent states, while conditions on arrows represent conditions for state transitions.

  Although FSM is concise and similar to human intuitive thinking, FSM also has shortcomings:

  A) Since all we can do is edit the transition from one state to another, we cannot make higher-level mode functions, So we find ourselves building similar behaviors all the time, which takes most of our time.

  B) A lot of work is required to achieve goal-directed behavior using FSM. This is a big problem because most targeted AI needs to deal with long-term goals.

  C) FSM is difficult to concurrency. When running multiple state machines in parallel, it either deadlocks or we manually edit them to make sure they are compatible to some extent.

  D) The large-scale support is poor, and even the hierarchical finite state machine is difficult to scale on a large scale. They tend to have a chunk of logic code mixed in with them, rather than behavioral editing modularity.

  E) Implementing any design with FSM is a lot of work, takes a lot of designer time (not programming time), and even ends up being a source of bugs in behavior.

  Behavior Tree Behavior Tree

  is a model proposed in Next-Gen AI. Although it is Next-Gen AI, it has been about 10 years since its prototype was proposed. Among them, Spore (Spore), Crysis (Crysis) 2, Red Dead Redemption (Red Dead Redemption: Redemption), etc. use behavior trees as their AI models. And more and more engines have begun to directly support behavior trees, such as Cry Engine, Havok, etc.

  For an AI system constructed with a behavior tree model, each time AI is executed, the system will traverse the entire tree from the root node, the parent node will execute the child node, and after the child node is executed, the result will be returned to the parent node, and then the parent node will execute the child node according to the child node. The result of the node to decide what to do next.

  There are 5 common basic types of nodes in behavior trees (of course, more types can be extended):

  1) Sequence node (Sequence): It belongs to the combination node and executes the child nodes in sequence. As long as a child node returns false, it will stop executing and return false, otherwise it will return true, which is similar to the logical AND in the program.

  2) Selector: It belongs to the combination node and executes the child nodes in sequence. As long as a child node returns true, it will stop executing and return true, otherwise it will return false, which is similar to the logical OR in the program.

  3) Parallel Node (Parallel Node): provides the concept of parallel, no matter what the return value of the child node is, it will traverse all the child nodes. So there is no need to predict which Child Node should be placed in the front and which should be placed in the back like Selector/Sequence. While Parallel Node increases the convenience, it also increases the complexity of implementation and maintenance.

  4) Condition node (Condition): It belongs to the leaf node and judges whether the condition is established.

  5) Execution node (Action): belongs to the leaf node, executes the action, and generally returns true.

  Next, let's look at an AI constructed by a behavior tree. The logical text of this AI is that an NPC needs to perform patrol tasks at night. And if it rains, people outdoors need to use umbrellas.

Artificial Intelligence (AI) and Behavior Tree Design for MMORPG Games...


  The approximate flow of the program is as follows:

  1) The Basic_AI node is processed first. Since this node is a parallel node, the next two subtrees will be processed in turn, no matter what the return value of the first subtree is.

  2) For the "Umbrella" node, since the node is a sequential node, its child nodes will be processed in turn, but if a child node returns false, then the node execution stops and returns false. Therefore, whether the umbrella action will be executed depends on whether the two conditions in front of it return true

  . 3) After the "big umbrella" node is executed, the night watch node must be executed next, and the night watch node is the selection node, so either Perform night patrols, or will perform rest nodes. Whether the night patrol will have this name naturally depends on the return value of the conditional node "Is it night?" The

  behavior tree model seems simple, but the following advantages make the behavior tree become the mainstream model of complex AI.   The more complex the

   static

The more the function of the game requires a simple foundation, otherwise you will not be able to play by yourself in the end. even if the system requires some "dynamic" It should also try to use a static behavior tree to represent it. One of the improvements to BT AI that Halo3 has over Halo2 is the removal of some of the dynamics. The principle is to keep all Node static and just check if Node is enabled based on events and environment.

  The direct benefit of staticity is that the planning of the entire tree does not need to be dynamically adjusted at runtime, which greatly facilitates designers and programmers, and greatly reduces weird bugs. At the same time, it also brings convenience to many optimizations and pre-editing.

  B) Intuitiveness

  Behavior trees can easily organize complex AI knowledge items very intuitively.

  The default combination node's iterative way of processing child nodes is like processing a preset priority policy queue, which is also very consistent with the normal human thinking mode: the first is the best and the second is the best.

  In addition, behavior tree editors are readily available to good programmers.

  C) Reusability

  Various nodes, including leaf nodes, are highly reusable.

  D) Extensibility

  New composite nodes or decoration nodes can be easily tailored to the project. You can also accumulate a project-related node library, which is very valuable in the long run.

  Summary

  After going through Behavior Trees and Finite State Machines, it is natural to choose which model to use depending on the project. For projects where the AI ​​is not too complex, choosing a finite state machine is a very sensible behavior, especially if some engines support it. But if the NPC's state is very large, thousands of kinds, then the behavior tree may be a good way to avoid the final collapse of the project.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326977234&siteId=291194637