- newSt.key = st->key;
- newSt.pawnKey = st->pawnKey;
- newSt.materialKey = st->materialKey;
- newSt.castleRights = st->castleRights;
- newSt.rule50 = st->rule50;
- newSt.epSquare = st->epSquare;
- newSt.mgValue = st->mgValue;
- newSt.egValue = st->egValue;
- newSt.capture = NO_PIECE_TYPE;
- newSt.previous = st;
+ if (!outsideChecker || st->pinned[them])
+ find_hidden_checks(us, Pinned);
+
+ if (!outsideChecker || st->dcCandidates[us] || bit_is_set(st->pinned[them], to))
+ find_hidden_checks(us, DcCandidates);
+ }
+
+ ksq = king_square(us);
+
+ if (ksq == to)
+ {
+ find_hidden_checks(them, Pinned | DcCandidates);
+ return;
+ }
+
+ // It is possible that we have captured an opponent hidden checker?
+ 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, Pinned);
+
+ // If we don't have opponent dc candidates and we are moving in the
+ // attack line then won't be any dc candidates also after the move.
+ if ( st->dcCandidates[them]
+ || (bit_is_set(RookPseudoAttacks[ksq], from) && (rooks_and_queens(them) & RookPseudoAttacks[ksq]))
+ || (bit_is_set(BishopPseudoAttacks[ksq], from) && (bishops_and_queens(them) & BishopPseudoAttacks[ksq])))
+ find_hidden_checks(them, DcCandidates);
+ }