X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fposition.h;h=b3d0cd0a6c90e8c4358fa461ab876ae4b7071b4b;hp=9668368a1bd9e3169f0a90798e838408e4b1fee3;hb=76bed11f7b79d939c250c02d73d0c1e2628e7a17;hpb=05e70d674019e27f2c9a58839f6a9c17e16f9fcc diff --git a/src/position.h b/src/position.h index 9668368a..b3d0cd0a 100644 --- a/src/position.h +++ b/src/position.h @@ -133,7 +133,7 @@ public: }; // Constructors - Position() {}; + Position() {} Position(const Position& pos); Position(const std::string& fen); @@ -163,25 +163,14 @@ public: Bitboard occupied_squares() const; Bitboard pieces_of_color(Color c) const; Bitboard pieces_of_type(PieceType pt) const; - Bitboard pieces_of_color_and_type(Color c, PieceType pt) const; - Bitboard pawns() const; - Bitboard knights() const; - Bitboard bishops() const; - Bitboard rooks() const; - Bitboard queens() const; - Bitboard kings() const; - Bitboard rooks_and_queens() const; - Bitboard bishops_and_queens() const; - Bitboard sliders() const; - Bitboard pawns(Color c) const; - Bitboard knights(Color c) const; - Bitboard bishops(Color c) const; - Bitboard rooks(Color c) const; - Bitboard queens(Color c) const; - Bitboard kings(Color c) const; - Bitboard rooks_and_queens(Color c) const; - Bitboard bishops_and_queens(Color c) const; - Bitboard sliders_of_color(Color c) const; + + // Pieces by constant type of both colors + template Bitboard pieces() const { return byTypeBB[Piece]; } + template<> Bitboard pieces() const { return byTypeBB[BISHOP] | byTypeBB[QUEEN]; } + template<> Bitboard pieces() const { return byTypeBB[ROOK] | byTypeBB[QUEEN]; } + + // Pieces by constant type of a given color + template Bitboard pieces(Color c) const { return byColorBB[c] & pieces(); } // Number of pieces of each color and type int piece_count(Color c, PieceType pt) const; @@ -236,10 +225,7 @@ public: bool move_is_check(Move m) const; bool move_is_check(Move m, Bitboard dcCandidates) const; bool move_is_capture(Move m) const; - bool move_is_deep_pawn_push(Move m) const; - bool move_is_pawn_push_to_7th(Move m) const; bool move_is_passed_pawn_push(Move m) const; - bool move_was_passed_pawn_push(Move m) const; bool move_attacks_square(Move m, Square s) const; // Information about pawns @@ -310,7 +296,7 @@ private: void allow_ooo(Color c); // Helper functions for doing and undoing moves - void do_capture_move(PieceType capture, Color them, Square to, bool ep); + void do_capture_move(Bitboard& key, PieceType capture, Color them, Square to, bool ep); void do_castle_move(Move m); void undo_castle_move(Move m); void find_checkers(); @@ -342,7 +328,7 @@ private: // Piece lists Square pieceList[2][8][16]; // [color][pieceType][index] - int index[64]; + int index[64]; // [square] // Other info Square kingSquare[2]; @@ -417,78 +403,6 @@ inline Bitboard Position::pieces_of_type(PieceType pt) const { return byTypeBB[pt]; } -inline Bitboard Position::pieces_of_color_and_type(Color c, PieceType pt) const { - return pieces_of_color(c) & pieces_of_type(pt); -} - -inline Bitboard Position::pawns() const { - return pieces_of_type(PAWN); -} - -inline Bitboard Position::knights() const { - return pieces_of_type(KNIGHT); -} - -inline Bitboard Position::bishops() const { - return pieces_of_type(BISHOP); -} - -inline Bitboard Position::rooks() const { - return pieces_of_type(ROOK); -} - -inline Bitboard Position::queens() const { - return pieces_of_type(QUEEN); -} - -inline Bitboard Position::kings() const { - return pieces_of_type(KING); -} - -inline Bitboard Position::rooks_and_queens() const { - return rooks() | queens(); -} - -inline Bitboard Position::bishops_and_queens() const { - return bishops() | queens(); -} - -inline Bitboard Position::sliders() const { - return bishops() | queens() | rooks(); -} - -inline Bitboard Position::pawns(Color c) const { - return pieces_of_color_and_type(c, PAWN); -} - -inline Bitboard Position::knights(Color c) const { - return pieces_of_color_and_type(c, KNIGHT); -} - -inline Bitboard Position::bishops(Color c) const { - return pieces_of_color_and_type(c, BISHOP); -} - -inline Bitboard Position::rooks(Color c) const { - return pieces_of_color_and_type(c, ROOK); -} - -inline Bitboard Position::queens(Color c) const { - return pieces_of_color_and_type(c, QUEEN); -} - -inline Bitboard Position::kings(Color c) const { - return pieces_of_color_and_type(c, KING); -} - -inline Bitboard Position::rooks_and_queens(Color c) const { - return rooks_and_queens() & pieces_of_color(c); -} - -inline Bitboard Position::bishops_and_queens(Color c) const { - return bishops_and_queens() & pieces_of_color(c); -} - inline int Position::piece_count(Color c, PieceType pt) const { return pieceCount[c][pt]; } @@ -567,7 +481,7 @@ inline bool Position::pawn_attacks_square(Color c, Square f, Square t) const { } template -Bitboard Position::piece_attacks_square(Square f, Square t) const { +inline Bitboard Position::piece_attacks_square(Square f, Square t) const { return bit_is_set(piece_attacks(f), t); } @@ -582,7 +496,7 @@ inline bool Position::square_is_attacked(Square s, Color c) const { } inline bool Position::pawn_is_passed(Color c, Square s) const { - return !(pawns(opposite_color(c)) & passed_pawn_mask(c, s)); + return !(pieces(opposite_color(c)) & passed_pawn_mask(c, s)); } inline bool Position::pawn_is_passed(Bitboard theirPawns, Color c, Square s) { @@ -598,7 +512,7 @@ inline bool Position::pawn_is_doubled(Bitboard ourPawns, Color c, Square s) { } inline bool Position::square_is_weak(Square s, Color c) const { - return !(pawns(c) & outpost_mask(opposite_color(c), s)); + return !(pieces(c) & outpost_mask(opposite_color(c), s)); } inline Key Position::get_key() const { @@ -653,20 +567,6 @@ inline Phase Position::game_phase() const { return Phase(((npm - EndgameLimit) * 128) / (MidgameLimit - EndgameLimit)); } -inline bool Position::move_is_deep_pawn_push(Move m) const { - - Color c = side_to_move(); - return piece_on(move_from(m)) == piece_of_color_and_type(c, PAWN) - && relative_rank(c, move_to(m)) > RANK_4; -} - -inline bool Position::move_is_pawn_push_to_7th(Move m) const { - - Color c = side_to_move(); - return piece_on(move_from(m)) == piece_of_color_and_type(c, PAWN) - && relative_rank(c, move_to(m)) == RANK_7; -} - inline bool Position::move_is_passed_pawn_push(Move m) const { Color c = side_to_move(); @@ -674,13 +574,6 @@ inline bool Position::move_is_passed_pawn_push(Move m) const { && pawn_is_passed(c, move_to(m)); } -inline bool Position::move_was_passed_pawn_push(Move m) const { - - Color c = opposite_color(side_to_move()); - return piece_on(move_to(m)) == piece_of_color_and_type(c, PAWN) - && pawn_is_passed(c, move_to(m)); -} - inline int Position::rule_50_counter() const { return st->rule50; @@ -695,7 +588,7 @@ inline bool Position::opposite_colored_bishops() const { inline bool Position::has_pawn_on_7th(Color c) const { - return pawns(c) & relative_rank_bb(c, RANK_7); + return pieces(c) & relative_rank_bb(c, RANK_7); } inline bool Position::move_is_capture(Move m) const {