Decision Making Overview: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
m (Reverted edits by Jiff (talk) to last revision by Beeswax)
Tag: Rollback
 
Line 1: Line 1:
{{langsp|title=决策总览}}
From a high-level perspective, [[NPC]]s follow a fairly simple (and real-world logical) process for making decisions. The easiest way to understand it is to examine the basic outline first, and then dig further into the necessary exceptions afterwards.
从上层应用的角度来看,[[NPC]]遵循相当简单(并符合现实逻辑)的决策过程。 想要理解它,最简单的方式就是查看其大纲,之后再进一步挖掘必要的特例情况。


每一次NPC [[Think()|思考]], 都会遵照以下的过程:
Each time an NPC [[Think()|thinks]], it follows this routine:


;感知
;Perform Sensing
:[[NPC_Sensing|NPC感知]] 会产生一个NPC所能看到的实体列表, 以及一个它能够听到的声响列表。并且,NPC会忽略它不关心的实体与声响。
:[[NPC Sensing]] generates a list of entities that it can see, and another list of NPC sounds that it can hear. The NPC ignores entities and sounds that it doesn't care about.
;生成条件列表
;Generate a list of Conditions
:[[Condition|条件]] 是一串NPC用于做决策的关键信息。 它们提取于所感知到的实体、声响以及world与NPC的状态。列举一些可能的条件:
:[[Conditions]] are key pieces of information that the NPC will be using to make a decision. They are extracted from the sensed lists of entities & sounds, and from the state of the world and the NPC. Conditions might include:
:*我看见了敌人
:*I can see an enemy
:*我正承受伤害
:*I have taken some damage
:*弹夹已空
:*My weapon's clip is empty
;切换合适状态
;Choose an appropriate State
:[[State|状态]] 是基于<!-- global?-->条件列表总体评估的。例如:
:The [[State]] is the overall assessment of the NPC based upon the<!-- global?--> list of Conditions. For example:
:*NPC视野存在可见敌人时将进入''Combat''状态
:*NPCs with a visible enemy enter ''Combat''
:*NPC认为不存在敌人时将进入''Alert''状态
:*NPCs who have no enemies left will drop back to ''Alert''
:*NPC血量为0时将进入''Dead''状态
:*NPCs with a health of 0 would move to ''Dead''
;适时选择行程
;Select a new Schedule if appropriate
:[[Schedule|行程]]是NPC将采取的行动总和, 它被拆为多个任务(见下方)被NPC实际执行。 行程的选择基本取决于NPC的状态与条件. 例子如下:
:The [[Schedule]] is the overall action being taken by the NPC, which is then broken down into Tasks (see below) for the NPC to actually perform. Schedules are chosen based upon the NPC's current State and Conditions. Examples might include:
:*我将寻找掩护并换弹
:*I'm taking cover to reload my gun
:*我将追逐我的敌人
:*I'm chasing after my enemy
:*我将转移到能够看到敌人的位置
:*I'm moving to a position where I have line-of-sight to my enemy
:NPC切换到新行程的原因有两个:
:NPCs will choose a new schedule for one of two reasons:
:#完成了前一个行程
:#They finish performing their last schedule
:#产生了一个条件,而这个条件被这个行程指定为 [[Interrupt]]
:#They generate a condition that their current schedule has specified as an [[Interrupt]]
;执行当前任务
;Perform the current Task
:[[Task|任务]]是行程的组件,可称为离散动作。要想完成一个行程,任务必须一个接一个地执行。 例如, 行程 "我将寻找掩护并换弹" 将被拆为以下任务:
:The [[Task]] is a component of a Schedule that describes a discrete action. Tasks must be performed one by one for the schedule to be completed. For example, the "I'm taking cover to reload my gun" schedule would be broken down into the following tasks:
:#找到掩护点
:#Find a position to take cover at
:#产生到掩护点的路径
:#Generate a path to that position
:#沿着路径行走
:#Run the path
:#换弹
:#Reload my gun
:像上面的任务一样,许多任务都会花时间执行, 所以NPC每次思考都会不停地执行任务,直到该任务完成。 接着,它会执行当前行程的下一个任务, 或者,当没有任务剩余时会跳到下一个行程. 如果任务失败了,那么行程也会立即失败。(存疑) <!-- is this always true? -->
:Many tasks, like the one above, take time to perform, so the NPC will keep performing that task each time it thinks until the task is completed. Then, it'll move onto then next task in the current schedule, or pick a new schedule if there are no tasks left. If a task fails, the schedule fails. <!-- is this always true? -->


[[Category: AI]]
[[Category: AI]]

Latest revision as of 01:59, 26 June 2024

From a high-level perspective, NPCs follow a fairly simple (and real-world logical) process for making decisions. The easiest way to understand it is to examine the basic outline first, and then dig further into the necessary exceptions afterwards.

Each time an NPC thinks, it follows this routine:

Perform Sensing
NPC Sensing generates a list of entities that it can see, and another list of NPC sounds that it can hear. The NPC ignores entities and sounds that it doesn't care about.
Generate a list of Conditions
Conditions are key pieces of information that the NPC will be using to make a decision. They are extracted from the sensed lists of entities & sounds, and from the state of the world and the NPC. Conditions might include:
  • I can see an enemy
  • I have taken some damage
  • My weapon's clip is empty
Choose an appropriate State
The State is the overall assessment of the NPC based upon the list of Conditions. For example:
  • NPCs with a visible enemy enter Combat
  • NPCs who have no enemies left will drop back to Alert
  • NPCs with a health of 0 would move to Dead
Select a new Schedule if appropriate
The Schedule is the overall action being taken by the NPC, which is then broken down into Tasks (see below) for the NPC to actually perform. Schedules are chosen based upon the NPC's current State and Conditions. Examples might include:
  • I'm taking cover to reload my gun
  • I'm chasing after my enemy
  • I'm moving to a position where I have line-of-sight to my enemy
NPCs will choose a new schedule for one of two reasons:
  1. They finish performing their last schedule
  2. They generate a condition that their current schedule has specified as an Interrupt
Perform the current Task
The Task is a component of a Schedule that describes a discrete action. Tasks must be performed one by one for the schedule to be completed. For example, the "I'm taking cover to reload my gun" schedule would be broken down into the following tasks:
  1. Find a position to take cover at
  2. Generate a path to that position
  3. Run the path
  4. Reload my gun
Many tasks, like the one above, take time to perform, so the NPC will keep performing that task each time it thinks until the task is completed. Then, it'll move onto then next task in the current schedule, or pick a new schedule if there are no tasks left. If a task fails, the schedule fails.