diff --git a/src/eval.c b/src/eval.c index 876d85d..d61e69e 100644 --- a/src/eval.c +++ b/src/eval.c @@ -37,29 +37,22 @@ move *findBest(move* moves, size_t size, game* g){ } 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) { - long long bit = 1LL << i; - if (game->white.pawns & bit) score += PAWN_VALUE; - else if (game->white.knights & bit) score += KNIGHT_VALUE; - else if (game->white.bishops & bit) score += BISHOP_VALUE; - else if (game->white.rooks & bit) score += ROOK_VALUE; - else if (game->white.queen & bit) score += QUEEN_VALUE; - else if (game->white.king & bit) score += KING_VALUE; - } + score -= __builtin_popcountll(game->black.pawns) * PAWN_VALUE; + score -= __builtin_popcountll(game->black.knights) * KNIGHT_VALUE; + score -= __builtin_popcountll(game->black.bishops) * BISHOP_VALUE; + score -= __builtin_popcountll(game->black.rooks) * ROOK_VALUE; + score -= __builtin_popcountll(game->black.queen) * QUEEN_VALUE; + score -= __builtin_popcountll(game->black.king) * 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; } void makeMove(game *g, move* m) {