-
-/// Position:hidden_checks<>() returns a bitboard of all pinned (against the
-/// king) pieces for the given color and for the given pinner type. Or, when
-/// template parameter FindPinned is false, the pinned pieces of opposite color
-/// that are, indeed, the pieces candidate for a discovery check.
-template<PieceType Piece, bool FindPinned>
-Bitboard Position::hidden_checks(Color c, Square ksq) const {
-
- Square s;
- Bitboard sliders, result = EmptyBoardBB;
-
- if (Piece == ROOK) // Resolved at compile time
- sliders = rooks_and_queens(FindPinned ? opposite_color(c) : c) & RookPseudoAttacks[ksq];
- else
- sliders = bishops_and_queens(FindPinned ? opposite_color(c) : c) & BishopPseudoAttacks[ksq];
-
- if (sliders && (!FindPinned || (sliders & ~checkersBB)))
- {
- // King blockers are candidate pinned pieces
- Bitboard candidate_pinned = piece_attacks<Piece>(ksq) & pieces_of_color(c);
-
- // Pinners are sliders, not checkers, that give check when
- // candidate pinned are removed.
- Bitboard pinners = (FindPinned ? sliders & ~checkersBB : sliders);
-
- if (Piece == ROOK)
- pinners &= rook_attacks_bb(ksq, occupied_squares() ^ candidate_pinned);
- else
- pinners &= bishop_attacks_bb(ksq, occupied_squares() ^ candidate_pinned);
-
- // Finally for each pinner find the corresponding pinned piece (if same color of king)
- // or discovery checker (if opposite color) among the candidates.
- while (pinners)
- {
- s = pop_1st_bit(&pinners);
- result |= (squares_between(s, ksq) & candidate_pinned);
- }
- }
- return result;
-}
-
-