/**
   * Method for finding the best child to explore
   *
   * @param n
   * @return
   */
  private Node bestChild(Node n) {
    Node best = null;
    double bestValue = Double.NEGATIVE_INFINITY;
    for (Node c : n.getChildren().values()) {
      double uctValue =
          (c.getTotalValue() / c.getVisits())
              + COEFFICIENT * Math.sqrt((2 * Math.log(n.getVisits())) / (c.getVisits()));

      uctValue +=
          rng.nextDouble()
              * 1e-6; // In case of same uctValue, this random will remove bias towards first
                      // checked child
      if (bestValue < uctValue) {
        bestValue = uctValue;
        best = c;
      }
    }
    // TESTING
    if (best == null) {
      System.out.println("BUGS");
    }
    //
    return best;
  }