switch to builtin_popcountll for board eval

This commit is contained in:
k 2025-06-19 19:41:44 -04:00
parent e1fe8ee603
commit 05a0b2b7f1

View File

@ -38,26 +38,19 @@ move *findBest(move* moves, size_t size, game* g){
int evaluateBoard(game *game) { int evaluateBoard(game *game) {
int score = 0; int score = 0;
score += __builtin_popcountll(game->white.pawns) * PAWN_VALUE;
score += __builtin_popcountll(game->white.knights) * KNIGHT_VALUE;
score += __builtin_popcountll(game->white.bishops) * BISHOP_VALUE;
score += __builtin_popcountll(game->white.rooks) * ROOK_VALUE;
score += __builtin_popcountll(game->white.queen) * QUEEN_VALUE;
score += __builtin_popcountll(game->white.king) * KING_VALUE;
for (int i = 0; i < 64; ++i) { score -= __builtin_popcountll(game->black.pawns) * PAWN_VALUE;
long long bit = 1LL << i; score -= __builtin_popcountll(game->black.knights) * KNIGHT_VALUE;
if (game->white.pawns & bit) score += PAWN_VALUE; score -= __builtin_popcountll(game->black.bishops) * BISHOP_VALUE;
else if (game->white.knights & bit) score += KNIGHT_VALUE; score -= __builtin_popcountll(game->black.rooks) * ROOK_VALUE;
else if (game->white.bishops & bit) score += BISHOP_VALUE; score -= __builtin_popcountll(game->black.queen) * QUEEN_VALUE;
else if (game->white.rooks & bit) score += ROOK_VALUE; score -= __builtin_popcountll(game->black.king) * KING_VALUE;
else if (game->white.queen & bit) score += QUEEN_VALUE;
else if (game->white.king & bit) score += KING_VALUE;
}
for (int i = 0; i < 64; ++i) {
long long bit = 1LL << i;
if (game->black.pawns & bit) score -= PAWN_VALUE;
else if (game->black.knights & bit) score -= KNIGHT_VALUE;
else if (game->black.bishops & bit) score -= BISHOP_VALUE;
else if (game->black.rooks & bit) score -= ROOK_VALUE;
else if (game->black.queen & bit) score -= QUEEN_VALUE;
else if (game->black.king & bit) score -= KING_VALUE;
}
return score; return score;
} }