mirror of
https://github.com/sockspls/badfish
synced 2025-05-01 09:13:08 +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:
parent
2f2f45f9f4
commit
7a9f67747f
2 changed files with 15 additions and 16 deletions
|
@ -92,10 +92,9 @@ public:
|
||||||
|
|
||||||
// Position representation
|
// Position representation
|
||||||
Bitboard pieces(PieceType pt) const;
|
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) const;
|
||||||
Bitboard pieces(Color c, PieceType pt) const;
|
template<typename ...PieceTypes> Bitboard pieces(Color c, PieceTypes... pts) const;
|
||||||
Bitboard pieces(Color c, PieceType pt1, PieceType pt2) const;
|
|
||||||
Piece piece_on(Square s) const;
|
Piece piece_on(Square s) const;
|
||||||
Square ep_square() const;
|
Square ep_square() const;
|
||||||
bool empty(Square s) const;
|
bool empty(Square s) const;
|
||||||
|
@ -229,20 +228,18 @@ inline Bitboard Position::pieces(PieceType pt = ALL_PIECES) const {
|
||||||
return byTypeBB[pt];
|
return byTypeBB[pt];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard Position::pieces(PieceType pt1, PieceType pt2) const {
|
template<typename ...PieceTypes>
|
||||||
return pieces(pt1) | pieces(pt2);
|
inline Bitboard Position::pieces(PieceType pt, PieceTypes... pts) const {
|
||||||
|
return pieces(pt) | pieces(pts...);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard Position::pieces(Color c) const {
|
inline Bitboard Position::pieces(Color c) const {
|
||||||
return byColorBB[c];
|
return byColorBB[c];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard Position::pieces(Color c, PieceType pt) const {
|
template<typename ...PieceTypes>
|
||||||
return pieces(c) & pieces(pt);
|
inline Bitboard Position::pieces(Color c, PieceTypes... pts) const {
|
||||||
}
|
return pieces(c) & pieces(pts...);
|
||||||
|
|
||||||
inline Bitboard Position::pieces(Color c, PieceType pt1, PieceType pt2) const {
|
|
||||||
return pieces(c) & (pieces(pt1) | pieces(pt2));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<PieceType Pt> inline int Position::count(Color c) const {
|
template<PieceType Pt> inline int Position::count(Color c) const {
|
||||||
|
|
|
@ -1018,16 +1018,18 @@ moves_loop: // When in check, search starts here
|
||||||
{
|
{
|
||||||
if (depth < 2 - capture)
|
if (depth < 2 - capture)
|
||||||
continue;
|
continue;
|
||||||
// don't prune move if a heavy enemy piece (KQR) is under attack after the exchanges
|
// Don't prune the move if opp. King/Queen/Rook is attacked by a slider after the exchanges.
|
||||||
Bitboard leftEnemies = (pos.pieces(~us, QUEEN, ROOK) | pos.pieces(~us, KING)) & occupied;
|
// 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;
|
Bitboard attacks = 0;
|
||||||
occupied |= to_sq(move);
|
occupied |= to_sq(move);
|
||||||
while (leftEnemies && !attacks)
|
while (leftEnemies && !attacks)
|
||||||
{
|
{
|
||||||
Square sq = pop_lsb(leftEnemies);
|
Square sq = pop_lsb(leftEnemies);
|
||||||
attacks |= pos.attackers_to(sq, occupied) & pos.pieces(us) & occupied;
|
attacks = pos.attackers_to(sq, occupied) & pos.pieces(us) & occupied;
|
||||||
// exclude Queen/Rook(s) which were already threatened before SEE
|
// 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))))
|
if (attacks && sq != pos.square<KING>(~us) && (pos.attackers_to(sq, pos.pieces()) & pos.pieces(us)))
|
||||||
attacks = 0;
|
attacks = 0;
|
||||||
}
|
}
|
||||||
if (!attacks)
|
if (!attacks)
|
||||||
|
|
Loading…
Add table
Reference in a new issue