- // yields_to_threat() tests whether the move at previous ply yields to the so
- // called threat move (the best move returned from a null search that fails
- // low). Here 'yields to' means that the move somehow made the threat possible
- // for instance if the moving piece is the same in both moves.
-
- bool yields_to_threat(const Position& pos, Move move, Move threat) {
-
- assert(is_ok(move));
- assert(is_ok(threat));
- assert(color_of(pos.piece_on(from_sq(threat))) == ~pos.side_to_move());
-
- Square mfrom = from_sq(move);
- Square mto = to_sq(move);
- Square tfrom = from_sq(threat);
- Square tto = to_sq(threat);
-
- // The piece is the same or threat's destination was vacated by the move
- if (mto == tfrom || tto == mfrom)
- return true;
-
- // Threat moves through the vacated square
- if (between_bb(tfrom, tto) & mfrom)
- return true;
-
- // Threat's destination is defended by the move's piece
- Bitboard matt = pos.attacks_from(pos.piece_on(mto), mto, pos.pieces() ^ tfrom);
- if (matt & tto)
- return true;
-
- // Threat gives a discovered check through the move's checking piece
- if (matt & pos.king_square(pos.side_to_move()))
- {
- assert(between_bb(mto, pos.king_square(pos.side_to_move())) & tfrom);
- return true;
- }
-
- return false;
- }
-
-
- // prevents_threat() tests whether a move is able to defend against the so
- // called threat move (the best move returned from a null search that fails
- // low). In this case will not be pruned.