Choosing through a decision tree
One of the simplest mechanisms for tackling decision-making problems is decision trees, because they are fast and easy to grasp and implement. As a consequence, it's one of the most used techniques today; it is extensively used in other character-controlled scopes such as animations.
Getting ready
This recipe requires a good understanding of recursion and inheritance as we will constantly be implementing and calling virtual functions throughout the sections.
How to do it...
This recipe requires a lot of attention due to the number of files that we will need to handle. Overall, we will create a parent class DecisionTreeNode
, from which we will derive the other ones. Finally, we will learn how to implement a couple of standard decision nodes:
First, create the parent class,
DecisionTreeNode
:using UnityEngine; using System.Collections; public class DecisionTreeNode : MonoBehaviour { public virtual DecisionTreeNode MakeDecision() { return null; ...