However, when after implementing quiescent search, I now get scores that alternate between pos/neg for odd/even depths. I have not done anything special with my implementation and even when checking against the pseudocode on wikipedia and the chess programming wiki, I can't seem to understand what is causing this to happen.
I'm using a very barebones evaluation to test search, so I don't suspect that's at fault
Code: Select all
int wMaterial = (P_VAL * count_bits(board->pieceBB[n_wPawn])) +
(N_VAL * count_bits(board->pieceBB[n_wKnight])) +
(B_VAL * count_bits(board->pieceBB[n_wBishop])) +
(R_VAL * count_bits(board->pieceBB[n_wRook])) +
(Q_VAL * count_bits(board->pieceBB[n_wQueen])) +
(K_VAL * count_bits(board->pieceBB[n_wKing]));
int bMaterial = (P_VAL * count_bits(board->pieceBB[n_bPawn])) +
(N_VAL * count_bits(board->pieceBB[n_bKnight])) +
(B_VAL * count_bits(board->pieceBB[n_bBishop])) +
(R_VAL * count_bits(board->pieceBB[n_bRook])) +
(Q_VAL * count_bits(board->pieceBB[n_bQueen])) +
(K_VAL * count_bits(board->pieceBB[n_bKing]));
if (count_bits(board->pieceBB[n_wBishop] >= 2)) wMaterial += 50; else wMaterial -= 50;
if (count_bits(board->pieceBB[n_bBishop] >= 2)) bMaterial += 50; else bMaterial -= 50;
const int material = wMaterial - bMaterial;
return color * (material + (nMoves / 2));
Code: Select all
static int quiesce(Board *board, int alpha, int beta, int color) {
moveList mList = { 0 };
moveList tacticalMoves = { 0 };
int nMoves = genLegalMoves(board, &mList);
int nTactical = genLegalTactical(board, &tacticalMoves);
int standPat = eval(board, nMoves, color);
if (standPat >= beta)
return beta;
if (standPat > alpha)
alpha = standPat;
for (int i = 0; i < nMoves; i++) {
if (nTactical == 0) break;
make(board, mList.moves[i].move);
int score = -quiesce(board, -beta, -alpha, -color);
unmake(board, mList.moves[i].move);
if (score >= beta) return beta;
if (score > alpha) alpha = score;
}
return alpha;
}
int alphaBeta(Board *board, int alpha, int beta, int depthLeft, int color) {
if (depthLeft == 0) return quiesce(board, alpha, beta, color);
moveList mList = {0};
genLegalMoves(board, &mList);
for (int i = 0; i < mList.nMoves; i++) {
make(board, mList.moves[i].move);
int score = -alphaBeta(board, -beta, -alpha, depthLeft - 1, -color);
unmake(board, mList.moves[i].move);
if (score >= beta) return beta;
if (score > alpha) alpha = score;
}
return alpha;
}
This is my principal search function
Code: Select all
void search(Board *board, int depth) {
moveList mList = { 0 };
genLegalMoves(board, &mList);
int best;
int max = -500000;
for (int i = 0; i < mList.nMoves; i++) {
int color = (board->turn == WHITE) ? 1 : -1;
make(board, mList.moves[i].move);
int score = -alphaBeta(board, -500000, 500000, depth - 1, -color);
unmake(board, mList.moves[i].move);
if (score > max) {
max = score;
best = mList.moves[i].move;
}
}
printf("score: %d, best move: ", max);
print_move(best);
printf("\n");
}