The difference between FSM (state machine), HFSM (layered state machine), BT (Behavior tree)

Source: Internet
Author: User
Tags fsm

The most commonly heard in game Ai Ai is the three-word pull:

Fsm

This needless to say pull, Baidu a lot of explanations,

The simple will be to divide the game AI behavior into one state, the transition between state and state is formed by triggering the event.

For example, the soldier's behavior has " patrol ", " pursues the enemy ", " attacks the enemy ", " escapes " and so on behavior,

In response to the event there are " discover the Enemy ", " catch the Enemy ", " enemy Escape ", " enemy Death ", " their own insufficient blood " and so on.

Then you can write a state machine like this:

1. Soldiers " patrol ", if " find the Enemy ", then, " hit the Enemy "

2. Soldiers "Chasing the enemy ", if " catch the Enemy", then, " attack the enemy "

3. Soldiers " chasing the enemy ", if " enemy Death ", then continue to " patrol "

4. Soldiers " attack the enemy ", if " enemy Death ", then continue to " patrol "

5. Soldiers " attack the enemy ", if " insufficient blood ", then, " escape "

Where the soldier is the executor of the FSM, the red is the state , the blue is the event ,

The behavior of the entire state machine can be summed up as:

Current status = = Whether the condition 1 is met, and if so, jumps to the corresponding state

Otherwise, = whether the condition 2 is satisfied, if it is, jumps to the corresponding state

It can be seen that the state machine is an "event-triggered" AI, that is, only the triggering of the event will cause a change in state.

Hfsm

In short, it is FSM when the state is too many times, not good maintenance, so the state classification, pull out, will be the same type of

The state is made as a state machine, and then a large state machine is made to maintain these sub-state machines .

To give an example of a decision-making puppy behavior:

We have defined a lot of behaviors for puppies, such as running, eating, sleeping, growling, spoiled, wagging tails and so on, if every action is a state,

With the conventional state machine, we need to define jumps between these states, for example, in the "Run" state, if tired, then jump to "sleep" state,

Again, in the "spoiled" state, if you feel threatened, then jump to the "roaring" state and so on, we will consider the relationship between each state, determined

All the jump links to create such a state machine. If we use a hierarchical state machine, we will first "classify" these behaviors and put a few small

To a state, and then define a jump link to a small internal state within a high-level state and a high-level state.

In fact, hierarchical state machine to a certain extent, is to limit the state machine jump, and state of the state is not to care about the external state of the jump,

This also does the isolation between unrelated states, for example, for puppies, we can define the state of the puppy as fatigue, happy, angry, and then these

State to define a small state , such as in a happy state, there is a bridge, wagging the tail and other small States, so that we only need to care about the outside of the three state jump

Turn (tired, happy, angry), in each state of the internal only need to care about their own small state of jump on it can be. This greatly reduces the complexity of the state machine,

In addition, you can define more state hierarchies to reduce the number of jump links if you feel that there are too many states on the two-tier state machine.

(Excerpt from this article)

Behavir Tree

Have time to update, first read the previous article: http://www.cnblogs.com/jeason1997/p/4803243.html

Unlike an FSM, a behavior tree is a "polling mechanism" in which each update traverses the tree, determines whether the logic is established, and whether it should continue to execute.

The difference between FSM (state machine), HFSM (layered state machine), BT (Behavior tree)

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.