X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fposition.h;h=e471baea099029c5b7d72dbb9d472a9d780b462a;hp=8826fa201161cfd9182502d1148b2105a410f106;hb=d8349f9d0f4eafda145de67330abcc2cb2d9ba56;hpb=c19ea4b0005c312aceb82d31ea17c2e1ff0729d2 diff --git a/src/position.h b/src/position.h index 8826fa20..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; @@ -210,7 +211,7 @@ private: // Initialization helper functions (used while setting up a position) void clear(); void put_piece(Piece p, Square s); - void set_castle_right(Square ksq, Square rsq); + void set_castle_right(Color c, Square rsq); bool move_is_legal(const Move m) const; // Helper template functions @@ -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 { @@ -392,7 +380,7 @@ inline Bitboard Position::pinned_pieces() const { } inline bool Position::pawn_is_passed(Color c, Square s) const { - return !(pieces(PAWN, flip(c)) & passed_pawn_mask(c, s)); + return !(pieces(PAWN, ~c) & passed_pawn_mask(c, s)); } inline Key Position::key() 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)); }