官术网_书友最值得收藏!

Finite State Machines (FSMs)

Finite State Machines (FSMs) are one of the simplest AI model forms and are commonly used in the majority of games. A state machine consists of a finite number of states that are connected in a graph by the transitions between them. A game entity starts with an initial state and then looks out for the events and rules that will trigger a transition to another state. A game entity can only be in exactly one state at any given time.

For example, let's take a look at an AI guard character in a typical shooting game. Its states could be as simple as patrolling, chasing, and shooting:

Simple FSM of an AI guard character

There are four components in a simple FSM:

  • States: This component defines a set of states that a game entity or an NPC can choose from (Patrol, Chase, and Shoot)
  • Transitions: This component defines relations between different states
  • Rules: This component is used to trigger a state transition (player on sight, close enough to attack, and lost/killed player)
  • Events: This is the component that will trigger to check the rules (guard's visible area, distance with the player, and so on)

So, a monster in Quake 2 might have the following states: standing, walking, running, dodging, attacking, idle, and searching.

FSMs are widely used in game AI because they are simple to implement and more than enough for both simple and somewhat complex games. Using simple if/else statements or switch statements, we can quickly implement an FSM. On the other hand, they can get messy when we start to have a lot of states and transitions. We'll look at how to manage a simple FSM in the next chapter.

主站蜘蛛池模板: 云梦县| 仙桃市| 台湾省| 高邮市| 罗平县| 济阳县| 延吉市| 五家渠市| 商河县| 四子王旗| 美姑县| 大连市| 黄骅市| 吉安县| 墨脱县| 寿阳县| 遂溪县| 墨竹工卡县| 桐乡市| 易门县| 黄大仙区| 大安市| 桦南县| 含山县| 天等县| 封开县| 会理县| 荔波县| 潮州市| 泰宁县| 五大连池市| 铜山县| 翼城县| 册亨县| 墨竹工卡县| 名山县| 自治县| 榕江县| 余干县| 高州市| 孝义市|