Artificial Intelligence: Behavior Trees Part 3

Hello everyone! I’m back from a long break of exhaustion of finishing another semester at college and from the holiday season!

I was previously talking about Behavior Trees, and today I want to continue where I left off with different types of Composite Nodes. Recall that Composite Nodes define the root of a particular branch of a Behavior Tree and the rules for how that branch is executed. In other words, they are mainly used for controlling the logic of each branch of the tree and which AI behavior(s) to perform on that branch.

Types of Composite Nodes

  • Sequences - Sequences are extremely useful when you have a series of AI behaviors that ALL must be completed “successfully” in a particular order before accomplishing a certain task. For example, imagine you want an AI to walk through a door that is currently closed. In order for the AI to complete this task, it first needs to walk to the door, open the door, then walk through the door, and finally close the door. These are all behaviors that must be completed in that order to complete the entire task. A Sequence is a type of Composite Node (i.e. a rule) that visits every child node in order from left-to-right in a linear fashion while checking for a “Success” status message to be returned for each node. If any one of the children nodes sends a “Failure” status message, the entire Sequence stops executing and is also said to “fail”. For example, with the door analogy used above, a failure message may be sent if the AI was interrupted by something, such as the player, another AI, or another event like the door being locked or the path being blocked. You can also think of a Sequence as an AND logic gate operation.

  • Selectors - Selectors are very useful when your AI has many different choices of the actions it can take in a given priority order, and you want the AI to find the single, best action that can be performed “Successfully”. For example, reconsider the last scenario with the game AI walking through a door. With the Sequence above, we assumed the door was always unlocked and could be opened. But what happens if the AI gets to the door and its locked? We can use a Selector here to check if the door can be opened! If the door is locked, meaning the ‘Open Door’ behavior sent a failure status message to the Selector, then the AI can attempt to unlock the door and then open the door. If that behavior “fails”, maybe the AI can try to bust the door in. If that behavior sends failure back to the Selector, then perhaps the door cannot be opened and the Selector also fails. However, you can see that a Selector gives the user a lot more control on the behaviors an AI can exhibit. A Selector is a type of Composite Node that visits it children in priority order from left-to-right and checks for the first child node that returns a “Success” status message. If all of the children nodes send a “Failure” status message, the entire Selector stops executing and also is said to “fail.” You can think of a Selector as an OR logic gate operation.

Here are some really good pictures to show what a Behavior Tree with just Sequences and Selectors looks like to help you understand! These pictures were made by another blogger named Chris Simpson. They are not made by me!

A Sequence Composite node that just describes an AI walking through a doorway. This tree just consists of a Leaf Nodes that define general behaviors for simplicity. The code structure to perform these behaviors is more complicated.Retrieved from htt…

A Sequence Composite node that just describes an AI walking through a doorway. This tree just consists of a Leaf Nodes that define general behaviors for simplicity. The code structure to perform these behaviors is more complicated.

Retrieved from http://www.gamasutra.com/blogs/ChrisSimpson/20140717/221339/Behavior_trees_for_AI_How_they_work.php

A Behavior Tree with a Sequence and Selector Composite Nodes that also describes an AI walking through a doorway.Retrieved from: http://www.gamasutra.com/blogs/ChrisSimpson/20140717/221339/Behavior_trees_for_AI_How_they_work.php

A Behavior Tree with a Sequence and Selector Composite Nodes that also describes an AI walking through a doorway.

Retrieved from: http://www.gamasutra.com/blogs/ChrisSimpson/20140717/221339/Behavior_trees_for_AI_How_they_work.php

A Behavior Tree with a series of Sequences and Selectors that represent an AI attempting to get into a building through both a doorway and a window.Retrieved from: http://www.gamasutra.com/blogs/ChrisSimpson/20140717/221339/Behavior_trees_for_AI_How…

A Behavior Tree with a series of Sequences and Selectors that represent an AI attempting to get into a building through both a doorway and a window.

Retrieved from: http://www.gamasutra.com/blogs/ChrisSimpson/20140717/221339/Behavior_trees_for_AI_How_they_work.php