/// computes bitboards relative to that color only, the other computes both
/// colors. Bitboard checkersBB must be already updated.
-void Position::find_hidden_checks(Color us) {
+void Position::find_hidden_checks(Color us, unsigned int types) {
Bitboard p1, p2;
Color them = opposite_color(us);
Square ksq = king_square(them);
- st->pinned[them] = hidden_checks<ROOK, true>(them, ksq, p1) | hidden_checks<BISHOP, true>(them, ksq, p2);
- st->pinners[them] = p1 | p2;
- st->dcCandidates[us] = hidden_checks<ROOK, false>(us, ksq, p1) | hidden_checks<BISHOP, false>(us, ksq, p2);
+ if (types & Pinned)
+ {
+ st->pinned[them] = hidden_checks<ROOK, true>(them, ksq, p1) | hidden_checks<BISHOP, true>(them, ksq, p2);
+ st->pinners[them] = p1 | p2;
+ }
+ if (types & DcCandidates)
+ st->dcCandidates[us] = hidden_checks<ROOK, false>(us, ksq, p1) | hidden_checks<BISHOP, false>(us, ksq, p2);
}
void Position::find_hidden_checks() {
for (Color c = WHITE; c <= BLACK; c++)
- find_hidden_checks(c);
+ find_hidden_checks(c, Pinned | DcCandidates);
}
// otherwise skip because our dcCandidates and opponent pinned pieces are not changed.
if ( (moveSquares & RookPseudoAttacks[ksq]) && (checkerMoved || (rooks_and_queens(us) & RookPseudoAttacks[ksq]))
|| (moveSquares & BishopPseudoAttacks[ksq]) && (checkerMoved || (bishops_and_queens(us) & BishopPseudoAttacks[ksq])))
- find_hidden_checks(us);
+ find_hidden_checks(us, Pinned | DcCandidates);
ksq = king_square(us);
if (ksq == to)
{
- find_hidden_checks(them);
+ find_hidden_checks(them, Pinned | DcCandidates);
return;
}
// It is possible that we have captured an opponent hidden checker?
- Bitboard checkerCaptured = (st->dcCandidates[them] | st->pinners[us]) && st->capture;
+ Bitboard checkerCaptured = st->capture && (st->dcCandidates[them] || bit_is_set(st->pinners[us], to));
// If we are moving from/to an our king attack direction and there was/is some possible
// opponent hidden checker then calculate the position otherwise skip because opponent
// dcCandidates and our pinned pieces are not changed.
if ( (moveSquares & RookPseudoAttacks[ksq]) && (checkerCaptured || (rooks_and_queens(them) & RookPseudoAttacks[ksq]))
|| (moveSquares & BishopPseudoAttacks[ksq]) && (checkerCaptured || (bishops_and_queens(them) & BishopPseudoAttacks[ksq])))
- find_hidden_checks(them);
+ {
+
+ // If we don't have opponent dc candidates and we are moving in the
+ // attack line then won't be dc candidates also after the move.
+ if ( st->dcCandidates[them]
+ || bit_is_set(RookPseudoAttacks[ksq], from)
+ || bit_is_set(BishopPseudoAttacks[ksq], from))
+
+ find_hidden_checks(them, Pinned | DcCandidates);
+ else
+ find_hidden_checks(them, Pinned);
+ }
}