- // Analyse enemy's safe distance checks
- safe = ~(pos.pieces_of_color(Them) | ei.attacked_by(Us));
-
- b1 = pos.attacks_from<ROOK>(ksq) & safe;
- b2 = pos.attacks_from<BISHOP>(ksq) & safe;
-
- // Enemy rooks safe checks
- b = b1 & ei.attacked_by(Them, ROOK);
- if (b)
- attackUnits += RookCheckBonus * count_1s_max_15<HasPopCnt>(b);
-
- // Enemy bishops safe checks
- b = b2 & ei.attacked_by(Them, BISHOP);
- if (b)
- attackUnits += BishopCheckBonus * count_1s_max_15<HasPopCnt>(b);
-
- // Enemy queens safe checks
- b = (b1 | b2) & ei.attacked_by(Them, QUEEN);
- if (b)
- attackUnits += QueenCheckBonus * count_1s_max_15<HasPopCnt>(b);
-
- // Enemy knights safe checks
- b = pos.attacks_from<KNIGHT>(ksq) & ei.attacked_by(Them, KNIGHT) & safe;
- if (b)
- attackUnits += KnightCheckBonus * count_1s_max_15<HasPopCnt>(b);
-
- // Analyse discovered checks (only for non-pawns right now, consider
- // adding pawns later).
- b = pos.discovered_check_candidates(Them) & ~pos.pieces(PAWN);
- if (b)
- attackUnits += DiscoveredCheckBonus * count_1s_max_15<HasPopCnt>(b) * (sente ? 2 : 1);
-
- // Has a mate threat been found? We don't do anything here if the
- // side with the mating move is the side to move, because in that
- // case the mating side will get a huge bonus at the end of the main
- // evaluation function instead.
- if (ei.mateThreat[Them] != MOVE_NONE)
- attackUnits += MateThreatBonus;
-
- // Ensure that attackUnits is between 0 and 99, in order to avoid array
- // out of bounds errors.
- attackUnits = Min(99, Max(0, attackUnits));
-
- // Finally, extract the king danger score from the KingDangerTable[] array.
- // Subtract the score from evaluation, and set ei.futilityMargin[].
- // The reason for storing the king danger score to futility margin
- // is that the king danger scores can sometimes be very big, and that
- // capturing a single attacking piece can therefore result in a score
- // change far bigger than the value of the captured piece.
- ei.value -= Sign[Us] * KingDangerTable[Us][attackUnits];
- ei.futilityMargin[Us] = mg_value(KingDangerTable[Us][attackUnits]);
+ // Enemy bishops safe checks
+ b = b2 & ei.attacked_by(Them, BISHOP);
+ if (b)
+ attackUnits += BishopCheckBonus * count_1s_max_15<HasPopCnt>(b);
+
+ // Enemy knights safe checks
+ b = pos.attacks_from<KNIGHT>(ksq) & ei.attacked_by(Them, KNIGHT) & safe;
+ if (b)
+ attackUnits += KnightCheckBonus * count_1s_max_15<HasPopCnt>(b);
+
+ // To index KingDangerTable[] attackUnits must be in [0, 99] range
+ attackUnits = Min(99, Max(0, attackUnits));
+
+ // Finally, extract the king danger score from the KingDangerTable[]
+ // array and subtract the score from evaluation. Set also ei.kingDanger[]
+ // value that will be used for pruning because this value can sometimes
+ // be very big, and so capturing a single attacking piece can therefore
+ // result in a score change far bigger than the value of the captured piece.
+ ei.value -= Sign[Us] * KingDangerTable[Us][attackUnits];
+ ei.kingDanger[Us] = mg_value(KingDangerTable[Us][attackUnits]);