Game Development Reference
Step 1. Download Chapter Five/DecisionTrees.zip from the Web site
and open the decisionTree scene in Unity. Play to see the decision
tree constructed from data in Table 5.5 . This tree is illustrated
in Figure 5.15 .
FIG 5.15 A tree graph produced from
data in Table 5.5 .
Note that the full code for decision tree construction using the ID3
algorithm is contained in the Plugins > ID3.cs file in the Project. The
original code can be found at http://codeproject.com/KB/recipes/
id3.aspx . Data have been changed to reflect the values in Table 5.5 .
Although we are not focusing on C# in this topic, the complexities of
most AI algorithms lend themselves to being written in more robust
but rather to point out parts of the code you could experiment with
changing should you want to create your own decision tree.
Step 2. Open ID3.cs in the script editor. Scroll to the very bottom of
the code to find the createDataTable() function.
Step 3. First the attributes are defined. For each of these are a set of
values. Data are then laid out in a table. The name of each column is
the attribute name followed by a final decision column, in this case
named strategy . Following this, each row from data is added to the
table. If you want to create your own decision tree you can add as
many attribute columns as you wish by following the same coding
format. Just ensure that there is an associated column for each item
in data. The last column, denoting a decision, is a Boolean value.