SlideShare una empresa de Scribd logo
1 de 56
Descargar para leer sin conexión
Behavior Tree AI

              AKara
       akaras@163.com
  http://blog.csdn.net/akara
  http://t.sina.com.cn/akaras
目录
•   常用方法
•   Behavior Tree
•   原理
•   进阶
•   应用
•   总结
前言
只关于:
• 环境中已具有完备的感知信息
• 决策式 AI:大量感知信息,做复杂决策



                 不涉及:
•怎么提供 感知信息?
     attr / code / XLS / AOI / FSM / search ...
•寻径
•学习
•...
• 常用方法
•   Behavior Tree
•   原理
•   进阶
•   应用
•   总结
if / else 神器
if visible:            优点:
   if close:            这个可以承受
        knife attack
   elif flank:         缺点:
        move
                        A:77倍可以承受不?
   else:
                        B:可以
        gun attack
                        A:...........
elif audible:
   creep
决策树 - Decision Tree




优点:单一,层次,自然…

缺点:过于单一,过于层次,过于自然…
有限状态机 - Finite State Machine
                关键字:
                关键字:
                • State
                • Transition(Ev/Con)

                经典设计: 1P + 3E
                • Precondition
                • Enter
                • Excute
                • Exit
States / Transitions?




       xaitControl
<<FSM Age is OVER>>
                     Alex.J.C
•   Unorthodox            •   Not Deliberative
•   Low-Level             •   Concurrency Nightmares
•   Logic is Limited      •   Scale Poorly
•   Require Extensions    •   Labor Intensive
•   Hard to Standardize   •   Industry is Moving On
http://aigamedev.com/open/articles/fsm-age-is-over/


难分解 / 低通用 / 难扩展 / 无层次 / 可预测 (FuSM)
分层有限状态机 - Hierarchical Finite State Machine




 关键字: SuperState
 关键字:
 <<Statecharts: A Visual Formalism for Complex Systems>> by D.Harel 1987
分层有限状态机 - Hierarchical Finite State Machine




其实它很好: Data driven, Probabilistic HFSM
理想的AI决策结构 ?
理想的AI
   AI决策结构
• 常用方法

• Behavior Tree
•   原理
•   进阶
•   应用
•   总结
Behavior Tree?
         Tree?
Google:行为树, behavior tree
Google:行为树
      :行为树,
GDC2005
Scalable decision-making BTs: Prioritized-list +
  Sequential + Seq-Looping + Probabilistic + One-off
V1.5 of Halo BT AI
Halo guys incredibly helpful and open with sharing
  detailed / pros / cons, this owes much to them.
GDC2007
We've spent 5 years living with BTs
And have learned how to optimize them
BTs are a GREAT tool for decision taking:
Easier to Use, More info, Less Resource,
Rapid iteration, Coordinating AI easily
800 NPCs full 24 hour schedules governing
their daily life , Each NPC is running a BT
— no dummy FSM's
Behavior Tree
• 2001: R.Geoff.Dromey 雏形

• 2003: Halo2使用(HFSM Like)

• 2005: Halo3改进

• 2006: Spore再改进

• 2007: Crysis / Crysis 2 协作式AI / BT Notation v1.0

• 2008-2009: AiGameDev (Alex.J.C) / MidWares / Libs

• 2010: Red Dead Redemption获BestNPC奖 / Halo: Reach
• 常用方法
• Behavior Tree

• 原理
• 进阶
• 应用
• 总结
初见BT:BOSS
       初见BT
         BT:
• 星期天,攻击男玩家;巡逻;巡逻一次原地休息每5分钟
4 种结点 + 1 个规则
• 行为结点 - Action Node

• 条件结点 - Condition Node

• 装饰结点 - Decorator Node

• 组合结点 - Composite Node

• 结点执行后,向 父结点 返回:
  成功(True)/失败(False)
(1) 行为结点




• def execute(self):
      calc 1 + 1
      return True
(2) 条件结点




• def execute(self):
      if 1 + 1 == 2: return True
(3) 装饰结点
• 结果取反 - Decorator NOT

• 次数限制 - Decorator Counter

• 强制循环 - Decorator Loop

• 时间限制 - Decorator Time

• GEEKS   - Decorator GEEKS

           AOP?
(3-1) 装饰结点 : 结果取反




• def execute(self):
    return not self.children[0].execute()
(3-2) 装饰结点 : 次数限制




•   def decorator(self):
         self.counter += 1
         return self.counter <= self.max_counter
•   def execute(self):
         if self.decorator(): return self.children[0].execute()
         else: return False
(3-3) 装饰结点 : GEEKS




• def decorator(self):
      print “GEEK”
      Animation? Sound? Log?
• def execute(self):
      self.decorator()
      return self.children[0].execute()
(4) 组合结点
• 选择结点 - Selector Node

• 顺序结点 - Sequence Node

• 平行结点 - Parallel Node
(4-1) 组合结点 : 选择




• def execute(self):
      for child in self.children:
            if child.execute(): return True
      return False
(4-2) 组合结点 : 顺序




• def execute(self):
      for child in self.children:
            if not child.execute(): return False
      return True
(4-3) 组合结点 : 平行




• def execute(self):
      for child in self.children:
            run child.execute()
      return True/False according to Policy
现在我们可以
•   顺序
•   选择
•   平行
•   循环
•   条件
•   时限
•   ……
回看:BOSS
        回看:BOSS
• 星期天,攻击男玩家;巡逻;巡逻一次原地休息每5分钟
决策依赖的数据在哪?
+可感知环境 : Blackboard
为何引入Blackboard?
    为何引入Blackboard
        Blackboard?
• 让Behavior Tree专注于决策执行

• 简化世界复杂性到Blackboard KV

• 易读取,易删改,易同步

• 叶结点间数据交互

• 使Behavior Tree与数据分离,甚至Dry-Run
• 常用方法
• Behavior Tree
• 原理

• 进阶
• 应用
• 总结
结点概率化
• 儿子结点均有Weight

• Probability结点先加权,再随机权重区间,执行
平行结点
   • FailPolicy
       – FAIL_ON_ALL
       – FAIL_ON_ONE
   • SuccPolicy
       – SUCC_ON_ALL
       – SUCC_ON_ONE
RUNNING态
RUNNING态
     • Action不一定瞬间完成!

     • 第三种返回
       – True/False
       – Running !

     • 记录当前访问子结点索引

     • 向上返回Running

     • 下次运行行为树时,保证
       跑到running结点
协作式AI(from Crysis)
协作式AI(from
•   常用方法
•   Behavior Tree
•   原理
•   进阶

• 应用
• 总结
举一个U3同学的栗子
      举一个U3
         U3同学的栗子
• AI需求:
1. 从A移动到B
2. 如果发现10码内有敌人,怒吼,然后攻击它
3. 如果没有发现敌人,坐下,然后睡觉。

• Unreal3的延迟函数
不厚道的对比
Unreal3 Script   Behavior Tree
• 写各个子函数         • 写各个Condition和Action
• 用延迟函数,写以下代码    • 无
  :


                 • (策划编写#_#)
掉落系统
飞机游戏
行为树编辑
1. 程序和策划一起讨论
需要什么节点

2. 程序写各种
Action/Condition

3. 策划输出xml
•   常用方法
•   Behavior Tree
•   原理
•   进阶
•   应用

• 总结
策划赐词
•   解放——解放程序&策划

•   易用——图形化优势

•   不足——编辑器不足

•   期待——学习型AI
优点

• 静态树 - Static Tree
 Halo2 -> Halo3 : - Stimulus + Masks


• 可复用 - Reusable
 内置结点(Com / Dec)给力,只编写外部结点(Con / Act)


• 可扩展 - Extendable
 内置 (WRandSel / WRandSeq / Probability…),外部(积累)
更重要的是
• 简单

• 直观

• 规范


• 流程优化
 以前:策划文档(xls),程序翻译(成就感=0),愤怒的QC (鸭梨大)
 现在:策划用BTE(所编即所玩);QC表示可以承受(Blackboard)
   程序前期——写condition/action
   程序后期——还要程序吗?
Q & A & Discuss
      Thx

Más contenido relacionado

Similar a Behavior+tree+ai lite

TensorFlow 深度學習快速上手班--深度學習
 TensorFlow 深度學習快速上手班--深度學習 TensorFlow 深度學習快速上手班--深度學習
TensorFlow 深度學習快速上手班--深度學習Mark Chang
 
深度學習(Deep learning)概論- 使用 SAS EM 實做
深度學習(Deep learning)概論- 使用 SAS EM 實做深度學習(Deep learning)概論- 使用 SAS EM 實做
深度學習(Deep learning)概論- 使用 SAS EM 實做SAS TW
 
[students AI workshop] Pytorch
[students AI workshop]  Pytorch[students AI workshop]  Pytorch
[students AI workshop] PytorchTzu-Wei Huang
 
2023 Decision Tree analysis in business practices
2023 Decision Tree analysis in business practices2023 Decision Tree analysis in business practices
2023 Decision Tree analysis in business practicesFEG
 
寫出高性能的服務與應用 那些你沒想過的事
寫出高性能的服務與應用 那些你沒想過的事寫出高性能的服務與應用 那些你沒想過的事
寫出高性能的服務與應用 那些你沒想過的事Chieh (Jack) Yu
 
A brief introduction to Machine Learning
A brief introduction to Machine LearningA brief introduction to Machine Learning
A brief introduction to Machine LearningWen-Tien Chang
 
2_學院碩士班_分類模型_20220523.pdf
2_學院碩士班_分類模型_20220523.pdf2_學院碩士班_分類模型_20220523.pdf
2_學院碩士班_分類模型_20220523.pdfFEG
 
【1110ROS社群開講】如何打造與人一起學習的機器檯燈_鄭凱文
【1110ROS社群開講】如何打造與人一起學習的機器檯燈_鄭凱文【1110ROS社群開講】如何打造與人一起學習的機器檯燈_鄭凱文
【1110ROS社群開講】如何打造與人一起學習的機器檯燈_鄭凱文MAKERPRO.cc
 
1到100000000 - 分布式大型网站的架构设计
1到100000000 - 分布式大型网站的架构设计1到100000000 - 分布式大型网站的架构设计
1到100000000 - 分布式大型网站的架构设计RolfZhang
 
模块一-Go语言特性.pdf
模块一-Go语言特性.pdf模块一-Go语言特性.pdf
模块一-Go语言特性.pdfczzz1
 
分布式Key Value Store漫谈
分布式Key Value Store漫谈分布式Key Value Store漫谈
分布式Key Value Store漫谈Tim Y
 
分布式Key-value漫谈
分布式Key-value漫谈分布式Key-value漫谈
分布式Key-value漫谈lovingprince58
 
我要活下來 - Ruby Junior 工程師的存活術
我要活下來 - Ruby Junior 工程師的存活術我要活下來 - Ruby Junior 工程師的存活術
我要活下來 - Ruby Junior 工程師的存活術Li Hsuan Hung
 
ElasticSearch Training#2 (advanced concepts)-ESCC#1
ElasticSearch Training#2 (advanced concepts)-ESCC#1ElasticSearch Training#2 (advanced concepts)-ESCC#1
ElasticSearch Training#2 (advanced concepts)-ESCC#1medcl
 
浅谈电商网站数据访问层(DAL)与 ORM 之适用性
浅谈电商网站数据访问层(DAL)与 ORM 之适用性浅谈电商网站数据访问层(DAL)与 ORM 之适用性
浅谈电商网站数据访问层(DAL)与 ORM 之适用性Xuefeng Zhang
 
# From statistics to ai
# From statistics to ai# From statistics to ai
# From statistics to aiTerence Huang
 
Introduction to big data
Introduction to big dataIntroduction to big data
Introduction to big data邦宇 叶
 
Linux binary Exploitation - Basic knowledge
Linux binary Exploitation - Basic knowledgeLinux binary Exploitation - Basic knowledge
Linux binary Exploitation - Basic knowledgeAngel Boy
 
Linux必备知识与Unix基础文化
Linux必备知识与Unix基础文化Linux必备知识与Unix基础文化
Linux必备知识与Unix基础文化Dahui Feng
 

Similar a Behavior+tree+ai lite (20)

TensorFlow 深度學習快速上手班--深度學習
 TensorFlow 深度學習快速上手班--深度學習 TensorFlow 深度學習快速上手班--深度學習
TensorFlow 深度學習快速上手班--深度學習
 
深度學習(Deep learning)概論- 使用 SAS EM 實做
深度學習(Deep learning)概論- 使用 SAS EM 實做深度學習(Deep learning)概論- 使用 SAS EM 實做
深度學習(Deep learning)概論- 使用 SAS EM 實做
 
Excel VBA
Excel VBAExcel VBA
Excel VBA
 
[students AI workshop] Pytorch
[students AI workshop]  Pytorch[students AI workshop]  Pytorch
[students AI workshop] Pytorch
 
2023 Decision Tree analysis in business practices
2023 Decision Tree analysis in business practices2023 Decision Tree analysis in business practices
2023 Decision Tree analysis in business practices
 
寫出高性能的服務與應用 那些你沒想過的事
寫出高性能的服務與應用 那些你沒想過的事寫出高性能的服務與應用 那些你沒想過的事
寫出高性能的服務與應用 那些你沒想過的事
 
A brief introduction to Machine Learning
A brief introduction to Machine LearningA brief introduction to Machine Learning
A brief introduction to Machine Learning
 
2_學院碩士班_分類模型_20220523.pdf
2_學院碩士班_分類模型_20220523.pdf2_學院碩士班_分類模型_20220523.pdf
2_學院碩士班_分類模型_20220523.pdf
 
【1110ROS社群開講】如何打造與人一起學習的機器檯燈_鄭凱文
【1110ROS社群開講】如何打造與人一起學習的機器檯燈_鄭凱文【1110ROS社群開講】如何打造與人一起學習的機器檯燈_鄭凱文
【1110ROS社群開講】如何打造與人一起學習的機器檯燈_鄭凱文
 
1到100000000 - 分布式大型网站的架构设计
1到100000000 - 分布式大型网站的架构设计1到100000000 - 分布式大型网站的架构设计
1到100000000 - 分布式大型网站的架构设计
 
模块一-Go语言特性.pdf
模块一-Go语言特性.pdf模块一-Go语言特性.pdf
模块一-Go语言特性.pdf
 
分布式Key Value Store漫谈
分布式Key Value Store漫谈分布式Key Value Store漫谈
分布式Key Value Store漫谈
 
分布式Key-value漫谈
分布式Key-value漫谈分布式Key-value漫谈
分布式Key-value漫谈
 
我要活下來 - Ruby Junior 工程師的存活術
我要活下來 - Ruby Junior 工程師的存活術我要活下來 - Ruby Junior 工程師的存活術
我要活下來 - Ruby Junior 工程師的存活術
 
ElasticSearch Training#2 (advanced concepts)-ESCC#1
ElasticSearch Training#2 (advanced concepts)-ESCC#1ElasticSearch Training#2 (advanced concepts)-ESCC#1
ElasticSearch Training#2 (advanced concepts)-ESCC#1
 
浅谈电商网站数据访问层(DAL)与 ORM 之适用性
浅谈电商网站数据访问层(DAL)与 ORM 之适用性浅谈电商网站数据访问层(DAL)与 ORM 之适用性
浅谈电商网站数据访问层(DAL)与 ORM 之适用性
 
# From statistics to ai
# From statistics to ai# From statistics to ai
# From statistics to ai
 
Introduction to big data
Introduction to big dataIntroduction to big data
Introduction to big data
 
Linux binary Exploitation - Basic knowledge
Linux binary Exploitation - Basic knowledgeLinux binary Exploitation - Basic knowledge
Linux binary Exploitation - Basic knowledge
 
Linux必备知识与Unix基础文化
Linux必备知识与Unix基础文化Linux必备知识与Unix基础文化
Linux必备知识与Unix基础文化
 

Más de 勇浩 赖

论 Python 与设计模式。
论 Python 与设计模式。论 Python 与设计模式。
论 Python 与设计模式。勇浩 赖
 
一种多屏时代的通用 web 应用架构
一种多屏时代的通用 web 应用架构一种多屏时代的通用 web 应用架构
一种多屏时代的通用 web 应用架构勇浩 赖
 
2012,我的技术之选
2012,我的技术之选2012,我的技术之选
2012,我的技术之选勇浩 赖
 
页游开发中的 Python 组件与模式
页游开发中的 Python 组件与模式页游开发中的 Python 组件与模式
页游开发中的 Python 组件与模式勇浩 赖
 
珠三角技术沙龙广州场
珠三角技术沙龙广州场珠三角技术沙龙广州场
珠三角技术沙龙广州场勇浩 赖
 
为什么 rust-lang 吸引我?
为什么 rust-lang 吸引我?为什么 rust-lang 吸引我?
为什么 rust-lang 吸引我?勇浩 赖
 
Python 于 webgame 的应用
Python 于 webgame 的应用Python 于 webgame 的应用
Python 于 webgame 的应用勇浩 赖
 
敏捷网游架构与性能的新玩法
敏捷网游架构与性能的新玩法敏捷网游架构与性能的新玩法
敏捷网游架构与性能的新玩法勇浩 赖
 
先用再学 - 借助 Xna 快速开发游戏原型
先用再学  - 借助 Xna 快速开发游戏原型先用再学  - 借助 Xna 快速开发游戏原型
先用再学 - 借助 Xna 快速开发游戏原型勇浩 赖
 
关于Bitworld的一些话题222
关于Bitworld的一些话题222关于Bitworld的一些话题222
关于Bitworld的一些话题222勇浩 赖
 
03 -黄朝兴--腾讯游戏
03 -黄朝兴--腾讯游戏03 -黄朝兴--腾讯游戏
03 -黄朝兴--腾讯游戏勇浩 赖
 
06 -甄焱琨--知识转化为资源
06 -甄焱琨--知识转化为资源06 -甄焱琨--知识转化为资源
06 -甄焱琨--知识转化为资源勇浩 赖
 
07 -林伟铃--成长中的36氪
07 -林伟铃--成长中的36氪07 -林伟铃--成长中的36氪
07 -林伟铃--成长中的36氪勇浩 赖
 
01 -阿朱--简单事情夯实做
01 -阿朱--简单事情夯实做01 -阿朱--简单事情夯实做
01 -阿朱--简单事情夯实做勇浩 赖
 
如何做好沙龙演讲
如何做好沙龙演讲如何做好沙龙演讲
如何做好沙龙演讲勇浩 赖
 

Más de 勇浩 赖 (20)

论 Python 与设计模式。
论 Python 与设计模式。论 Python 与设计模式。
论 Python 与设计模式。
 
一种多屏时代的通用 web 应用架构
一种多屏时代的通用 web 应用架构一种多屏时代的通用 web 应用架构
一种多屏时代的通用 web 应用架构
 
Tp web
Tp webTp web
Tp web
 
2012,我的技术之选
2012,我的技术之选2012,我的技术之选
2012,我的技术之选
 
页游开发中的 Python 组件与模式
页游开发中的 Python 组件与模式页游开发中的 Python 组件与模式
页游开发中的 Python 组件与模式
 
Scala
ScalaScala
Scala
 
珠三角技术沙龙广州场
珠三角技术沙龙广州场珠三角技术沙龙广州场
珠三角技术沙龙广州场
 
为什么 rust-lang 吸引我?
为什么 rust-lang 吸引我?为什么 rust-lang 吸引我?
为什么 rust-lang 吸引我?
 
Python 于 webgame 的应用
Python 于 webgame 的应用Python 于 webgame 的应用
Python 于 webgame 的应用
 
敏捷网游架构与性能的新玩法
敏捷网游架构与性能的新玩法敏捷网游架构与性能的新玩法
敏捷网游架构与性能的新玩法
 
先用再学 - 借助 Xna 快速开发游戏原型
先用再学  - 借助 Xna 快速开发游戏原型先用再学  - 借助 Xna 快速开发游戏原型
先用再学 - 借助 Xna 快速开发游戏原型
 
关于Bitworld的一些话题222
关于Bitworld的一些话题222关于Bitworld的一些话题222
关于Bitworld的一些话题222
 
Stekin
StekinStekin
Stekin
 
03 -黄朝兴--腾讯游戏
03 -黄朝兴--腾讯游戏03 -黄朝兴--腾讯游戏
03 -黄朝兴--腾讯游戏
 
abu.rpc intro
abu.rpc introabu.rpc intro
abu.rpc intro
 
06 -甄焱琨--知识转化为资源
06 -甄焱琨--知识转化为资源06 -甄焱琨--知识转化为资源
06 -甄焱琨--知识转化为资源
 
07 -林伟铃--成长中的36氪
07 -林伟铃--成长中的36氪07 -林伟铃--成长中的36氪
07 -林伟铃--成长中的36氪
 
01 -阿朱--简单事情夯实做
01 -阿朱--简单事情夯实做01 -阿朱--简单事情夯实做
01 -阿朱--简单事情夯实做
 
Python 温故
Python 温故Python 温故
Python 温故
 
如何做好沙龙演讲
如何做好沙龙演讲如何做好沙龙演讲
如何做好沙龙演讲
 

Behavior+tree+ai lite