The framework that we just reviewed is nothing more than this. It provides us with all the functionality we need to make a tree, but we have to make the actual tree ourselves. For the purposes of this book, a somewhat manually constructed tree is provided.
Before we set up our tree, let's look at what we're trying to accomplish. It is often helpful to visualize a tree before implementing it. Our tree will count up from zero to a specified value. Along the way, it will check whether certain conditions are met for that value and report its state accordingly. The following diagram illustrates the basic hierarchy for our tree:
For our tests, we will use a three-tier tree, including the root node:
Node 1: This is our root node. It has children, and we want to be able to return a success if any of the children is a success, so we'll implement it as a selector.
Node 2a: We'll implement this node using an
ActionNode
.Node 2b: We'll use this node to demonstrate how...