220 likes | 331 Views
Lecture 24 – Decision Making. CS 490/590 Wesley Kerr. Quiz. On a piece of paper – no computers write code to complete the following task: Write a program that prints the numbers from 1 to 100. For multiples of five print “Fizz” instead of the number
E N D
Lecture 24 – Decision Making CS 490/590 Wesley Kerr
Quiz • On a piece of paper – no computers write code to complete the following task: • Write a program that prints the numbers from 1 to 100. • For multiples of five print “Fizz” instead of the number • For multiples of seven print “Buzz” instead of the number • For multiples of five and seven print “FizzBuzz” • You have 10 minutes.
Review • Decision Trees • State Machines • Hierarchical State Machines • Goal-Driven Behavior • Planning • Rule-Based Systems • And all combinations…
Behavior Trees ? ? ? ? S P S S
Motivations • Bigger environments • Greater numbers of entities • More accurate physics • Better sensory systems • Advanced animation
Acknowledgements • Alex J. Champanard, AIGameDev.com • We are using his notation for behavior trees • Some slides based on is Behavior Tree talks
Requirements • Designers • They want to micro manage every decision in the game • This allows them to put their own touch on each situation • Also allows them to create cinematic experiences • …but they don’t want to do all of their work on their own • The AI needs to behave autonomously as well • AI • Should be goal directed • They each need to have personal motivations • These motivations manifest themselves as purposeful behaviors • …but also able to respond to events • Reactive when the situation demands it.
Holy Trinity HFSM Good: Simple and intuitive Low-level reactive control Bad: Labor intensive Not easy to build goal-directed behavior Scripting C++/Lua/Ruby Planner (HTN) Good: Turing complete Widespread experience Bad: Difficult to analyze Not accessible to designers Good: Use search for automation Goal directed by default Bad: Disconnected from real world Ignores control and execution
Holy Trinity HFSM Behavior Trees Scripting C++/Lua/Ruby Planner (HTN)
Behavior Trees ? ? ? ? S P S S
Leaf Nodes Actions Actions are the way that the agent changes the world Every action should return succeed or fail Examples move, turn, animate, sound Conditions Conditions are leaves in the Behavior Tree They check information from the world by accessing the world model Conditions are tests that return succeed or fail to the parent task Examples actor state, collision, entity queries
Adding Complexity • Add branches to manage the leaves • Accomplished with composite tasks / nodes
Logical Control • Sequence Nodes • Sequences execute child nodes in the order supplied • As long as each child behavior succeeds, the sequence continues it’s execution. • If a child has an unexpected error, the sequence breaks and returns the child’s error bail out S keep going • Parallel Nodes • Parallel nodes executes each child task concurrently • Failure Policy: How many children must fail before the parallel fails? • Completion Policy: How many children must finish before the parallel finishes? P
Parallel Node • Often it is useful to have a scheduler to manage the behaviors without having to do micromanagement in the Behavior Tree • Parallel trees work better with independent behaviors • For example: one behavior is movement and the second would be animation • Common Pattern: One parallel node with multiple conditions as children and a single action. • Conditions do not modify the world • Single action so no concern about dependence between behaviors • Safe to use parallel nodes with completely different trees • Example: Agent on patrol has one behavior tree for the head of the agent and a second behavior tree for deciding where to go
Logical Control bail out • Priority Selector Nodes • Try to execute children in order • If the current child fails, fall back to the next one • If a child succeeds and finishes, then the selector node finishes ? 1 2 • Random Selector Nodes • Randomly select a child node based on some probability distribution • Continue selecting children until one succeeds. ? 0.25 0.75
Sequences and Selectors • Programming language basics • Statements and conditionals • Very powerful model for computation
Update ? 3 1 2 ? ? ? 2 1 S P S S
Concrete Example – Dog AI • What do dogs do? • walk, run, sit, stand idle, rest, sleep, eat, poop, chase tail, scratch, etc. • Break these down into three categories • Bodily • rest, sleep, eat, poop, etc. • Active • walking around, running, chasing tail, scratching, etc. • Passive • sitting, lying down, standing idle, etc.
? 1. bodily 2. active 3. passive ? ? ? S P S S walk to food play eat animation play poop animation create new objects
Remaining Issues • We may spend a lot of time in leaves, so what happens if a higher priority node becomes active? • Option 1: • Search the tree from the root with low frequency • If new task found • invalidate the old task • begin the new task • Option 2: • Event driven interrupts • How do we handle parallel tasks? • Requires implementing a scheduler ? 2 1 P S S
Behavior Tree Resources • AIGameDev.com • Single greatest source of information for Game AI • Building AI for a Simulation from the Ground Up • Series of tutorials written for AIGameDev.com • Damian Isla • Handling Complexity in the Halo 2 AI. Gamasutra • Building a Better Battle. Bungie • Behavior Trees: Three Ways of Cultivating Game AI. GDC 2010 • Behavior Trees: Branching Paths with Selectors. Arges Systems • Introduction to Behavior Trees