Remove undefined functions sliding_attacks() and ray_attacks()
and retire square_is_attacked(), use the corresponding definition
instead. It is more clear that we are computing full attack
info for the given square.
Alos fix some obsolete comments in move generation functions.
No functional change.
Signed-off-by: Marco Costalba <mcostalba@gmail.com>
/// generate_captures generates() all pseudo-legal captures and queen
/// generate_captures generates() all pseudo-legal captures and queen
-/// promotions. The return value is the number of moves generated.
+/// promotions. Returns a pointer to the end of the move list.
MoveStack* generate_captures(const Position& pos, MoveStack* mlist) {
MoveStack* generate_captures(const Position& pos, MoveStack* mlist) {
/// generate_noncaptures() generates all pseudo-legal non-captures and
/// generate_noncaptures() generates all pseudo-legal non-captures and
-/// underpromotions. The return value is the number of moves generated.
+/// underpromotions. Returns a pointer to the end of the move list.
MoveStack* generate_noncaptures(const Position& pos, MoveStack* mlist) {
MoveStack* generate_noncaptures(const Position& pos, MoveStack* mlist) {
/// generate_non_capture_checks() generates all pseudo-legal non-capturing,
/// generate_non_capture_checks() generates all pseudo-legal non-capturing,
-/// non-promoting checks. It returns the number of generated moves.
+/// non-promoting checks. Returns a pointer to the end of the move list.
MoveStack* generate_non_capture_checks(const Position& pos, MoveStack* mlist, Bitboard dc) {
MoveStack* generate_non_capture_checks(const Position& pos, MoveStack* mlist, Bitboard dc) {
/// generate_evasions() generates all check evasions when the side to move is
/// in check. Unlike the other move generation functions, this one generates
/// generate_evasions() generates all check evasions when the side to move is
/// in check. Unlike the other move generation functions, this one generates
-/// only legal moves. It returns the number of generated moves.
+/// only legal moves. Returns a pointer to the end of the move list.
MoveStack* generate_evasions(const Position& pos, MoveStack* mlist, Bitboard pinned) {
MoveStack* generate_evasions(const Position& pos, MoveStack* mlist, Bitboard pinned) {
// Find squares attacked by slider checkers, we will
// remove them from king evasions set so to avoid a couple
// of cycles in the slow king evasions legality check loop
// Find squares attacked by slider checkers, we will
// remove them from king evasions set so to avoid a couple
// of cycles in the slow king evasions legality check loop
- // and to be able to use square_is_attacked().
+ // and to be able to use attacks_to().
Bitboard checkers = pos.checkers();
Bitboard checkersAttacks = EmptyBoardBB;
Bitboard b = checkers & pos.pieces(BISHOP, QUEEN);
Bitboard checkers = pos.checkers();
Bitboard checkersAttacks = EmptyBoardBB;
Bitboard b = checkers & pos.pieces(BISHOP, QUEEN);
while (b1)
{
to = pop_1st_bit(&b1);
while (b1)
{
to = pop_1st_bit(&b1);
- // Note that we can use square_is_attacked() only because we
+ // Note that we can use attacks_to() only because we
// have already removed slider checkers.
// have already removed slider checkers.
- if (!pos.square_is_attacked(to, them))
+ if (!pos.attacks_to(to, them))
(*mlist++).move = make_move(ksq, to);
}
(*mlist++).move = make_move(ksq, to);
}
// is occupied or under attack.
for (s = Min(from, g1); s <= Max(from, g1); s++)
if ( (s != from && s != to && !pos.square_is_empty(s))
// is occupied or under attack.
for (s = Min(from, g1); s <= Max(from, g1); s++)
if ( (s != from && s != to && !pos.square_is_empty(s))
- || pos.square_is_attacked(s, them))
+ || pos.attacks_to(s, them))
illegal = true;
// Check if any of the squares between king and rook
illegal = true;
// Check if any of the squares between king and rook
for (s = Min(from, c1); s <= Max(from, c1); s++)
if( (s != from && s != to && !pos.square_is_empty(s))
for (s = Min(from, c1); s <= Max(from, c1); s++)
if( (s != from && s != to && !pos.square_is_empty(s))
- || pos.square_is_attacked(s, them))
+ || pos.attacks_to(s, them))
illegal = true;
for (s = Min(to, d1); s <= Max(to, d1); s++)
illegal = true;
for (s = Min(to, d1); s <= Max(to, d1); s++)
// It is a bit complicated to correctly handle Chess960
for (s = Min(ksq, s1); s <= Max(ksq, s1); s++)
if ( (s != ksq && s != rsq && pos.square_is_occupied(s))
// It is a bit complicated to correctly handle Chess960
for (s = Min(ksq, s1); s <= Max(ksq, s1); s++)
if ( (s != ksq && s != rsq && pos.square_is_occupied(s))
- || pos.square_is_attacked(s, them))
+ || pos.attacks_to(s, them))
illegal = true;
for (s = Min(rsq, s2); s <= Max(rsq, s2); s++)
illegal = true;
for (s = Min(rsq, s2); s <= Max(rsq, s2); s++)
// If the moving piece is a king, check whether the destination
// square is attacked by the opponent.
if (type_of_piece_on(from) == KING)
// If the moving piece is a king, check whether the destination
// square is attacked by the opponent.
if (type_of_piece_on(from) == KING)
- return !(square_is_attacked(move_to(m), opposite_color(us)));
+ return !attacks_to(move_to(m), opposite_color(us));
// 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.
// 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.
Color us = side_to_move();
Color them = opposite_color(us);
Square ksq = king_square(them);
Color us = side_to_move();
Color them = opposite_color(us);
Square ksq = king_square(them);
- if (square_is_attacked(ksq, us))
+ if (attacks_to(ksq, us))
Square initial_kr_square(Color c) const;
Square initial_qr_square(Color c) const;
Square initial_kr_square(Color c) const;
Square initial_qr_square(Color c) const;
- // Attack bitboards
- Bitboard sliding_attacks(Square s, Direction d) const;
- Bitboard ray_attacks(Square s, SignedDirection d) const;
- Bitboard pawn_attacks(Color c, Square s) const;
-
- template<PieceType>
- Bitboard piece_attacks(Square s) const;
-
// Bitboards for pinned pieces and discovered check candidates
Bitboard discovered_check_candidates(Color c) const;
Bitboard pinned_pieces(Color c, Bitboard& p) const;
Bitboard pinned_pieces(Color c) const;
// Bitboards for pinned pieces and discovered check candidates
Bitboard discovered_check_candidates(Color c) const;
Bitboard pinned_pieces(Color c, Bitboard& p) const;
Bitboard pinned_pieces(Color c) const;
+ // Checking pieces and under check information
Bitboard checkers() const;
Bitboard checkers() const;
// Piece lists
Square piece_list(Color c, PieceType pt, int index) const;
// Attack information for a given square
// Piece lists
Square piece_list(Color c, PieceType pt, int index) const;
// Attack information for a given square
- bool square_is_attacked(Square s, Color c) const;
Bitboard attacks_to(Square s) const;
Bitboard attacks_to(Square s, Color c) const;
Bitboard attacks_to(Square s) const;
Bitboard attacks_to(Square s, Color c) const;
bool pawn_attacks_square(Color c, Square f, Square t) const;
bool pawn_attacks_square(Color c, Square f, Square t) const;
+ Bitboard pawn_attacks(Color c, Square s) const;
+
+ template<PieceType>
+ Bitboard piece_attacks(Square s) const;
template<PieceType>
Bitboard piece_attacks_square(Square f, Square t) const; // Dispatch at compile-time
template<PieceType>
Bitboard piece_attacks_square(Square f, Square t) const; // Dispatch at compile-time
return attacks_to(s) & pieces_of_color(c);
}
return attacks_to(s) & pieces_of_color(c);
}
-inline bool Position::square_is_attacked(Square s, Color c) const {
-
- return attacks_to(s, c) != EmptyBoardBB;
-}
-
inline bool Position::pawn_is_passed(Color c, Square s) const {
return !(pieces(PAWN, opposite_color(c)) & passed_pawn_mask(c, s));
}
inline bool Position::pawn_is_passed(Color c, Square s) const {
return !(pieces(PAWN, opposite_color(c)) & passed_pawn_mask(c, s));
}