- /// Rule 1. Using checks to reposition pieces when close to beta
- if (eval + PawnValueMidgame / 4 < beta)
- {
- if (eval + PawnValueMidgame / 4 > bestValue)
- bestValue = eval + PawnValueMidgame / 4;
- }
- else
- return false;
-
- Square from = move_from(move);
- Square to = move_to(move);
- Color oppColor = opposite_color(pos.side_to_move());
- Square oppKing = pos.king_square(oppColor);
-
- Bitboard occ = pos.occupied_squares() & ~(1ULL << from) & ~(1ULL <<oppKing);
- Bitboard oppOcc = pos.pieces_of_color(oppColor) & ~(1ULL <<oppKing);
- Bitboard oldAtt = attacks(pos.piece_on(from), from, occ);
- Bitboard newAtt = attacks(pos.piece_on(from), to, occ);
-
- // Rule 2. Checks which give opponent's king at most one escape square are dangerous
- Bitboard escapeBB = attacks(WK, oppKing, 0) & ~oppOcc & ~newAtt & ~(1ULL << to);
-
- if (!escapeBB)
- return false;
-
- if (!(escapeBB & (escapeBB - 1)))
- return false;
+ bool check_is_dangerous(Position &pos, Move move, Value futilityBase, Value beta, Value *bestValue)
+ {
+ Bitboard b, occ, oldAtt, newAtt, kingAtt;
+ Square from, to, ksq, victimSq;
+ Piece pc;
+ Color them;
+ Value futilityValue, bv = *bestValue;
+
+ from = move_from(move);
+ to = move_to(move);
+ them = opposite_color(pos.side_to_move());
+ ksq = pos.king_square(them);
+ kingAtt = pos.attacks_from<KING>(ksq);
+ pc = pos.piece_on(from);
+
+ occ = pos.occupied_squares() & ~(1ULL << from) & ~(1ULL << ksq);
+ oldAtt = pos.attacks_from(pc, from, occ);
+ newAtt = pos.attacks_from(pc, to, occ);
+
+ // Rule 1. Checks which give opponent's king at most one escape square are dangerous
+ b = kingAtt & ~pos.pieces_of_color(them) & ~newAtt & ~(1ULL << to);
+
+ if (!(b && (b & (b - 1))))
+ return true;