X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fposition.h;h=d47d84b7633c40924e38439e4b41a4fb0dd54ba6;hp=0006fbc772ca267e825d781c458e30ee28409c71;hb=f74f42b2982e25e180417948771843e8bb6bd4b7;hpb=9f28d8a854d05c6c6edcd6f8911b352477f82c91 diff --git a/src/position.h b/src/position.h index 0006fbc7..d47d84b7 100644 --- a/src/position.h +++ b/src/position.h @@ -89,7 +89,7 @@ enum Phase { struct StateInfo { Key key, pawnKey, materialKey; int castleRights, rule50; - Square epSquare; + Square kingSquare[2], epSquare; Value mgValue, egValue; Value npMaterial[2]; @@ -183,36 +183,24 @@ public: 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 - 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; - // Checking pieces + // Checking pieces and under check information Bitboard checkers() const; + bool is_check() const; // 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; - bool is_check() const; - bool pawn_attacks_square(Color c, Square f, Square t) const; - - template - Bitboard piece_attacks_square(Square f, Square t) const; // Dispatch at compile-time - - bool piece_attacks_square(Piece p, Square f, Square t) const; // Dispatch at run-time + // Attack information to a given square + Bitboard attackers_to(Square s) const; + Bitboard attackers_to(Square s, Color c) const; + Bitboard piece_attacks(Piece p, Square s) const; + Bitboard pawn_attacks(Square s, Color c) const; + template Bitboard piece_attacks(Square s) const; // Properties of moves bool pl_move_is_legal(Move m) const; @@ -278,7 +266,7 @@ public: // Position consistency check, for debugging bool is_ok(int* failedStep = NULL) const; - // Static member functions: + // Static member functions static void init_zobrist(); static void init_piece_square_tables(); @@ -326,7 +314,6 @@ private: int index[64]; // [square] // Other info - Square kingSquare[2]; Color sideToMove; int gamePly; Key history[MaxGameLength]; @@ -423,7 +410,7 @@ inline Square Position::ep_square() const { } inline Square Position::king_square(Color c) const { - return kingSquare[c]; + return st->kingSquare[c]; } inline bool Position::can_castle_kingside(Color side) const { @@ -446,7 +433,7 @@ inline Square Position::initial_qr_square(Color c) const { return relative_square(c, make_square(initialQRFile, RANK_1)); } -inline Bitboard Position::pawn_attacks(Color c, Square s) const { +inline Bitboard Position::pawn_attacks(Square s, Color c) const { return StepAttackBB[piece_of_color_and_type(c, PAWN)][s]; } @@ -457,7 +444,7 @@ inline Bitboard Position::piece_attacks(Square s) const { template<> inline Bitboard Position::piece_attacks(Square s) const { - return StepAttackBB[piece_of_color_and_type(opposite_color(sideToMove), PAWN)][s]; + return StepAttackBB[WP][s] | StepAttackBB[BP][s]; } template<> @@ -483,23 +470,9 @@ inline bool Position::is_check() const { return st->checkersBB != EmptyBoardBB; } -inline bool Position::pawn_attacks_square(Color c, Square f, Square t) const { - return bit_is_set(pawn_attacks(c, f), t); -} - -template -inline Bitboard Position::piece_attacks_square(Square f, Square t) const { - return bit_is_set(piece_attacks(f), t); -} - -inline Bitboard Position::attacks_to(Square s, Color c) const { - - return attacks_to(s) & pieces_of_color(c); -} - -inline bool Position::square_is_attacked(Square s, Color c) const { +inline Bitboard Position::attackers_to(Square s, Color c) const { - return attacks_to(s, c) != EmptyBoardBB; + return attackers_to(s) & pieces_of_color(c); } inline bool Position::pawn_is_passed(Color c, Square s) const {