游戏人工智能 - 行为树

问题描述 投票:0回答:2

如何为游戏制作强大的人工智能/脚本系统?

1) 对于所有 NPC/环境/实体,您是否为他们提供了一个单独的单一行为树(例如巡逻行为、盟友行为、供应商行为、门行为)?如果屏幕上有 500 个单元,我应该对树进行完整遍历(从根 -> 节点/操作)还是应该对所有单元进行 1 节点进度?

2) 我正在 update() 函数中执行 AI 逻辑...但我听说有些游戏有独立的 AI 线程,有什么想法吗?

3) 我想知道如何将我的游戏划分为部分/章节...我是否使用一个简单的变量(EVENT =“Mission 3”)来表示玩家的表现,并使其全部呈线性?然后利用上面树中的变量?

xna artificial-intelligence behavior-tree
2个回答
6
投票

我会尽力回答你的问题。

  1. 我在静态类中执行所有分支逻辑和行为树,例如:
     public static class Behavior
    {
        //Branch
        public static Action Selector(Func<bool> cond, Action ifTrue, Action ifFalse) {
            return () => { if (cond()) { ifTrue(); } else { ifFalse(); } };
            }
        public static Action Sequencer(Action a, Action b) {
              return () => { a(); b(); }
            }

        //Example trees
        public static Func<bool> ifPlayerIsInSight = () => { return true; /*...true iff WorldState shows guard can see player...*/};

        public static Action shootAtPlayer = () => { /*...aim guard's weapon at player and fire...*/ };

        public static Func<bool> ifUnderFire = () => { return true; /*...true iff WorldState shows guard hears player gunfire...*/};

        public static Action takeCover = () => { /*...guard runs for nearest shelter... */};

        public static Action walkBackAndForthGuardingDoorway = () => { /*...default guard patrol behaviour...*/ };

        public static Action patrollingGuardBehaviour =
          Selector(Behavior.ifPlayerIsInSight, Behavior.shootAtPlayer,
            Selector(Behavior.ifUnderFire, Behavior.takeCover,
              Behavior.walkBackAndForthGuardingDoorway));
    }
  1. 在 LateUpdate() 或最后执行此操作,这样它就不会滞后于主循环。

  2. 这取决于你。您可以在每个行为树中实现一个“状态”,或者将其拆分并管理在什么时间使用哪些行为。


0
投票
  1. 每个 NPC/Agent 都有自己的行为树。树被更新并且它“知道”从哪里继续,因此效率通常相当不错。
  2. AI可以在主线程中更新,也可以在单独的线程中更新。这取决于你。
  3. 这取决于您。

behaviac 是一个非常优秀的行为。

behaviac 支持行为树、有限状态机和分层任务网络。行为可以在设计器中设计和调试,由游戏导出和执行。

C++版本适用于客户端和服务器端。

而且,它是开源的!

© www.soinside.com 2019 - 2024. All rights reserved.