I am working on an engine and recently implemented q-search. My q-search is slow and I spend as much time in it as I spend in regular evaluation (although my regular evaluation is currently just material and piece-square tables). It is halving my number of nodes per second (I don't count nodes in q-search). I am looking for advice on how I can speed it up. My code is below, and a few notes on it:
-I don't use MVV/LVA or SEE. Instead, I order my moves by piece value. My pawn capturing an enemy queen I value at +800 priority units, and my rook capturing an enemy knight I value at -200 priority units. My king capturing anything at all is valued at +1000 priority units. Then I search the move with the highest priority units first. I feel like makes more sense than MVV/LVA where RxR is searched before PxB. I put the king captures at +1000 because I feel like any legal king captures tend to be very good.
-I store evaluation/alpha/beta in the node itself, rather than passing by value.
-The function generateCaptures not only generates captures, but orders them by the method I gave above.
Code: Select all
void quiescenceSearch(boardState* board) {
assert(board != NULL);
board->alpha = board->parentNode->alpha;
board->beta = board->parentNode->beta;
board->depth = board->parentNode->depth+1;
evaluate(board);
if (board->whoseTurn == WHITE) {
if (board->evaluation > board->alpha) {
board->alpha = board->evaluation;
}
}
else if (board->whoseTurn == BLACK) {
if (board->evaluation < board->beta) {
board->beta = board->evaluation;
}
}
if (board->alpha > board->beta) {
return;
}
generateCaptures(board);
boardState* node = board->childNode;
while (node != NULL) {
quiescenceSearch(node);
if (board->whoseTurn == WHITE) {
if (node->evaluation > board->alpha) {
board->alpha = node->evaluation;
}
if (node->evaluation > board->evaluation) {
board->evaluation = node->evaluation;
}
}
else if (board->whoseTurn == BLACK) {
if (node->evaluation < board->beta) {
board->beta = node->evaluation;
}
if (node->evaluation < board->evaluation) {
board->evaluation = node->evaluation;
}
}
if (board->alpha >= board->beta) {
deleteAllUnderneath(board);
return;
}
node = node->nextNode;
}
deleteAllUnderneath(board);
}