X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fposition.cpp;h=6022518e80b4b2330975c6a673b98bedf3e60d90;hp=cd91b07fe773e5b9ba766d4055a36867c72b5c5f;hb=f2f3a06a1acfa14b3054bfd73d6c3966c326a7cc;hpb=c73706243672bf36b0fef58e817f843cb341d8ca diff --git a/src/position.cpp b/src/position.cpp index cd91b07f..6022518e 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -420,28 +420,27 @@ Phase Position::game_phase() const { } -/// Position::check_blockers() returns a bitboard of all the pieces with color -/// 'c' that are blocking check on the king with color 'kingColor'. A piece -/// blocks a check if removing that piece from the board would result in a -/// position where the king is in check. A check blocking piece can be either a -/// pinned or a discovered check piece, according if its color 'c' is the same -/// or the opposite of 'kingColor'. +/// Position::slider_blockers() returns a bitboard of all the pieces in 'target' that +/// are blocking attacks on the square 's' from 'sliders'. A piece blocks a slider +/// if removing that piece from the board would result in a position where square 's' +/// is attacked. For example, a king-attack blocking piece can be either a pinned or +/// a discovered check piece, according if its color is the opposite or the same of +/// the color of the slider. -Bitboard Position::check_blockers(Color c, Color kingColor) const { +Bitboard Position::slider_blockers(Bitboard target, Bitboard sliders, Square s) const { Bitboard b, pinners, result = 0; - Square ksq = square(kingColor); - // Pinners are sliders that give check when a pinned piece is removed - pinners = ( (pieces( ROOK, QUEEN) & PseudoAttacks[ROOK ][ksq]) - | (pieces(BISHOP, QUEEN) & PseudoAttacks[BISHOP][ksq])) & pieces(~kingColor); + // Pinners are sliders that attack 's' when a pinned piece is removed + pinners = ( (PseudoAttacks[ROOK ][s] & pieces(QUEEN, ROOK)) + | (PseudoAttacks[BISHOP][s] & pieces(QUEEN, BISHOP))) & sliders; while (pinners) { - b = between_bb(ksq, pop_lsb(&pinners)) & pieces(); + b = between_bb(s, pop_lsb(&pinners)) & pieces(); if (!more_than_one(b)) - result |= b & pieces(c); + result |= b & target; } return result; }