// Adds the position and it's estimated utility to the table.
  // If the position is already in the table (which will happen sometimes), It will either update.
  public void addPositionToListOfAnalysedPositions(
      int key[], boolean isDarkPlayerCurrentTurn, int curdepth, double utility) {

    boolean alreadyDidPos = false;
    AnalysedPosition alreadyAnalysedPos = null;

    // check if the position has been inserted after doing the recursion:
    if (viewedPos != null) {
      alreadyAnalysedPos = viewedPos.search(key);
      if (alreadyAnalysedPos != null) {
        alreadyDidPos = true;
      }
    }

    // If the position is not already done:
    if (alreadyDidPos == false) {
      AnalysedPosition pos = new AnalysedPosition(curdepth, isDarkPlayerCurrentTurn, utility, key);
      viewedPos = BalancedSearchTree.addValueToTree(viewedPos, pos);

      // FOR TEST PURPOSES
      numPosRecorded++;
      // TESTING SLOW
      if (debug) {
        sanityCheckNumNodes();
        viewedPos.sanityCheckSorted();
      }
      // END TESTING

      // if we only need to update:
    } else {
      alreadyAnalysedPos.updatePositionWithImprovedCalculation(curdepth, utility);
    }
  }