X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fposition.cpp;h=ed7510101de89fbbd38270113019d82b710d8b7a;hp=83a83c1887eddbfa7731c1f1b537a5d995822fba;hb=a188a047ab79a742e55f157f29e30299baafa7d0;hpb=1d2247aea39074d8ecea4a5ce81b1cf85165538e diff --git a/src/position.cpp b/src/position.cpp index 83a83c18..ed751010 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -317,6 +317,25 @@ void Position::copy(const Position &pos) { } +/// Position::update_checkers() updates checkers info, used in do_move() +template +inline void Position::update_checkers(Bitboard* pCheckersBB, Square ksq, Square from, + Square to, Bitboard dcCandidates) { + + if (Piece != KING && bit_is_set(piece_attacks(ksq), to)) + set_bit(pCheckersBB, to); + + if (Piece != QUEEN && bit_is_set(dcCandidates, from)) + { + if (Piece != ROOK) + (*pCheckersBB) |= (piece_attacks(ksq) & rooks_and_queens(side_to_move())); + + if (Piece != BISHOP) + (*pCheckersBB) |= (piece_attacks(ksq) & bishops_and_queens(side_to_move())); + } +} + + /// Position:pinned_pieces() returns a bitboard of all pinned (against the /// king) pieces for the given color. Bitboard Position::pinned_pieces(Color c) const { @@ -710,22 +729,6 @@ void Position::restore(const UndoInfo& u) { // u.capture is restored in undo_move() } -template -inline void Position::update_checkers(Bitboard* pCheckersBB, Square ksq, Square from, Square to, Bitboard dcCandidates) { - - if (Piece != KING && bit_is_set(piece_attacks(ksq), to)) - set_bit(pCheckersBB, to); - - if (Piece != QUEEN && bit_is_set(dcCandidates, from)) - { - if (Piece != ROOK) - (*pCheckersBB) |= (piece_attacks(ksq) & rooks_and_queens(side_to_move())); - - if (Piece != BISHOP) - (*pCheckersBB) |= (piece_attacks(ksq) & bishops_and_queens(side_to_move())); - } -} - /// Position::do_move() makes a move, and backs up all information necessary /// to undo the move to an UndoInfo object. The move is assumed to be legal. /// Pseudo-legal moves should be filtered out before this function is called. @@ -849,12 +852,7 @@ void Position::do_move(Move m, UndoInfo& u, Bitboard dcCandidates) { switch (piece) { case PAWN: - if (bit_is_set(pawn_attacks(them, ksq), to)) - set_bit(&checkersBB, to); - - if (bit_is_set(dcCandidates, from)) - checkersBB |= ( (piece_attacks(ksq) & rooks_and_queens(us)) - |(piece_attacks(ksq) & bishops_and_queens(us))); + update_checkers(&checkersBB, ksq, from, to, dcCandidates); break; case KNIGHT: