1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-04-30 08:43:09 +00:00

Reduce Position::pieces() overloads

Reduce the number of overloads for pieces() by using a more general template implementation.
Secondly simplify some code in search.cpp using the new general functionality.

TC https://tests.stockfishchess.org/tests/view/642ce27877ff3301150dc193
LLR: 2.94 (-2.94,2.94) <-1.75,0.25>
Total: 269640 W: 71775 L: 71809 D: 126056
Ptnml(0-2): 687, 27294, 78885, 27274, 680

closes https://github.com/official-stockfish/Stockfish/pull/4501

No functional change.
This commit is contained in:
mstembera 2023-04-04 19:44:09 -07:00 committed by Joost VandeVondele
parent 2f2f45f9f4
commit 7a9f67747f
2 changed files with 15 additions and 16 deletions

View file

@ -92,10 +92,9 @@ public:
// Position representation
Bitboard pieces(PieceType pt) const;
Bitboard pieces(PieceType pt1, PieceType pt2) const;
template<typename ...PieceTypes> Bitboard pieces(PieceType pt, PieceTypes... pts) const;
Bitboard pieces(Color c) const;
Bitboard pieces(Color c, PieceType pt) const;
Bitboard pieces(Color c, PieceType pt1, PieceType pt2) const;
template<typename ...PieceTypes> Bitboard pieces(Color c, PieceTypes... pts) const;
Piece piece_on(Square s) const;
Square ep_square() const;
bool empty(Square s) const;
@ -229,20 +228,18 @@ inline Bitboard Position::pieces(PieceType pt = ALL_PIECES) const {
return byTypeBB[pt];
}
inline Bitboard Position::pieces(PieceType pt1, PieceType pt2) const {
return pieces(pt1) | pieces(pt2);
template<typename ...PieceTypes>
inline Bitboard Position::pieces(PieceType pt, PieceTypes... pts) const {
return pieces(pt) | pieces(pts...);
}
inline Bitboard Position::pieces(Color c) const {
return byColorBB[c];
}
inline Bitboard Position::pieces(Color c, PieceType pt) const {
return pieces(c) & pieces(pt);
}
inline Bitboard Position::pieces(Color c, PieceType pt1, PieceType pt2) const {
return pieces(c) & (pieces(pt1) | pieces(pt2));
template<typename ...PieceTypes>
inline Bitboard Position::pieces(Color c, PieceTypes... pts) const {
return pieces(c) & pieces(pts...);
}
template<PieceType Pt> inline int Position::count(Color c) const {

View file

@ -1018,16 +1018,18 @@ moves_loop: // When in check, search starts here
{
if (depth < 2 - capture)
continue;
// don't prune move if a heavy enemy piece (KQR) is under attack after the exchanges
Bitboard leftEnemies = (pos.pieces(~us, QUEEN, ROOK) | pos.pieces(~us, KING)) & occupied;
// Don't prune the move if opp. King/Queen/Rook is attacked by a slider after the exchanges.
// Since in see_ge we don't update occupied when the king recaptures, we also don't prune the
// move when the opp. King gets a discovered slider attack DURING the exchanges.
Bitboard leftEnemies = pos.pieces(~us, ROOK, QUEEN, KING) & occupied;
Bitboard attacks = 0;
occupied |= to_sq(move);
while (leftEnemies && !attacks)
{
Square sq = pop_lsb(leftEnemies);
attacks |= pos.attackers_to(sq, occupied) & pos.pieces(us) & occupied;
// exclude Queen/Rook(s) which were already threatened before SEE
if (attacks && (sq != pos.square<KING>(~us) && (pos.attackers_to(sq, pos.pieces()) & pos.pieces(us))))
attacks = pos.attackers_to(sq, occupied) & pos.pieces(us) & occupied;
// Exclude Queen/Rook(s) which were already threatened before SEE
if (attacks && sq != pos.square<KING>(~us) && (pos.attackers_to(sq, pos.pieces()) & pos.pieces(us)))
attacks = 0;
}
if (!attacks)