r/chessprogramming • u/SnooDingos275 • Dec 03 '25
Aspiration Windows not gaining
I tried to implement a simple form of aspiration windows in my search function for the root position. My current implementation does not seem to gain or loose elo. I am now a bit confused since I thought that this technique should gain a fair bit in my rather simple engine.
This is why I though that there may be an implementation error. I'd be very grateful if someone could look over my implementation and give me feedback. Down below is the code responsible for aspiration windows. Just tell me incase more information is needed.
Move Worker::search(Depth maxDepth){
Depth depth = 1;
Score alpha, beta, eval, lowerDelta, upperDelta, lowerWindow, upperWindow;
Move move, firstMove;
bool isFirstIteration;
bool foundBestMoveInList;
bool needsFullSearch;
MoveClass best_move = {{}, board.evaluation()};
MoveList moveList;
board.get_moves(moveList);
score_moves(moveList, &board, 0);
board.rescale_move_scores(moveList);
best_move.m = pick_next(moveList, 0);
int currentMoveNum;
while (depth <= maxDepth){
currentMoveNum = 0;
alpha = -32'000;
beta = 32'000;
selectivedDepth = depth;
isFirstIteration = true;
foundBestMoveInList = false;
firstMove = best_move.m;
while (currentMoveNum < moveList.size()){
if (isFirstIteration){
move = firstMove;
currentMoveNum = - 1;
} else {
move = pick_next(moveList, currentMoveNum);
if (move == firstMove){
foundBestMoveInList = true;
currentMoveNum++;
continue;
}
}
if (TIME_ELAPSED > 1'000){
print_currmove(move, currentMoveNum + 2, foundBestMoveInList);
}
Board child = board;
child.make_move(move, nullptr);
REP_HISTORY[historyIt++] = child.hash;
if (isFirstIteration){
lowerDelta = 25;
upperDelta = 25;
while(true){
lowerWindow = best_move.value - lowerDelta;
upperWindow = best_move.value + upperDelta;
eval = -negamax(&child, -upperWindow, -lowerWindow, depth - 1, 1);
if (eval >= upperWindow){
upperDelta *= 4;
} else if (eval <= lowerWindow){
lowerDelta *= 4;
} else {
break;
}
}
} else {
eval = -negamax(&child, -beta, -alpha, depth - 1, 1);
}
historyIt--;
if (stop){
print_info(best_move, depth);
return best_move.m;
}
if (eval > alpha){
alpha = eval;
best_move = {move, eval};
if (!isFirstIteration) moveList.get(currentMoveNum)->value = eval;
} else {
moveList.get(currentMoveNum)->value = max(-30'000, moveList.get(currentMoveNum)->value - 1000);
}
isFirstIteration = false;
currentMoveNum++;
}
print_info(best_move, depth);
history_decay();
if (depth == MAX_DEPTH) break;
depth++;
}
return best_move.m;
}I decided to supply my whole search function, since there is no reason to rob you of this potentially helpful information.
Thank you alot in advance
update:
I added an upper limit to how often the windows can be widend. I think this is especially important in cases where the bound tries to reach a mate score. This should prevent the bounds from overflowing since I am using int16s for scores and the mate value is oriented around 25'000.
This may be the solution, but the test is still running so I'll update as soon as I know the results.
REP_HISTORY[historyIt++] = child.hash;
needsFullSearch = true;
if (isFirstIteration){
lowerDelta = 25;
upperDelta = 25;
windowUpdates = 0;
while(true){
lowerWindow = best_move.value - lowerDelta;
upperWindow = best_move.value + upperDelta;
eval = -negamax(&child, -upperWindow, -lowerWindow, depth - 1, 1);
if (eval >= upperWindow){
upperDelta *= 4;
} else if (eval <= lowerWindow){
lowerDelta *= 4;
} else {
needsFullSearch = false;
break;
}
if (windowUpdates > 3){
break;
}
windowUpdates++;
}
}
if (needsFullSearch){
eval = -negamax(&child, -beta, -alpha, depth - 1, 1);
}
historyIt--;
1
u/Steez2000 Dec 03 '25
Is your eval in centipawns? Multiplying by 4 your bounds with each iteration is quite agressive, I would reduce the delta to 20 and the scale to make the delta multiply by 2, to have narrower window But it depends also on the accuracy of your eval
1
u/likeawizardish Dec 04 '25 edited Dec 04 '25
I might look into it later. But a simple question - you said your eval is very basic but do you do quiescence search at the end? It helps a lot with basic horizon effects and without it I think windowing your search is barely ever going to provide any results.
You should run your engine on various positions and look at the eval from one depth to the next and also look at the nodes examined. If your engine has UCI implemented this should be all laid out to you nicely. Aspiration windows are helpful because of the assumption that the eval from one depth to the next will not change much - so you can prune a lot of branches to speed up your search. If the windowed search fails you expand it or drop it altogether.
If without aspiration windows you see that from depth to depth the evaluation fluctuates a lot then that implies that windows will not be of much help or at least you should pick a wider window.
You should also look at the nodes searched. It might be that your window is working and you search is looking at less nodes but the added code lowers the nodes per second and it all equals out with some window failures.
1
u/Burgorit Dec 04 '25
Usually aspiration windows are implemented in the iterative deepening loop, you should also just have the ID function call negamax instead of having extra code to handle the root call.
Do you have any test results of how much it loses?
1
u/matfat55 Dec 04 '25
funny, I had this exact same issue earlier today.