diff --git a/src/evaluate.cpp b/src/evaluate.cpp index 5c1f7496d0b..44da2325690 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -701,9 +701,17 @@ namespace { ei.attackedBy[WHITE][ALL_PIECES] |= ei.attackedBy[WHITE][KING]; ei.attackedBy[BLACK][ALL_PIECES] |= ei.attackedBy[BLACK][KING]; - // Do not include in mobility squares protected by enemy pawns or occupied by our pawns or king - Bitboard mobilityArea[] = { ~(ei.attackedBy[BLACK][PAWN] | pos.pieces(WHITE, PAWN, KING)), - ~(ei.attackedBy[WHITE][PAWN] | pos.pieces(BLACK, PAWN, KING)) }; + // Find pawns on rank 4 and above which can move forward + Bitboard pmobw = shift_bb(~pos.pieces()) & ~(Rank2BB | Rank3BB); + Bitboard pmobb = shift_bb(~pos.pieces()) & ~(Rank7BB | Rank6BB); + + // Find pawns which can capture + pmobw |= shift_bb(pos.pieces(BLACK)) | shift_bb(pos.pieces(BLACK)); + pmobb |= shift_bb(pos.pieces(WHITE)) | shift_bb(pos.pieces(WHITE)); + + // Do not include in mobility squares protected by enemy pawns or occupied by our blocked pawns or king + Bitboard mobilityArea[] = { ~(ei.attackedBy[BLACK][PAWN] | (pos.pieces(WHITE, PAWN) & ~pmobw) | pos.pieces(WHITE, KING)) , + ~(ei.attackedBy[WHITE][PAWN] | (pos.pieces(BLACK, PAWN) & ~pmobb) | pos.pieces(BLACK, KING)) }; // Evaluate pieces and mobility score += evaluate_pieces(pos, ei, mobility, mobilityArea);