- return kingSquares[Us] == ksq && castleRights[Us] == pos.can_castle(Us)
- ? kingSafety[Us] : update_safety<Us>(pos, ksq);
+ int pawns_on_same_color_squares(Color c, Square s) const {
+ return pawnsOnSquares[c][bool(DarkSquares & s)];
+ }
+
+ template<Color Us>
+ Score king_safety(const Position& pos, Square ksq) {
+ return kingSquares[Us] == ksq && castlingRights[Us] == pos.can_castle(Us)
+ ? kingSafety[Us] : (kingSafety[Us] = do_king_safety<Us>(pos, ksq));