mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 00:33:09 +00:00
Cleanup piece_attacks_square() functions
Most of them are not required to be public and are used in one place only so remove them and use its definitions. Also rename piece_attacks_square() in piece_attacks() to be aligned to the current naming policy. No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
0e0adfe2e1
commit
f74f42b298
4 changed files with 23 additions and 34 deletions
|
@ -557,7 +557,7 @@ bool move_is_legal(const Position& pos, const Move m, Bitboard pinned) {
|
|||
}
|
||||
|
||||
// Luckly we can handle all the other pieces in one go
|
||||
return ( pos.piece_attacks_square(pos.piece_on(from), from, to)
|
||||
return ( bit_is_set(pos.piece_attacks(pc, from), to)
|
||||
&& pos.pl_move_is_legal(m, pinned)
|
||||
&& !move_is_promotion(m));
|
||||
}
|
||||
|
|
|
@ -392,23 +392,22 @@ Bitboard Position::attackers_to(Square s) const {
|
|||
| (piece_attacks<KING>(s) & pieces(KING));
|
||||
}
|
||||
|
||||
/// Position::piece_attacks_square() tests whether the piece on square f
|
||||
/// attacks square t.
|
||||
/// Position::piece_attacks() computes a bitboard of all attacks
|
||||
/// of a given piece put in a given square.
|
||||
|
||||
bool Position::piece_attacks_square(Piece p, Square f, Square t) const {
|
||||
Bitboard Position::piece_attacks(Piece p, Square s) const {
|
||||
|
||||
assert(square_is_ok(f));
|
||||
assert(square_is_ok(t));
|
||||
assert(square_is_ok(s));
|
||||
|
||||
switch (p)
|
||||
{
|
||||
case WP: return pawn_attacks_square(f, t, WHITE);
|
||||
case BP: return pawn_attacks_square(f, t, BLACK);
|
||||
case WN: case BN: return piece_attacks_square<KNIGHT>(f, t);
|
||||
case WB: case BB: return piece_attacks_square<BISHOP>(f, t);
|
||||
case WR: case BR: return piece_attacks_square<ROOK>(f, t);
|
||||
case WQ: case BQ: return piece_attacks_square<QUEEN>(f, t);
|
||||
case WK: case BK: return piece_attacks_square<KING>(f, t);
|
||||
case WP: return pawn_attacks(s, WHITE);
|
||||
case BP: return pawn_attacks(s, BLACK);
|
||||
case WN: case BN: return piece_attacks<KNIGHT>(s);
|
||||
case WB: case BB: return piece_attacks<BISHOP>(s);
|
||||
case WR: case BR: return piece_attacks<ROOK>(s);
|
||||
case WQ: case BQ: return piece_attacks<QUEEN>(s);
|
||||
case WK: case BK: return piece_attacks<KING>(s);
|
||||
default: break;
|
||||
}
|
||||
return false;
|
||||
|
@ -427,7 +426,7 @@ bool Position::move_attacks_square(Move m, Square s) const {
|
|||
|
||||
assert(square_is_occupied(f));
|
||||
|
||||
if (piece_attacks_square(piece_on(f), t, s))
|
||||
if (bit_is_set(piece_attacks(piece_on(f), t), s))
|
||||
return true;
|
||||
|
||||
// Move the piece and scan for X-ray attacks behind it
|
||||
|
|
|
@ -198,13 +198,9 @@ public:
|
|||
// Attack information to a given square
|
||||
Bitboard attackers_to(Square s) const;
|
||||
Bitboard attackers_to(Square s, Color c) const;
|
||||
template<PieceType> Bitboard piece_attacks(Square s) const;
|
||||
Bitboard piece_attacks(Piece p, Square s) const;
|
||||
Bitboard pawn_attacks(Square s, Color c) const;
|
||||
|
||||
// Attack information to a given square from another given square
|
||||
template<PieceType> Bitboard piece_attacks_square(Square f, Square t) const; // Dispatch at compile-time
|
||||
bool piece_attacks_square(Piece p, Square f, Square t) const; // Dispatch at run-time
|
||||
bool pawn_attacks_square(Square f, Square t, Color c) const;
|
||||
template<PieceType> Bitboard piece_attacks(Square s) const;
|
||||
|
||||
// Properties of moves
|
||||
bool pl_move_is_legal(Move m) const;
|
||||
|
@ -474,15 +470,6 @@ inline bool Position::is_check() const {
|
|||
return st->checkersBB != EmptyBoardBB;
|
||||
}
|
||||
|
||||
inline bool Position::pawn_attacks_square(Square f, Square t, Color c) const {
|
||||
return bit_is_set(pawn_attacks(f, c), t);
|
||||
}
|
||||
|
||||
template<PieceType Piece>
|
||||
inline Bitboard Position::piece_attacks_square(Square f, Square t) const {
|
||||
return bit_is_set(piece_attacks<Piece>(f), t);
|
||||
}
|
||||
|
||||
inline Bitboard Position::attackers_to(Square s, Color c) const {
|
||||
|
||||
return attackers_to(s) & pieces_of_color(c);
|
||||
|
|
|
@ -2153,7 +2153,9 @@ namespace {
|
|||
// the second move is assumed to be a move from the current position.
|
||||
|
||||
bool connected_moves(const Position& pos, Move m1, Move m2) {
|
||||
|
||||
Square f1, t1, f2, t2;
|
||||
Piece p;
|
||||
|
||||
assert(move_is_ok(m1));
|
||||
assert(move_is_ok(m2));
|
||||
|
@ -2179,11 +2181,12 @@ namespace {
|
|||
return true;
|
||||
|
||||
// Case 4: The destination square for m2 is attacked by the moving piece in m1
|
||||
if (pos.piece_attacks_square(pos.piece_on(t1), t1, t2))
|
||||
p = pos.piece_on(t1);
|
||||
if (bit_is_set(pos.piece_attacks(p, t1), t2))
|
||||
return true;
|
||||
|
||||
// Case 5: Discovered check, checking piece is the piece moved in m1
|
||||
if ( piece_is_slider(pos.piece_on(t1))
|
||||
if ( piece_is_slider(p)
|
||||
&& bit_is_set(squares_between(t1, pos.king_square(pos.side_to_move())), f2)
|
||||
&& !bit_is_set(squares_between(t1, pos.king_square(pos.side_to_move())), t2))
|
||||
{
|
||||
|
@ -2191,19 +2194,19 @@ namespace {
|
|||
Color us = pos.side_to_move();
|
||||
Square ksq = pos.king_square(us);
|
||||
clear_bit(&occ, f2);
|
||||
if (pos.type_of_piece_on(t1) == BISHOP)
|
||||
if (type_of_piece(p) == BISHOP)
|
||||
{
|
||||
if (bit_is_set(bishop_attacks_bb(ksq, occ), t1))
|
||||
return true;
|
||||
}
|
||||
else if (pos.type_of_piece_on(t1) == ROOK)
|
||||
else if (type_of_piece(p) == ROOK)
|
||||
{
|
||||
if (bit_is_set(rook_attacks_bb(ksq, occ), t1))
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(pos.type_of_piece_on(t1) == QUEEN);
|
||||
assert(type_of_piece(p) == QUEEN);
|
||||
if (bit_is_set(queen_attacks_bb(ksq, occ), t1))
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue