+ if ((b1 | b2) & ei.attackedBy[Them][QUEEN] & safe)
+ kingDanger += QueenCheck;
+
+ // For minors and rooks, also consider the square safe if attacked twice,
+ // and only defended by our queen.
+ safe |= ei.attackedBy2[Them]
+ & ~(ei.attackedBy2[Us] | pos.pieces(Them))
+ & ei.attackedBy[Us][QUEEN];
+
+ // Some other potential checks are also analysed, even from squares
+ // currently occupied by the opponent own pieces, as long as the square
+ // is not attacked by our pawns, and is not occupied by a blocked pawn.
+ other = ~( ei.attackedBy[Us][PAWN]
+ | (pos.pieces(Them, PAWN) & shift<Up>(pos.pieces(PAWN))));
+
+ // Enemy rooks safe and other checks
+ if (b1 & ei.attackedBy[Them][ROOK] & safe)
+ kingDanger += RookCheck;
+
+ else if (b1 & ei.attackedBy[Them][ROOK] & other)
+ score -= OtherCheck;
+
+ // Enemy bishops safe and other checks
+ if (b2 & ei.attackedBy[Them][BISHOP] & safe)
+ kingDanger += BishopCheck;
+
+ else if (b2 & ei.attackedBy[Them][BISHOP] & other)
+ score -= OtherCheck;
+
+ // Enemy knights safe and other checks
+ b = pos.attacks_from<KNIGHT>(ksq) & ei.attackedBy[Them][KNIGHT];
+ if (b & safe)
+ kingDanger += KnightCheck;
+
+ else if (b & other)
+ score -= OtherCheck;
+
+ // Transform the kingDanger units into a Score, and substract it from the evaluation
+ if (kingDanger > 0)
+ score -= make_score(std::min(kingDanger * kingDanger / 4096, 2 * int(BishopValueMg)), 0);
+ }