-
Notifications
You must be signed in to change notification settings - Fork 0
2. Nodes
So, to assemble the tree I first need to program the nodes. Thus, step one was to create the composite nodes first, disregarding the root node, since that happens to be a composite node as well. After that, I create the leaf nodes depending on what behavior I need at the end.
First, I created an abstract class so that all nodes will have a common interface to work with, as well as an enum called "State" containing the three possible states: Success, Failure, and Running.
Next up was the selector node, which is simply a loop, evaluating all nodes in its list. The method returns if a node is either running or successful, and keeps evaluating when the current node was a failure.
The sequence node is structurally similar to the selector node but returns when the evaluation of the current node turns out to be a failure.
Lastly, for the decorator nodes, I implemented an inverter node, whose purpose is to simply invert the evaluation of another node. It leaves running at running but inverts success and failure.