mirror of
https://github.com/sockspls/badfish
synced 2025-04-29 16:23:09 +00:00
Templetize Position::xxx_attacks_square()
Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
d4f14a8e83
commit
ff211469ba
2 changed files with 19 additions and 35 deletions
|
@ -408,11 +408,11 @@ bool Position::piece_attacks_square(Square f, Square t) const {
|
|||
switch(piece_on(f)) {
|
||||
case WP: return white_pawn_attacks_square(f, t);
|
||||
case BP: return black_pawn_attacks_square(f, t);
|
||||
case WN: case BN: return knight_attacks_square(f, t);
|
||||
case WB: case BB: return bishop_attacks_square(f, t);
|
||||
case WR: case BR: return rook_attacks_square(f, t);
|
||||
case WQ: case BQ: return queen_attacks_square(f, t);
|
||||
case WK: case BK: return king_attacks_square(f, t);
|
||||
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);
|
||||
default: return false;
|
||||
}
|
||||
|
||||
|
@ -549,7 +549,7 @@ bool Position::move_is_check(Move m, Bitboard dcCandidates) const {
|
|||
|
||||
switch(move_promotion(m)) {
|
||||
case KNIGHT:
|
||||
return knight_attacks_square(to, ksq);
|
||||
return piece_attacks_square<KNIGHT>(to, ksq);
|
||||
case BISHOP:
|
||||
return bit_is_set(bishop_attacks_bb(to, b), ksq);
|
||||
case ROOK:
|
||||
|
@ -670,11 +670,11 @@ bool Position::move_attacks_square(Move m, Square s) const {
|
|||
switch(piece_on(f)) {
|
||||
case WP: return white_pawn_attacks_square(t, s);
|
||||
case BP: return black_pawn_attacks_square(t, s);
|
||||
case WN: case BN: return knight_attacks_square(t, s);
|
||||
case WB: case BB: return bishop_attacks_square(t, s);
|
||||
case WR: case BR: return rook_attacks_square(t, s);
|
||||
case WQ: case BQ: return queen_attacks_square(t, s);
|
||||
case WK: case BK: return king_attacks_square(t, s);
|
||||
case WN: case BN: return piece_attacks_square<KNIGHT>(t, s);
|
||||
case WB: case BB: return piece_attacks_square<BISHOP>(t, s);
|
||||
case WR: case BR: return piece_attacks_square<ROOK>(t, s);
|
||||
case WQ: case BQ: return piece_attacks_square<QUEEN>(t, s);
|
||||
case WK: case BK: return piece_attacks_square<KING>(t, s);
|
||||
default: assert(false);
|
||||
}
|
||||
|
||||
|
|
|
@ -213,14 +213,13 @@ public:
|
|||
Bitboard attacks_to(Square s) const;
|
||||
Bitboard attacks_to(Square s, Color c) const;
|
||||
bool is_check() const;
|
||||
bool piece_attacks_square(Square f, Square t) const;
|
||||
bool white_pawn_attacks_square(Square f, Square t) const;
|
||||
bool black_pawn_attacks_square(Square f, Square t) const;
|
||||
bool knight_attacks_square(Square f, Square t) const;
|
||||
bool bishop_attacks_square(Square f, Square t) const;
|
||||
bool rook_attacks_square(Square f, Square t) const;
|
||||
bool queen_attacks_square(Square f, Square t) const;
|
||||
bool king_attacks_square(Square f, Square t) const;
|
||||
|
||||
template<PieceType>
|
||||
Bitboard piece_attacks_square(Square f, Square t) const; // Dispatch at compile-time
|
||||
|
||||
bool piece_attacks_square(Square f, Square t) const; // Dispatch at run-time
|
||||
|
||||
// Properties of moves
|
||||
bool move_is_legal(Move m) const;
|
||||
|
@ -590,24 +589,9 @@ inline bool Position::black_pawn_attacks_square(Square f, Square t) const {
|
|||
return bit_is_set(pawn_attacks(BLACK, f), t);
|
||||
}
|
||||
|
||||
inline bool Position::knight_attacks_square(Square f, Square t) const {
|
||||
return bit_is_set(piece_attacks<KNIGHT>(f), t);
|
||||
}
|
||||
|
||||
inline bool Position::bishop_attacks_square(Square f, Square t) const {
|
||||
return bit_is_set(piece_attacks<BISHOP>(f), t);
|
||||
}
|
||||
|
||||
inline bool Position::rook_attacks_square(Square f, Square t) const {
|
||||
return bit_is_set(piece_attacks<ROOK>(f), t);
|
||||
}
|
||||
|
||||
inline bool Position::queen_attacks_square(Square f, Square t) const {
|
||||
return bit_is_set(piece_attacks<QUEEN>(f), t);
|
||||
}
|
||||
|
||||
inline bool Position::king_attacks_square(Square f, Square t) const {
|
||||
return bit_is_set(piece_attacks<KING>(f), t);
|
||||
template<PieceType Piece>
|
||||
Bitboard Position::piece_attacks_square(Square f, Square t) const {
|
||||
return bit_is_set(piece_attacks<Piece>(f), t);
|
||||
}
|
||||
|
||||
inline bool Position::pawn_is_passed(Color c, Square s) const {
|
||||
|
|
Loading…
Add table
Reference in a new issue