+ // max_threat() is a helper function to calculate the score of a set of threats.
+ // The set of threatened pieces is in the "targets" parameter, and we return
+ // the value of the threat on the biggest piece.
+
+ template<Color Us> FORCE_INLINE
+ Score max_threat(const Bitboard targets, const Position& pos, const Score threat_values[]) {
+
+ const Color Them = (Us == WHITE ? BLACK : WHITE);
+
+ PieceType threat = PAWN;
+ if (targets & pos.pieces(Them, KNIGHT)) threat = KNIGHT;
+ if (targets & pos.pieces(Them, BISHOP)) threat = BISHOP;
+ if (targets & pos.pieces(Them, ROOK)) threat = ROOK;
+ if (targets & pos.pieces(Them, QUEEN)) threat = QUEEN;
+
+ return threat_values[threat];
+ }