@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.get(0);
Entry entry = new Entry(bestMove, depth, window);
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) {
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 );
searchable.undoInternalMove( theMove );
selectedValue = -selectedMove.getInheritedValue();
theMove.setInheritedValue(selectedValue);
bestMove = theMove;
if (window.alpha >= window.beta) {
break;
}