Behavior Tree / AI
BlitzMax Forums/BlitzMax Programming/Behavior Tree / AI
| ||
MERRY CHRISTMAS TO ALL A couple of years ago, the AI (using a FSM) of a game I was developing became so large and unwieldy that I ultimately gave up on it. Recently I started trying different approaches and during some research found this article about AI in Halo 2 which took me in a totally different direction. Further research gave me some information on Behavior trees but nothing much to build upon so I started from scratch. My design goals were simple: It had to fit into existing code, not be reliant on other libraries and be reusable. My Behavior Tree is implemented as a linked tree of Nodes called Controls and Traits. Controls decide on which child should be executed and Traits are the Leaf nodes that implement a Behavior or Action for your sprite or character. Take the following code; it shows a simple AI that moves a sprite to a screen location and when it arrives, chooses a new destination: Example1-Simple Whilst this example is very simple (and probably easier to implement with a FSM), you have to remember that the tree can be easily expanded to thousands of decisions without having to manually maintain a state. The Behavior tree in the example is created by using a standard "Selector" Control as a root node and two custom Traits as children of that node (Movement and ChooseDestination). I have currently implemented the following standard Control nodes: * Selector - Executes each child until one is successful and only fails if all children fail. * Randomiser - Executes a single random child node. * Sequence - Executes each child until one fails. Succeeds if all children succeed. It also supports bitvector based node execution, which means that large portions of the Behaviour Tree can be enabled / disabled based on a single system game state. My Code is in BETA at the moment and I hope to have it up on SourceForge shortly. I'd be interested in hearing your thoughts on this. Cheers, Si... |
| ||
V1.00 Released on SourceForge Whats new! * Three new Controls: Singular, RoundRobin and RequireNone * Three new Traits: Enabler, Disabler and Decision * TreeBuilder that allows Behavior trees to be created from a definition file (No more code changes when tweeking your AI). * Added Enable/Disable ability to all traits & controls * Started a Wiki * Can be used standalone or compiled as a module. Controls * Selector - Executes each child until one is successful and only fails if all children fail. * Randomiser - Executes a single random child node. * Sequence - Executes each child until one fails. Succeeds if all children succeed. * Singular NEW * RoundRobin NEW Selects the next child in order * RequireNone NEW Parses all children and returns success when all children fail, or fail when any one succeeds. Traits: * Enabler NEW - Enables a list of nodes * Disabler NEW - Disables a list of nodes * Decision NEW - Allows a decision point to be included Examples * Example1-Simple.bmx * Example2-TreeBuilder.bmx NEW |