+/// Position::update_hidden_checks() udpates pinned, pinners and dcCandidates
+/// bitboards incrementally, given the move. It is called in do_move and is
+/// faster then find_hidden_checks().
+
+void Position::update_hidden_checks(Square from, Square to) {
+
+ Color us = sideToMove;
+ Color them = opposite_color(us);
+ Square ksq = king_square(opposite_color(us));
+
+ Bitboard moveSquares = EmptyBoardBB;
+ set_bit(&moveSquares, from);
+ set_bit(&moveSquares, to);
+
+ // Our moving piece could have been a possible pinner or hidden checker behind a dcCandidates?
+ bool checkerMoved = (st->dcCandidates[us] | st->pinners[them]) && (moveSquares & sliders());
+
+ // If we are moving from/to an opponent king attack direction and we was a possible hidden checker
+ // or there exsist some possible hidden checker on that line then recalculate the position
+ // 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, Pinned | 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])))
+ {
+
+ // 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);
+ }
+}
+
+
+/// Position::do_move() makes a move, and saves all information necessary
+/// to a StateInfo object. The move is assumed to be legal.