【发布时间】: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