mirror of
https://github.com/sockspls/badfish
synced 2025-05-01 17:19:36 +00:00
Retire move_attacks_square()
There is only one call site. This patch is a preparation for the next one that will affect functionality. No functional change.
This commit is contained in:
parent
13f90a30ef
commit
4e31c39a64
3 changed files with 23 additions and 42 deletions
|
@ -473,37 +473,6 @@ Bitboard Position::attacks_from(Piece p, Square s, Bitboard occ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Position::move_attacks_square() tests whether a move from the current
|
|
||||||
/// position attacks a given square.
|
|
||||||
|
|
||||||
bool Position::move_attacks_square(Move m, Square s) const {
|
|
||||||
|
|
||||||
assert(is_ok(m));
|
|
||||||
assert(is_ok(s));
|
|
||||||
|
|
||||||
Bitboard occ, xray;
|
|
||||||
Square from = from_sq(m);
|
|
||||||
Square to = to_sq(m);
|
|
||||||
Piece piece = piece_moved(m);
|
|
||||||
|
|
||||||
assert(!is_empty(from));
|
|
||||||
|
|
||||||
// Update occupancy as if the piece is moving
|
|
||||||
occ = pieces() ^ from ^ to;
|
|
||||||
|
|
||||||
// The piece moved in 'to' attacks the square 's' ?
|
|
||||||
if (attacks_from(piece, to, occ) & s)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
// Scan for possible X-ray attackers behind the moved piece
|
|
||||||
xray = (attacks_bb< ROOK>(s, occ) & pieces(color_of(piece), QUEEN, ROOK))
|
|
||||||
| (attacks_bb<BISHOP>(s, occ) & pieces(color_of(piece), QUEEN, BISHOP));
|
|
||||||
|
|
||||||
// Verify attackers are triggered by our move and not already existing
|
|
||||||
return xray && (xray ^ (xray & attacks_from<QUEEN>(s)));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// Position::pl_move_is_legal() tests whether a pseudo-legal move is legal
|
/// Position::pl_move_is_legal() tests whether a pseudo-legal move is legal
|
||||||
|
|
||||||
bool Position::pl_move_is_legal(Move m, Bitboard pinned) const {
|
bool Position::pl_move_is_legal(Move m, Bitboard pinned) const {
|
||||||
|
|
|
@ -137,7 +137,6 @@ public:
|
||||||
|
|
||||||
// Properties of moves
|
// Properties of moves
|
||||||
bool move_gives_check(Move m, const CheckInfo& ci) const;
|
bool move_gives_check(Move m, const CheckInfo& ci) const;
|
||||||
bool move_attacks_square(Move m, Square s) const;
|
|
||||||
bool move_is_legal(const Move m) const;
|
bool move_is_legal(const Move m) const;
|
||||||
bool pl_move_is_legal(Move m, Bitboard pinned) const;
|
bool pl_move_is_legal(Move m, Bitboard pinned) const;
|
||||||
bool is_pseudo_legal(const Move m) const;
|
bool is_pseudo_legal(const Move m) const;
|
||||||
|
|
|
@ -1411,12 +1411,10 @@ split_point_start: // At split points actual search starts from here
|
||||||
assert(!pos.is_capture_or_promotion(m));
|
assert(!pos.is_capture_or_promotion(m));
|
||||||
assert(!pos.is_passed_pawn_push(m));
|
assert(!pos.is_passed_pawn_push(m));
|
||||||
|
|
||||||
Square mfrom, mto, tfrom, tto;
|
Square mfrom = from_sq(m);
|
||||||
|
Square mto = to_sq(m);
|
||||||
mfrom = from_sq(m);
|
Square tfrom = from_sq(threat);
|
||||||
mto = to_sq(m);
|
Square tto = to_sq(threat);
|
||||||
tfrom = from_sq(threat);
|
|
||||||
tto = to_sq(threat);
|
|
||||||
|
|
||||||
// Case 1: Don't prune moves which move the threatened piece
|
// Case 1: Don't prune moves which move the threatened piece
|
||||||
if (mfrom == tto)
|
if (mfrom == tto)
|
||||||
|
@ -1426,10 +1424,25 @@ split_point_start: // At split points actual search starts from here
|
||||||
// value of the threatening piece, don't prune moves which defend it.
|
// value of the threatening piece, don't prune moves which defend it.
|
||||||
if ( pos.is_capture(threat)
|
if ( pos.is_capture(threat)
|
||||||
&& ( PieceValue[MG][pos.piece_on(tfrom)] >= PieceValue[MG][pos.piece_on(tto)]
|
&& ( PieceValue[MG][pos.piece_on(tfrom)] >= PieceValue[MG][pos.piece_on(tto)]
|
||||||
|| type_of(pos.piece_on(tfrom)) == KING)
|
|| type_of(pos.piece_on(tfrom)) == KING))
|
||||||
&& pos.move_attacks_square(m, tto))
|
{
|
||||||
|
// Update occupancy as if the piece is moving
|
||||||
|
Bitboard occ = pos.pieces() ^ mfrom ^ mto;
|
||||||
|
Piece piece = pos.piece_on(mfrom);
|
||||||
|
|
||||||
|
// The moved piece attacks the square 'tto' ?
|
||||||
|
if (pos.attacks_from(piece, mto, occ) & tto)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
// Scan for possible X-ray attackers behind the moved piece
|
||||||
|
Bitboard xray = (attacks_bb< ROOK>(tto, occ) & pos.pieces(color_of(piece), QUEEN, ROOK))
|
||||||
|
| (attacks_bb<BISHOP>(tto, occ) & pos.pieces(color_of(piece), QUEEN, BISHOP));
|
||||||
|
|
||||||
|
// Verify attackers are triggered by our move and not already existing
|
||||||
|
if (xray && (xray ^ (xray & pos.attacks_from<QUEEN>(tto))))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// Case 3: If the moving piece in the threatened move is a slider, don't
|
// Case 3: If the moving piece in the threatened move is a slider, don't
|
||||||
// prune safe moves which block its ray.
|
// prune safe moves which block its ray.
|
||||||
if ( piece_is_slider(pos.piece_on(tfrom))
|
if ( piece_is_slider(pos.piece_on(tfrom))
|
||||||
|
|
Loading…
Add table
Reference in a new issue