@Override
protected TwoPlayerMove findBestMove(TwoPlayerMove lastMove, int depth, MoveList list,
SearchWindow window, SearchTreeNode parent) {
int i = 0;
int newBeta = window.beta;
TwoPlayerMove selectedMove;
TwoPlayerMove bestMove = (TwoPlayerMove)list.getFirstMove();
while ( !list.isEmpty() ) {
TwoPlayerMove theMove = getNextMove(list);
if (pauseInterrupted())
return lastMove;
updatePercentDone(depth, list);
searchable.makeInternalMove( theMove );
SearchTreeNode child = addNodeToTree(parent, theMove, window );
// search with minimal search window
selectedMove = searchInternal( theMove, depth-1, new SearchWindow(-newBeta, -window.alpha), child);
searchable.undoInternalMove( theMove );
if (selectedMove != null) {
int selectedValue = -selectedMove.getInheritedValue();
theMove.setInheritedValue( selectedValue );
if (selectedValue > window.alpha) {
window.alpha = selectedValue;
}
if (window.alpha >= window.beta) { // beta cut-off
//System.out.println(getIndent(depth) + "beta cut-off1 because a=" + window.alpha + " >= " + window.beta);
theMove.setInheritedValue(window.alpha);
bestMove = theMove;
break;
}
if (window.alpha >= newBeta) {
// re-search with narrower window (typical alpha beta search).
searchable.makeInternalMove( theMove );
selectedMove = searchInternal( theMove, depth-1, window.negateAndSwap(), child );
if (selectedMove != null) {
searchable.undoInternalMove( theMove );
selectedValue = -selectedMove.getInheritedValue();
theMove.setInheritedValue(selectedValue);
bestMove = theMove;
if (window.alpha >= window.beta) {
showPrunedNodesInTree(list, parent, i, selectedValue, window);
break;