X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;ds=sidebyside;f=src%2Fposition.h;h=e471baea099029c5b7d72dbb9d472a9d780b462a;hb=d8349f9d0f4eafda145de67330abcc2cb2d9ba56;hp=c391d8247c72f4530d78d942a1d087eb1d472180;hpb=d98150dffc69a810b0b842244aec0d29deddabfb;p=stockfish diff --git a/src/position.h b/src/position.h index c391d824..e471baea 100644 --- a/src/position.h +++ b/src/position.h @@ -189,6 +189,7 @@ public: template bool is_draw() const; int startpos_ply_counter() const; bool opposite_colored_bishops() const; + bool both_color_bishops(Color c) const; bool has_pawn_on_7th(Color c) const; bool is_chess960() const; @@ -342,29 +343,16 @@ inline Square Position::castle_rook_square(CastleRight f) const { return castleRookSquare[f]; } -template<> -inline Bitboard Position::attacks_from(Square s, Color c) const { - return StepAttacksBB[make_piece(c, PAWN)][s]; -} - -template // Knight and King and white pawns +template inline Bitboard Position::attacks_from(Square s) const { - return StepAttacksBB[Piece][s]; -} - -template<> -inline Bitboard Position::attacks_from(Square s) const { - return bishop_attacks_bb(s, occupied_squares()); + return Pt == BISHOP || Pt == ROOK ? attacks_bb(s, occupied_squares()) + : Pt == QUEEN ? attacks_from(s) | attacks_from(s) + : StepAttacksBB[Pt][s]; } template<> -inline Bitboard Position::attacks_from(Square s) const { - return rook_attacks_bb(s, occupied_squares()); -} - -template<> -inline Bitboard Position::attacks_from(Square s) const { - return attacks_from(s) | attacks_from(s); +inline Bitboard Position::attacks_from(Square s, Color c) const { + return StepAttacksBB[make_piece(c, PAWN)][s]; } inline Bitboard Position::attacks_from(Piece p, Square s) const { @@ -444,6 +432,12 @@ inline bool Position::opposite_colored_bishops() const { && opposite_colors(pieceList[WHITE][BISHOP][0], pieceList[BLACK][BISHOP][0]); } +inline bool Position::both_color_bishops(Color c) const { + // Assumes that there are only two bishops + return pieceCount[c][BISHOP] >= 2 && + opposite_colors(pieceList[c][BISHOP][0], pieceList[c][BISHOP][1]); +} + inline bool Position::has_pawn_on_7th(Color c) const { return pieces(PAWN, c) & rank_bb(relative_rank(c, RANK_7)); }