// 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); } }
public Double getUtilityIfAlreadyFound(int key[], int curdepth) { if (viewedPos != null) { AnalysedPosition alreadyAnalysedPos = viewedPos.search(key); if (alreadyAnalysedPos != null && alreadyAnalysedPos.getDepth() >= curdepth) { return new Double(alreadyAnalysedPos.getUtility()); } } return null; }
// testing: make sure that the position didn't suddenly get on the list. public void sanityTestPositionDidntDissapearOffTree( AnalysedPosition alreadyAnalysedPos, int key[], boolean alreadyDidPos, int curdepth) { // note: this should not happen within this function. if (viewedPos != null) { alreadyAnalysedPos = viewedPos.search(key); if (alreadyAnalysedPos != null && alreadyDidPos == false) { if (alreadyAnalysedPos.getDepth() >= curdepth) { System.out.println("ERROR: Position should have been viewable earlier"); System.exit(1); } } } }