diff --git a/src/pawns.cpp b/src/pawns.cpp index 6897969c..6923d20b 100644 --- a/src/pawns.cpp +++ b/src/pawns.cpp @@ -260,6 +260,7 @@ template 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; diff --git a/src/pawns.h b/src/pawns.h index 0376ce61..4fee9316 100644 --- a/src/pawns.h +++ b/src/pawns.h @@ -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 inline Score PawnEntry::king_safety(const Position& pos, Square ksq) { - return kingSquares[Us] == ksq ? kingSafety[Us] : update_safety(pos, ksq); + return kingSquares[Us] == ksq && castleRights[Us] == pos.can_castle(Us) + ? kingSafety[Us] : update_safety(pos, ksq); } #endif // !defined(PAWNS_H_INCLUDED) diff --git a/src/position.h b/src/position.h index 8f11a394..e67dfbd4 100644 --- a/src/position.h +++ b/src/position.h @@ -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); }