1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-04-30 08:43:09 +00:00

Rename attacks_to() in attackers_to()

These functions return bitboard of attacking pieces,
not the attacks themselfs so reflect this in the name.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba 2009-09-20 09:31:48 +01:00
parent 049139d025
commit 0e0adfe2e1
4 changed files with 21 additions and 20 deletions

View file

@ -235,7 +235,7 @@ MoveStack* generate_evasions(const Position& pos, MoveStack* mlist, Bitboard pin
// Find squares attacked by slider checkers, we will // Find squares attacked by slider checkers, we will
// remove them from king evasions set so to avoid a couple // remove them from king evasions set so to avoid a couple
// of cycles in the slow king evasions legality check loop // of cycles in the slow king evasions legality check loop
// and to be able to use attacks_to(). // and to be able to use attackers_to().
Bitboard checkers = pos.checkers(); Bitboard checkers = pos.checkers();
Bitboard checkersAttacks = EmptyBoardBB; Bitboard checkersAttacks = EmptyBoardBB;
Bitboard b = checkers & pos.pieces(BISHOP, QUEEN); Bitboard b = checkers & pos.pieces(BISHOP, QUEEN);
@ -257,9 +257,9 @@ MoveStack* generate_evasions(const Position& pos, MoveStack* mlist, Bitboard pin
while (b1) while (b1)
{ {
to = pop_1st_bit(&b1); to = pop_1st_bit(&b1);
// Note that we can use attacks_to() only because we // Note that we can use attackers_to() only because we
// have already removed slider checkers. // have already removed slider checkers.
if (!pos.attacks_to(to, them)) if (!pos.attackers_to(to, them))
(*mlist++).move = make_move(ksq, to); (*mlist++).move = make_move(ksq, to);
} }
@ -441,7 +441,7 @@ bool move_is_legal(const Position& pos, const Move m, Bitboard pinned) {
// is occupied or under attack. // is occupied or under attack.
for (s = Min(from, g1); s <= Max(from, g1); s++) for (s = Min(from, g1); s <= Max(from, g1); s++)
if ( (s != from && s != to && !pos.square_is_empty(s)) if ( (s != from && s != to && !pos.square_is_empty(s))
|| pos.attacks_to(s, them)) || pos.attackers_to(s, them))
illegal = true; illegal = true;
// Check if any of the squares between king and rook // Check if any of the squares between king and rook
@ -472,7 +472,7 @@ bool move_is_legal(const Position& pos, const Move m, Bitboard pinned) {
for (s = Min(from, c1); s <= Max(from, c1); s++) for (s = Min(from, c1); s <= Max(from, c1); s++)
if( (s != from && s != to && !pos.square_is_empty(s)) if( (s != from && s != to && !pos.square_is_empty(s))
|| pos.attacks_to(s, them)) || pos.attackers_to(s, them))
illegal = true; illegal = true;
for (s = Min(to, d1); s <= Max(to, d1); s++) for (s = Min(to, d1); s <= Max(to, d1); s++)
@ -942,7 +942,7 @@ namespace {
// It is a bit complicated to correctly handle Chess960 // It is a bit complicated to correctly handle Chess960
for (s = Min(ksq, s1); s <= Max(ksq, s1); s++) for (s = Min(ksq, s1); s <= Max(ksq, s1); s++)
if ( (s != ksq && s != rsq && pos.square_is_occupied(s)) if ( (s != ksq && s != rsq && pos.square_is_occupied(s))
|| pos.attacks_to(s, them)) || pos.attackers_to(s, them))
illegal = true; illegal = true;
for (s = Min(rsq, s2); s <= Max(rsq, s2); s++) for (s = Min(rsq, s2); s <= Max(rsq, s2); s++)

View file

@ -379,10 +379,10 @@ Bitboard Position::discovered_check_candidates(Color c) const {
return hidden_checkers<false>(c); return hidden_checkers<false>(c);
} }
/// Position::attacks_to() computes a bitboard containing all pieces which /// Position::attackers_to() computes a bitboard containing all pieces which
/// attacks a given square. /// attacks a given square.
Bitboard Position::attacks_to(Square s) const { Bitboard Position::attackers_to(Square s) const {
return (pawn_attacks(s, BLACK) & pieces(PAWN, WHITE)) return (pawn_attacks(s, BLACK) & pieces(PAWN, WHITE))
| (pawn_attacks(s, WHITE) & pieces(PAWN, BLACK)) | (pawn_attacks(s, WHITE) & pieces(PAWN, BLACK))
@ -446,14 +446,14 @@ bool Position::move_attacks_square(Move m, Square s) const {
/// Position::find_checkers() computes the checkersBB bitboard, which /// Position::find_checkers() computes the checkersBB bitboard, which
/// contains a nonzero bit for each checking piece (0, 1 or 2). It /// contains a nonzero bit for each checking piece (0, 1 or 2). It
/// currently works by calling Position::attacks_to, which is probably /// currently works by calling Position::attackers_to, which is probably
/// inefficient. Consider rewriting this function to use the last move /// inefficient. Consider rewriting this function to use the last move
/// played, like in non-bitboard versions of Glaurung. /// played, like in non-bitboard versions of Glaurung.
void Position::find_checkers() { void Position::find_checkers() {
Color us = side_to_move(); Color us = side_to_move();
st->checkersBB = attacks_to(king_square(us), opposite_color(us)); st->checkersBB = attackers_to(king_square(us), opposite_color(us));
} }
@ -510,7 +510,7 @@ bool Position::pl_move_is_legal(Move m, Bitboard pinned) const {
// If the moving piece is a king, check whether the destination // If the moving piece is a king, check whether the destination
// square is attacked by the opponent. // square is attacked by the opponent.
if (type_of_piece_on(from) == KING) if (type_of_piece_on(from) == KING)
return !attacks_to(move_to(m), opposite_color(us)); return !attackers_to(move_to(m), opposite_color(us));
// A non-king move is legal if and only if it is not pinned or it // A non-king move is legal if and only if it is not pinned or it
// is moving along the ray towards or away from the king. // is moving along the ray towards or away from the king.
@ -864,7 +864,7 @@ void Position::do_move(Move m, StateInfo& newSt, Bitboard dcCandidates) {
// Update checkers bitboard, piece must be already moved // Update checkers bitboard, piece must be already moved
if (ep | pm) if (ep | pm)
st->checkersBB = attacks_to(king_square(them), us); st->checkersBB = attackers_to(king_square(them), us);
else else
{ {
st->checkersBB = EmptyBoardBB; st->checkersBB = EmptyBoardBB;
@ -1041,7 +1041,7 @@ void Position::do_castle_move(Move m) {
st->rule50 = 0; st->rule50 = 0;
// Update checkers BB // Update checkers BB
st->checkersBB = attacks_to(king_square(them), us); st->checkersBB = attackers_to(king_square(them), us);
// Finish // Finish
sideToMove = opposite_color(sideToMove); sideToMove = opposite_color(sideToMove);
@ -1923,7 +1923,7 @@ bool Position::is_ok(int* failedStep) const {
Color us = side_to_move(); Color us = side_to_move();
Color them = opposite_color(us); Color them = opposite_color(us);
Square ksq = king_square(them); Square ksq = king_square(them);
if (attacks_to(ksq, us)) if (attackers_to(ksq, us))
return false; return false;
} }

View file

@ -196,8 +196,8 @@ public:
Square piece_list(Color c, PieceType pt, int index) const; Square piece_list(Color c, PieceType pt, int index) const;
// Attack information to a given square // Attack information to a given square
Bitboard attacks_to(Square s) const; Bitboard attackers_to(Square s) const;
Bitboard attacks_to(Square s, Color c) const; Bitboard attackers_to(Square s, Color c) const;
template<PieceType> Bitboard piece_attacks(Square s) const; template<PieceType> Bitboard piece_attacks(Square s) const;
Bitboard pawn_attacks(Square s, Color c) const; Bitboard pawn_attacks(Square s, Color c) const;
@ -483,9 +483,9 @@ inline Bitboard Position::piece_attacks_square(Square f, Square t) const {
return bit_is_set(piece_attacks<Piece>(f), t); return bit_is_set(piece_attacks<Piece>(f), t);
} }
inline Bitboard Position::attacks_to(Square s, Color c) const { inline Bitboard Position::attackers_to(Square s, Color c) const {
return attacks_to(s) & pieces_of_color(c); return attackers_to(s) & pieces_of_color(c);
} }
inline bool Position::pawn_is_passed(Color c, Square s) const { inline bool Position::pawn_is_passed(Color c, Square s) const {

View file

@ -2439,8 +2439,9 @@ namespace {
n = Slowdown; n = Slowdown;
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
Square s = Square(i&63); Square s = Square(i&63);
if (count_1s(pos.attacks_to(s)) > 63) if (count_1s(pos.attackers_to(s)) > 63)
std::cout << "This can't happen, but I put this string here anyway, in order to prevent the compiler from optimizing away the useless computation." << std::endl; std::cout << "This can't happen, but I put this string here anyway, in order to "
"prevent the compiler from optimizing away the useless computation." << std::endl;
} }
} }