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

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.

主站蜘蛛池模板: 邳州市| 汶川县| 策勒县| 商河县| 苍山县| 丽水市| 琼中| 工布江达县| 澳门| 两当县| 蒙山县| 襄垣县| 德清县| 潼关县| 棋牌| 汉川市| 高雄县| 壤塘县| 纳雍县| 阳曲县| 安阳市| 潞西市| 永清县| 安徽省| 磐安县| 盱眙县| 威海市| 新乡县| 庆元县| 辛集市| 开鲁县| 志丹县| 漾濞| 望奎县| 永胜县| 建水县| 南昌县| 夏津县| 余江县| 聂荣县| 绥中县|