Is this valid iterative deepening code??
public Move GetBestMove(IBoard board, int depth)
{
this.maxDepth = 100;
this.maxTime = 9000;
//Set initial window
int alpha = -INFINITY, beta = INFINITY;
//The move that will be returned
Move bestMove = null;
List<Move> moves = board.getMoves();
//Get the time search has started
long startTime = System.nanoTime();
//Iterate through the depths
for (int i = 0; i < maxDepth; i++)
{
bestMove = negaScoutRoot(board, alpha, beta);
int val = bestMove.score;
//Time check
double curTime = (System.nanoTime() - startTime) / 1e6;
if (curTime >= maxTime)
return bestMove;
//Score missed aspiration window
if (val <= alpha || val >= beta)
{
alpha = -INFINITY;
beta = INFINITY;
//Go to next iteration
continue;
}
//Set new aspiration window
alpha = val - ASPIRATION_SIZE;
if (alpha < -INFINITY)
alpha = -INFINITY;
beta = val + ASPIRATION_SIZE;
if (beta > INFINITY)
beta = INFINITY;
}
//Return the move
return bestMove;
}
private Move negaScoutRoot(IBoard board, int alpha, int beta)
{
//The move that will be returned
Move bestMove = null;
List<Move> moves = board.getMoves();
for (Move move : moves)
{
//Make the move
board.make(move, true);
//Search
int val = -negascout(board, 0, alpha, beta);
//Undo the move
board.undo(move);
//Keep best move
if (val > alpha)
{
alpha = val;
bestMove = move;
bestMove.score = alpha;
}
}
//Return the move
return bestMove;
}
I also added aspiration window. The root always starts searching from the current board state but with a different window.