From: Marco Costalba Date: Thu, 12 Feb 2009 11:26:23 +0000 (+0100) Subject: Use update_checkers<>() also for PAWN X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=a188a047ab79a742e55f157f29e30299baafa7d0 Use update_checkers<>() also for PAWN No functional change. Signed-off-by: Marco Costalba --- 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: diff --git a/src/position.h b/src/position.h index d05546f7..3822e3bc 100644 --- a/src/position.h +++ b/src/position.h @@ -532,6 +532,11 @@ inline Bitboard Position::pawn_attacks(Color c, Square s) const { return StepAttackBB[pawn_of_color(c)][s]; } +template<> +inline Bitboard Position::piece_attacks(Square s) const { + return StepAttackBB[pawn_of_color(opposite_color(sideToMove))][s]; +} + template<> inline Bitboard Position::piece_attacks(Square s) const { return StepAttackBB[KNIGHT][s];