// A leaf node for a BINARY-VALUED decision tree.

import AgentWorld.*;

class LeafNode extends DecisionTree
{ boolean decision;
  int examplesFallingHere, // How many (in)correctly categorized training
      examplesIncorrectlyFallingHere; // examples reached this node?

  // The constructors.
  LeafNode(boolean decision, int examplesFallingHere)
  {
    this(decision, examplesFallingHere, 0);
  }
  LeafNode(boolean decision, int examplesFallingHere, int examplesIncorrectlyFallingHere)
  { // Due to tree "pruning" leaf nodes might not be purely of one category.
    super();
    this.decision = decision;
    this.examplesFallingHere            = examplesFallingHere;
    this.examplesIncorrectlyFallingHere = examplesIncorrectlyFallingHere;
  }

  boolean makeDecision(Sensors sensors)
  {
    if (debugging) Utils.println("reached " + toString());
    return decision;
  }

  void printTree(int currentDepth, int maxDepth)
  {
    indentTree(2 * currentDepth);
    System.out.println(toString());
  }

  int countInteriorNodes()
  {
    return 0;
  }
  int countLeaves()
  {
    return 1;
  }

  public String toString()
  { String answer = "";

    if (decision) answer += "GOOD"; else answer += "BAD";

    answer += " move (" + examplesFallingHere + " ex's";

    if (examplesIncorrectlyFallingHere > 0)
    {
      answer += " and " + examplesIncorrectlyFallingHere + " counter ex's";
    }

    return answer += ")";
  }
}
