X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fposition.h;h=a55d1770fe59d225f550e97b11e75aaabd1c7ced;hp=de6d186bc1c19bc3f97b43d229e850ead260ba42;hb=941d923bf81128e5420ffe3dcf0116bf7758f430;hpb=0e0adfe2e1a01ca5f46af495e14c41e23ffaa4d0 diff --git a/src/position.h b/src/position.h index de6d186b..a55d1770 100644 --- a/src/position.h +++ b/src/position.h @@ -88,8 +88,8 @@ enum Phase { struct StateInfo { Key key, pawnKey, materialKey; - int castleRights, rule50; - Square kingSquare[2], epSquare; + int castleRights, rule50, pliesFromNull; + Square epSquare; Value mgValue, egValue; Value npMaterial[2]; @@ -185,7 +185,6 @@ public: // 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 and under check information @@ -194,17 +193,13 @@ public: // Piece lists Square piece_list(Color c, PieceType pt, int index) const; + const Square* piece_list_begin(Color c, PieceType pt) const; - // Attack information to a given square + // Information about attacks to or from a given square Bitboard attackers_to(Square s) const; - Bitboard attackers_to(Square s, Color c) const; - template Bitboard piece_attacks(Square s) const; - Bitboard pawn_attacks(Square s, Color c) const; - - // Attack information to a given square from another given square - 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 - bool pawn_attacks_square(Square f, Square t, Color c) const; + Bitboard attacks_from(Piece p, Square s) const; + template Bitboard attacks_from(Square s) const; + template Bitboard attacks_from(Square s, Color c) const; // Properties of moves bool pl_move_is_legal(Move m) const; @@ -212,6 +207,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_capture_or_promotion(Move m) const; bool move_is_passed_pawn_push(Move m) const; bool move_attacks_square(Move m, Square s) const; @@ -233,7 +229,7 @@ public: void undo_null_move(); // Static exchange evaluation - int see(Square from, Square to) const; + int see(Square from, Square to, bool shortcut) const; int see(Move m) const; int see(Square to) const; int see_sign(Move m) const; @@ -304,12 +300,12 @@ private: template Value compute_value() const; Value compute_non_pawn_material(Color c) const; - // Bitboards - Bitboard byColorBB[2], byTypeBB[8]; - // Board Piece board[64]; + // Bitboards + Bitboard byTypeBB[8], byColorBB[2]; + // Piece counts int pieceCount[2][8]; // [color][pieceType] @@ -409,12 +405,16 @@ inline Square Position::piece_list(Color c, PieceType pt, int index) const { return pieceList[c][pt][index]; } +inline const Square* Position::piece_list_begin(Color c, PieceType pt) const { + return pieceList[c][pt]; +} + inline Square Position::ep_square() const { return st->epSquare; } inline Square Position::king_square(Color c) const { - return st->kingSquare[c]; + return pieceList[c][KING][0]; } inline bool Position::can_castle_kingside(Color side) const { @@ -437,33 +437,29 @@ inline Square Position::initial_qr_square(Color c) const { return relative_square(c, make_square(initialQRFile, RANK_1)); } -inline Bitboard Position::pawn_attacks(Square s, Color c) const { +template<> +inline Bitboard Position::attacks_from(Square s, Color c) const { return StepAttackBB[piece_of_color_and_type(c, PAWN)][s]; } -template // Knight and King -inline Bitboard Position::piece_attacks(Square s) const { +template // Knight and King and white pawns +inline Bitboard Position::attacks_from(Square s) const { return StepAttackBB[Piece][s]; } template<> -inline Bitboard Position::piece_attacks(Square s) const { - return StepAttackBB[WP][s] | StepAttackBB[BP][s]; -} - -template<> -inline Bitboard Position::piece_attacks(Square s) const { +inline Bitboard Position::attacks_from(Square s) const { return bishop_attacks_bb(s, occupied_squares()); } template<> -inline Bitboard Position::piece_attacks(Square s) const { +inline Bitboard Position::attacks_from(Square s) const { return rook_attacks_bb(s, occupied_squares()); } template<> -inline Bitboard Position::piece_attacks(Square s) const { - return piece_attacks(s) | piece_attacks(s); +inline Bitboard Position::attacks_from(Square s) const { + return attacks_from(s) | attacks_from(s); } inline Bitboard Position::checkers() const { @@ -474,20 +470,6 @@ inline bool Position::is_check() const { return st->checkersBB != EmptyBoardBB; } -inline bool Position::pawn_attacks_square(Square f, Square t, Color c) const { - return bit_is_set(pawn_attacks(f, c), t); -} - -template -inline Bitboard Position::piece_attacks_square(Square f, Square t) const { - return bit_is_set(piece_attacks(f), t); -} - -inline Bitboard Position::attackers_to(Square s, Color c) const { - - return attackers_to(s) & pieces_of_color(c); -} - inline bool Position::pawn_is_passed(Color c, Square s) const { return !(pieces(PAWN, opposite_color(c)) & passed_pawn_mask(c, s)); } @@ -587,8 +569,13 @@ inline bool Position::has_pawn_on_7th(Color c) const { inline bool Position::move_is_capture(Move m) const { // Move must not be MOVE_NONE ! + return (m & (3 << 15)) ? !move_is_castle(m) : !square_is_empty(move_to(m)); +} - return (!square_is_empty(move_to(m)) && !move_is_castle(m)) || move_is_ep(m); +inline bool Position::move_is_capture_or_promotion(Move m) const { + + // Move must not be MOVE_NONE ! + return (m & (0x1F << 12)) ? !move_is_castle(m) : !square_is_empty(move_to(m)); } #endif // !defined(POSITION_H_INCLUDED)