I'm working on my engine right now and have been facing some weird bugs that all have to do with qsearch (whenever I don't use it, everything works perfectly): if I run 'go depth 6', followed by 'go depth 8' and 'go depth 9' (on the same position), everything works fine. But when I then try 'go depth 8' again, it gives me values close to -INF and INF.
Here is my code - I also do move ordering but I removed it to make this simpler.
Code: Select all
int quiescence(int alpha, int beta) {
nodes_evaluated++;
// static evaluation:
int eval = evaluate();
// alpha/beta escape conditions:
if (eval >= beta) return beta;
if (eval > alpha) alpha = eval;
// generate all possible moves from this position:
int moves[MAX_POSITION_MOVES];
int num_moves = b.get_nonquiet_moves(moves);
// if there are no more nonquiet moves to make, return the current static eval:
if (num_moves == 0) return eval;
// recursively qsearch the horizon:
for (int i = 0; i < num_moves; i++) {
// make move & recursively call negamax helper function:
b.make_move(moves[i]);
int score = -quiescence(-beta, -alpha);
b.undo_move();
if (score > alpha) {
alpha = score;
if (score >= beta) return beta;
}
}
return alpha;
}
Thank you and enjoy the rest of your day!