63
Behavior Tree Overview 아아아 : http://cafe.naver.com/architect1 아아아 : [email protected]

시작발표 - behavior tree

Embed Size (px)

Citation preview

Page 1: 시작발표 - behavior tree

Behavior Tree Overview

아꿈사 : http://cafe.naver.com/architect1김태우 : [email protected]

Page 2: 시작발표 - behavior tree
Page 3: 시작발표 - behavior tree

INDEX• Introduction

• FSM

• HFSM

• BTs

Page 4: 시작발표 - behavior tree

Introduction

Page 5: 시작발표 - behavior tree

Wish List

– Perfect designer supervision– AI behaves autonomously too

I want full

control...

...but not all the time!

Page 6: 시작발표 - behavior tree

Wish List

– Purposeful behaviors– Responds to events

The AI should be goal directed

...yet react to sudden

changes!

Page 7: 시작발표 - behavior tree
Page 8: 시작발표 - behavior tree

HierarchicalLogic

Page 9: 시작발표 - behavior tree

HFSM

PlannersHTN

ScriptingC++ Lua

Page 10: 시작발표 - behavior tree

Scripting: The Good

– Any computation possible– Widespread experience

I've done this for years!

Page 11: 시작발표 - behavior tree

Scripting: The Bad

– Difficult to introspect, analyze– Not accessible to many designers

What's planning?

Page 12: 시작발표 - behavior tree

HFSM: The Good

– Simple and intuitive– Full low-level reactive control

It's actually usable!

Page 13: 시작발표 - behavior tree

HFSM: The Bad

– Generally labor intensive– Not easy to build goal directed

It takes a lot of

work...

Page 14: 시작발표 - behavior tree

Planning: The Good

– Uses search for automation– Goal directed by default!

AI can solve many logic problems.

Page 15: 시작발표 - behavior tree

Planning: The Bad

– Integration of procedural code– Ignores control & execution

It's disconnected from the real

world?

Page 16: 시작발표 - behavior tree

HFSM

PlannersHTN

ScriptingC++ Lua

Page 17: 시작발표 - behavior tree

intuitivereactive

autonomouspurposeful

integratedflexible

Behavior Trees

Page 18: 시작발표 - behavior tree

Bang for Buck!

– Decision making over time– Control & monitoring execution

Page 19: 시작발표 - behavior tree

FSM

Page 20: 시작발표 - behavior tree

Abstract– 이론적으로 , FSM은  logic의 명확한 형태를 제공 – 실용적으로도 , FSM은 해결하려는 문제에 유용– A blessing and a curse

•처음엔 간단히 시작하지만 , •규모가 커지게 되면 문제가 생긴다

Page 21: 시작발표 - behavior tree

What is state?• FSM은  state라는 개념에 기반하는데 ,

state는  2 가지로 구성된다– Set of actions at the same time

•애니메이션 , 사운드 , 약간의 대기

– Set of transitions with conditional check•다음  state으로 언제 넘어갈 지를 결정

• State들은 정말  generic하고  robust하게 

만들어 질 수 있다 .– 간단한 문제에 관해서는 좋은 편이다 . – 커다란 문제에 관해서는 더욱 확장성 있는 접근법이 필요하다 .

Page 22: 시작발표 - behavior tree

Idle CombatSelf-

preservation

Search

Flight

Page 23: 시작발표 - behavior tree

Idle CombatSelf-

preservation

Search

Flight

Page 24: 시작발표 - behavior tree

HFSM

Page 25: 시작발표 - behavior tree

Abstract• HFSM은 재사용 가능한 로직에 대한 약간의 도움을 제공 

•디자인 절차는  non-HFSM과 매우 유사– state마다 로직을 구축한다 . transition들로 

state들을  bottom up식으로 연결한다 . – 새로운  state들을 생성하는 동안 , transition들을 공유하기 위해  state들을 그룹화 한다 .

•이렇게 하면 , transition logic의 중복을 간단히 피할 수 있다 .

Page 26: 시작발표 - behavior tree

Super-States and Generalized Transitions

• Super-States == Groups of States

•이  super-states 역시  transition들을 소유이론적으로 중복 전이를 예방 가능– 전이를 각 상태 마다 개별적으로 적용시키지 말고 ,

super-states에 한 번만 적용시킴 – 이것을  generalized transitions라고 부름

• state들은 전형적으로 하나의  super-state에포함되어 , 폴더처럼 엄격한 계층을 가지게 됨

Page 27: 시작발표 - behavior tree

Behavior Trees

Page 28: 시작발표 - behavior tree

Abstract•게임 AI의 주 목적 중 하나는 로직을 편집하기 위해 간단하고 확장성있는 솔루션을 찾는 것 

• FSM– 장점 : 정말 간단하다– 단점 : 큰 시스템에서는  state들 간에 재사용 가능한 

transition들을 제공하기 위해 HFSM이 필요함• HFSM

– 장점 : 확장성 있는 로직을 만드는데 분명히 유용– 단점 : state들에 대해 어떤 모듈성도 제공하지 않음

•다양한 목적과 상황에 대한 로직을 제공하기 위해 state들을 재사용할 수 없음 

Page 29: 시작발표 - behavior tree

State of Behaviors • state들의 모듈성을 증가 

– encapsulating logic transparently

• state들이 독립 (self-contained) 되도록– state들에 대한  transition들을 제거

• No more 'states‘– 'transitions'가 없기 때문– 단지 실행하고 종료하는 

behaviors 또는  action의 집합이 됨

Page 30: 시작발표 - behavior tree

A Programming Analogy •어떻게  behavior들을 차례로 배열할까 ?

– 각 연산은  successor에 대한 포인터 없음

– 대신에 , 연산들은  parent scope에서 삽입됨그리고 , parent scope의 의미에 따라 실행됨 

– 연산 간의  transition들은 자동적으로 정의됨

Page 31: 시작발표 - behavior tree

Why Behavior Trees Work • BTs가 확장성 있게 구현된다면 매우 강력

– sequences와  selectors 같은 표준 합성의 제공

– custom decorators를 섞어 넣음

• sequences와  selectors의 간단한  BT를 FSM으로 변환 가능– FSM

•   개별적인  transition들에서 더 많은 제어를 제공

– BT•   로직이 모듈적이고 재사용이 쉽도록 만듬

Page 32: 시작발표 - behavior tree

BehaviorTrees

Page 33: 시작발표 - behavior tree

A Guard Dog's AI

Woof

Page 34: 시작발표 - behavior tree

patrol investigate attack

look aroundmove bite

Example

recursive decomposition

Page 35: 시작발표 - behavior tree

Leaves

– interface between AI and engine

Page 36: 시작발표 - behavior tree

Conditions

– actor state, meta-checks– collision, entity queries

Page 37: 시작발표 - behavior tree

Actions

– animation, sound– using objects, game logic

Page 38: 시작발표 - behavior tree

It's All About Tasks

– Latent computation– Succeed or Fail

Condition ActionCondition

Task

Page 39: 시작발표 - behavior tree

Building Complexity

branches manage the leaves

done using composite tasks

Page 40: 시작발표 - behavior tree

Sequences

keep going

bail out

Page 41: 시작발표 - behavior tree

Selectors

terminate

keep trying

Page 42: 시작발표 - behavior tree

Dynamic Behavior as Search

Page 43: 시작발표 - behavior tree

Behavior Language

– Standard & high-level composite tasks– Rather than custom low-level logic

So I implement concepts once, and

reuse them everywhere?

Page 44: 시작발표 - behavior tree

In Practice

Page 45: 시작발표 - behavior tree

Improving Your HFSM

Does this help me with my

state machine?

Page 46: 시작발표 - behavior tree

Improving Your HFSM– make it easy to build sequences– no need to (re)wire transitions– easier to build purposeful behaviors

Page 47: 시작발표 - behavior tree

Design Principles

That gives me some guidelines

to follow for editing all those

transitions!

Page 48: 시작발표 - behavior tree

Improving Your Scripts

How does that help me

with my scripts?

Page 49: 시작발표 - behavior tree

Improving Your Scripts– provide better dynamic error handling– by making it easy to build selectors

Page 50: 시작발표 - behavior tree

Software Patterns

It'll help me think about my scripts

on a higher-level.

Page 51: 시작발표 - behavior tree

Scalability

Page 52: 시작발표 - behavior tree

Remove Bottlenecks

– Custom logic takes time to code up..– Also much more likely to cause bugs

? ?Lua /FSM

Page 53: 시작발표 - behavior tree

Embrace Design Patterns– find common patterns– implement them as high-level tasks– it's much simpler and intuitive– helps designers mix and match

Page 54: 시작발표 - behavior tree

Decorator Tasks

“In object-oriented programming, the decorator pattern allows additional behavior to be added to an existing

method of an object without modifying the original code.”

original task

decorator filter

Page 55: 시작발표 - behavior tree

Decorating a Behavior

Bark,

woof pause wuf

multiple times,

ignoring voice failures,

no more often than every x seconds.

at most n times in total,

timer

counter

loop

wrapper

Page 56: 시작발표 - behavior tree

Incremental Development

– it's a modular script interpreter

These decorators can be

implemented as they are required.

Page 57: 시작발표 - behavior tree

Summary

Page 58: 시작발표 - behavior tree

HFSM

PlannersHTN

ScriptingC++ Lua

BT

Page 59: 시작발표 - behavior tree

intuitivereactive

autonomouspurposeful

integratedflexible

BT

tree editor

stacklanguage

full planning

Page 60: 시작발표 - behavior tree

That's All Folks!

Page 61: 시작발표 - behavior tree

References• AIGameDev

– http://aigamedev.com/open/articles/bt-overview/

• The Artificial Intelligence of Halo 2– http://electronics.howstuffworks.com/halo2-ai.htm

• Halo2 AI and Blah Blah– http://www.naimadgames.com/publications/gdc05/

gdc05.ppt

Page 62: 시작발표 - behavior tree
Page 63: 시작발표 - behavior tree

Lisence