- // Case 2: If the threatened piece has value less than or equal to the
- // value of the threatening piece, don't prune moves which defend it.
- if ( pos.is_capture(threat)
- && ( PieceValue[MG][pos.piece_on(tfrom)] >= PieceValue[MG][pos.piece_on(tto)]
- || type_of(pos.piece_on(tfrom)) == KING)
- && pos.move_attacks_square(m, tto))
- return true;
+ // If the threatened piece has value less than or equal to the value of the
+ // threat piece, don't prune moves which defend it.
+ if ( pos.is_capture(second)
+ && ( PieceValue[MG][pos.piece_on(m2from)] >= PieceValue[MG][pos.piece_on(m2to)]
+ || type_of(pos.piece_on(m2from)) == KING))
+ {
+ // Update occupancy as if the piece and the threat are moving
+ Bitboard occ = pos.pieces() ^ m1from ^ m1to ^ m2from;
+ Piece piece = pos.piece_on(m1from);
+
+ // The moved piece attacks the square 'tto' ?
+ if (pos.attacks_from(piece, m1to, occ) & m2to)
+ return true;