1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-04-30 08:43: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:
Marco Costalba 2009-09-20 09:43:28 +01:00
parent 0e0adfe2e1
commit f74f42b298
4 changed files with 23 additions and 34 deletions

View file

@ -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 // 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) && pos.pl_move_is_legal(m, pinned)
&& !move_is_promotion(m)); && !move_is_promotion(m));
} }

View file

@ -392,23 +392,22 @@ Bitboard Position::attackers_to(Square s) const {
| (piece_attacks<KING>(s) & pieces(KING)); | (piece_attacks<KING>(s) & pieces(KING));
} }
/// Position::piece_attacks_square() tests whether the piece on square f /// Position::piece_attacks() computes a bitboard of all attacks
/// attacks square t. /// 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(s));
assert(square_is_ok(t));
switch (p) switch (p)
{ {
case WP: return pawn_attacks_square(f, t, WHITE); case WP: return pawn_attacks(s, WHITE);
case BP: return pawn_attacks_square(f, t, BLACK); case BP: return pawn_attacks(s, BLACK);
case WN: case BN: return piece_attacks_square<KNIGHT>(f, t); case WN: case BN: return piece_attacks<KNIGHT>(s);
case WB: case BB: return piece_attacks_square<BISHOP>(f, t); case WB: case BB: return piece_attacks<BISHOP>(s);
case WR: case BR: return piece_attacks_square<ROOK>(f, t); case WR: case BR: return piece_attacks<ROOK>(s);
case WQ: case BQ: return piece_attacks_square<QUEEN>(f, t); case WQ: case BQ: return piece_attacks<QUEEN>(s);
case WK: case BK: return piece_attacks_square<KING>(f, t); case WK: case BK: return piece_attacks<KING>(s);
default: break; default: break;
} }
return false; return false;
@ -427,7 +426,7 @@ bool Position::move_attacks_square(Move m, Square s) const {
assert(square_is_occupied(f)); 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; return true;
// Move the piece and scan for X-ray attacks behind it // Move the piece and scan for X-ray attacks behind it

View file

@ -198,13 +198,9 @@ public:
// Attack information to a given square // Attack information to a given square
Bitboard attackers_to(Square s) const; Bitboard attackers_to(Square s) const;
Bitboard attackers_to(Square s, Color c) 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; Bitboard pawn_attacks(Square s, Color c) const;
template<PieceType> Bitboard piece_attacks(Square s) 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;
// Properties of moves // Properties of moves
bool pl_move_is_legal(Move m) const; bool pl_move_is_legal(Move m) const;
@ -474,15 +470,6 @@ inline bool Position::is_check() const {
return st->checkersBB != EmptyBoardBB; 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 { inline Bitboard Position::attackers_to(Square s, Color c) const {
return attackers_to(s) & pieces_of_color(c); return attackers_to(s) & pieces_of_color(c);

View file

@ -2153,7 +2153,9 @@ namespace {
// the second move is assumed to be a move from the current position. // the second move is assumed to be a move from the current position.
bool connected_moves(const Position& pos, Move m1, Move m2) { bool connected_moves(const Position& pos, Move m1, Move m2) {
Square f1, t1, f2, t2; Square f1, t1, f2, t2;
Piece p;
assert(move_is_ok(m1)); assert(move_is_ok(m1));
assert(move_is_ok(m2)); assert(move_is_ok(m2));
@ -2179,11 +2181,12 @@ namespace {
return true; return true;
// Case 4: The destination square for m2 is attacked by the moving piece in m1 // 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; return true;
// Case 5: Discovered check, checking piece is the piece moved in m1 // 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())), f2)
&& !bit_is_set(squares_between(t1, pos.king_square(pos.side_to_move())), t2)) && !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(); Color us = pos.side_to_move();
Square ksq = pos.king_square(us); Square ksq = pos.king_square(us);
clear_bit(&occ, f2); 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)) if (bit_is_set(bishop_attacks_bb(ksq, occ), t1))
return true; 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)) if (bit_is_set(rook_attacks_bb(ksq, occ), t1))
return true; return true;
} }
else 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)) if (bit_is_set(queen_attacks_bb(ksq, occ), t1))
return true; return true;
} }