mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 16:53:09 +00:00
Fix wrong condition in PawnEntry::king_safety()
Since revision 374c9e6b63
we use also castling information to calculate king safety.
So before to reuse the cached king safety score we have to
veify not only king position, but also castling rights are
the same of the pre-calculated ones.
This is a very subtle bug, found only becuase even after
previous patch, consecutives runs of 'bench' _still_ showed
different numbers. Pawn tables are not cleared between 'bench'
runs and in the second run a king safety score, previously
evaluated under some castling rights, was reused by another
position with different castling rights instead of being
recalculated from scratch.
Bug spotted and tracked down by Balint Pfliegel
Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
8b00e50cb7
commit
2aac860db3
3 changed files with 8 additions and 5 deletions
|
@ -260,6 +260,7 @@ template<Color Us>
|
|||
Score PawnEntry::update_safety(const Position& pos, Square ksq) {
|
||||
|
||||
kingSquares[Us] = ksq;
|
||||
castleRights[Us] = pos.can_castle(Us);
|
||||
|
||||
if (relative_rank(Us, ksq) > RANK_4)
|
||||
return kingSafety[Us] = SCORE_ZERO;
|
||||
|
|
|
@ -59,6 +59,7 @@ private:
|
|||
Bitboard passedPawns[2];
|
||||
Bitboard pawnAttacks[2];
|
||||
Square kingSquares[2];
|
||||
int castleRights[2];
|
||||
Score value;
|
||||
int halfOpenFiles[2];
|
||||
Score kingSafety[2];
|
||||
|
@ -106,7 +107,8 @@ inline int PawnEntry::has_open_file_to_right(Color c, File f) const {
|
|||
|
||||
template<Color Us>
|
||||
inline Score PawnEntry::king_safety(const Position& pos, Square ksq) {
|
||||
return kingSquares[Us] == ksq ? kingSafety[Us] : update_safety<Us>(pos, ksq);
|
||||
return kingSquares[Us] == ksq && castleRights[Us] == pos.can_castle(Us)
|
||||
? kingSafety[Us] : update_safety<Us>(pos, ksq);
|
||||
}
|
||||
|
||||
#endif // !defined(PAWNS_H_INCLUDED)
|
||||
|
|
|
@ -111,8 +111,8 @@ public:
|
|||
int piece_count(Color c, PieceType pt) const;
|
||||
|
||||
// Castling
|
||||
bool can_castle(CastleRight f) const;
|
||||
bool can_castle(Color c) const;
|
||||
int can_castle(CastleRight f) const;
|
||||
int can_castle(Color c) const;
|
||||
bool castle_impeded(Color c, CastlingSide s) const;
|
||||
Square castle_rook_square(Color c, CastlingSide s) const;
|
||||
|
||||
|
@ -297,11 +297,11 @@ inline Square Position::king_square(Color c) const {
|
|||
return pieceList[c][KING][0];
|
||||
}
|
||||
|
||||
inline bool Position::can_castle(CastleRight f) const {
|
||||
inline int Position::can_castle(CastleRight f) const {
|
||||
return st->castleRights & f;
|
||||
}
|
||||
|
||||
inline bool Position::can_castle(Color c) const {
|
||||
inline int Position::can_castle(Color c) const {
|
||||
return st->castleRights & ((WHITE_OO | WHITE_OOO) << c);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue