【问题标题】:AI, State Machine - how to expand a state machine to handle multiple monsters?AI,状态机——如何扩展一个状态机来处理多个怪物?
【发布时间】:2013-12-12 02:38:19
【问题描述】:

我正在阅读this excellent article on how to create a state machine for ai purposes。不幸的是,我无法理解如何扩展下面列出的状态机。此示例的伪代码似乎要求状态机针对当前状态执行操作:

do_stateless_ai(statemachine[action][currentstate]);

如果我需要实现多个怪物 AI,这意味着什么?

我是否要创建一个状态机实现,然后使用不同的状态表加载它,如下所示?

我是否为每个怪物编写了唯一的状态机?

如果我有多个怪物,我会创建一个巨大的状态表吗?对不起,如果这个问题看起来很业余,这是我第一次尝试实现 AI。

这里是文章中描述的人工智能状态表:

DRAGON AI(部分)

  State:  Obs: Action:          input L    input M    input H   NULL

  SLEEPING L   asleep-ai        WAKING:1              HUNGRY:1
  WAKING   C   none                        ENRAGED:1  HUNGRY:1  CURIOUS:1
  ENRAGED  C   typical-ai, p1                                   WAKING:1
  HUNGRY   C   typical-ai, p2              ENRAGED:1
  CURIOUS  A   curious-ai                  ENRAGED:1  HUNGRY:1  BORED:0.1

这是本机实现的伪代码:

acted = 0;
while (!acted)
{
    observe(statemachine[obs][currentstate]);
    shifted = 0;
    for (inputs=FIRSTINPUT; inputs < LASTINPUT && !shifted; inputs++)
    {
       if (input_is_true(input))
       {  /* note that what's stored in the statemachine is an expression, 
             not necessarily just a number. getshiftprob substitute in 
             values from the monster's extrinsic info and solves the expr.*/
          probshift = getshiftprob 
                 (statemachine[input][currentstate].probshift);
          if random() < probshift
          {
             currentstate = statemachine[input][currentstate].state;
             shifted = 1;
          }
       }
    }
    if statemachine[action][currentstate] != NULL
    {
       do_stateless_ai(statemachine[action][currentstate]);
       acted = 1;
    }      
}

【问题讨论】:

    标签: artificial-intelligence state-machine


    【解决方案1】:

    如果你使用一张巨大的桌子,那么你最终会得到一个巨大的 AI 直接控制一切。但是稍微考虑一下该表和实现会是什么样子,即使对于两个代理 - 考虑状态和观察的组合,以及即使对于两个或三个代理,该表会增长到多大。我想你会得出这样的结论:那是不可行的。它甚至可能是不可取的。

    如果您有多个表,那么您就有多个独立控制的代理,并且它们的大小更合理。对我来说,为什么您需要为每个代理提供独特的机器对我来说并不明显。即使您想要不同的行为,这意味着不同的表格,您仍然应该能够提出一些可以轻松个性化的通用基础架构。

    【讨论】:

      猜你喜欢
      • 2013-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-09-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多