mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 00:33:09 +00:00
Teach check_blockers to check also non-king pieces
This is a prerequisite for next patch No functional change.
This commit is contained in:
parent
ab0f4c0353
commit
abac509ccb
2 changed files with 15 additions and 16 deletions
|
@ -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<KING>(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;
|
||||
}
|
||||
|
|
|
@ -131,6 +131,7 @@ public:
|
|||
Bitboard attacks_from(Piece pc, Square s) const;
|
||||
template<PieceType> Bitboard attacks_from(Square s) const;
|
||||
template<PieceType> Bitboard attacks_from(Square s, Color c) const;
|
||||
Bitboard slider_blockers(Bitboard target, Bitboard sliders, Square s) const;
|
||||
|
||||
// Properties of moves
|
||||
bool legal(Move m, Bitboard pinned) const;
|
||||
|
@ -186,7 +187,6 @@ private:
|
|||
void set_state(StateInfo* si) const;
|
||||
|
||||
// Other helpers
|
||||
Bitboard check_blockers(Color c, Color kingColor) const;
|
||||
void put_piece(Color c, PieceType pt, Square s);
|
||||
void remove_piece(Color c, PieceType pt, Square s);
|
||||
void move_piece(Color c, PieceType pt, Square from, Square to);
|
||||
|
@ -311,11 +311,11 @@ inline Bitboard Position::checkers() const {
|
|||
}
|
||||
|
||||
inline Bitboard Position::discovered_check_candidates() const {
|
||||
return check_blockers(sideToMove, ~sideToMove);
|
||||
return slider_blockers(pieces(sideToMove), pieces(sideToMove), square<KING>(~sideToMove));
|
||||
}
|
||||
|
||||
inline Bitboard Position::pinned_pieces(Color c) const {
|
||||
return check_blockers(c, c);
|
||||
return slider_blockers(pieces(c), pieces(~c), square<KING>(c));
|
||||
}
|
||||
|
||||
inline bool Position::pawn_passed(Color c, Square s) const {
|
||||
|
|
Loading…
Add table
Reference in a new issue