- clear_bit(&occ, from);
- attackers =
- (rook_attacks_bb(to, occ) & rooks_and_queens()) |
- (bishop_attacks_bb(to, occ) & bishops_and_queens()) |
- (piece_attacks<KNIGHT>(to) & knights()) |
- (piece_attacks<KING>(to) & kings()) |
- (pawn_attacks(WHITE, to) & pawns(BLACK)) |
- (pawn_attacks(BLACK, to) & pawns(WHITE));
- attackers &= occ;
-
- // If the opponent has no attackers, we are finished:
- if((attackers & pieces_of_color(them)) == EmptyBoardBB)
- return seeValues[capture];
+
+ // Handle en passant moves
+ if (st->epSquare == to && type_of_piece_on(from) == PAWN)
+ {
+ assert(capture == EMPTY);
+
+ Square capQq = (side_to_move() == WHITE)? (to - DELTA_N) : (to - DELTA_S);
+ capture = piece_on(capQq);
+
+ assert(type_of_piece_on(capQq) == PAWN);
+
+ // Remove the captured pawn
+ clear_bit(&occ, capQq);
+ }
+
+ while (true)
+ {
+ clear_bit(&occ, from);
+ attackers = (rook_attacks_bb(to, occ) & rooks_and_queens())
+ | (bishop_attacks_bb(to, occ) & bishops_and_queens())
+ | (piece_attacks<KNIGHT>(to) & knights())
+ | (piece_attacks<KING>(to) & kings())
+ | (pawn_attacks(WHITE, to) & pawns(BLACK))
+ | (pawn_attacks(BLACK, to) & pawns(WHITE));
+
+ // Remove our pinned pieces from attacks if the captured piece is not
+ // a pinner, otherwise we could remove a valid "capture the pinner" attack.
+ if (pinned[us] != EmptyBoardBB && !bit_is_set(pinners[us], to))
+ attackers &= ~pinned[us];
+
+ // Remove opponent pinned pieces from attacks if the moving piece is not
+ // a pinner, otherwise we could remove a piece that is no more pinned
+ // due to our pinner piece is moving away.
+ if (pinned[them] != EmptyBoardBB && !bit_is_set(pinners[them], from))
+ attackers &= ~pinned[them];
+
+ if (from != SQ_NONE)
+ break;
+
+ // If we don't have any attacker we are finished
+ if ((attackers & pieces_of_color(us)) == EmptyBoardBB)
+ return 0;
+
+ // Locate the least valuable attacker to the destination square
+ // and use it to initialize from square.
+ PieceType pt;
+ for (pt = PAWN; !(attackers & pieces_of_color_and_type(us, pt)); pt++)
+ assert(pt < KING);
+
+ from = first_1(attackers & pieces_of_color_and_type(us, pt));
+ piece = piece_on(from);
+ }
+
+ // If the opponent has no attackers we are finished
+ if ((attackers & pieces_of_color(them)) == EmptyBoardBB)
+ return seeValues[capture];
+
+ attackers &= occ; // Remove the moving piece