X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fposition.h;h=370bb1d45e0476a9618c42725e350b7dc0e018e2;hb=18cd83a38042a3993678e88bc8163ceb1cbd62b4;hp=de6d186bc1c19bc3f97b43d229e850ead260ba42;hpb=0e0adfe2e1a01ca5f46af495e14c41e23ffaa4d0;p=stockfish diff --git a/src/position.h b/src/position.h index de6d186b..370bb1d4 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 kingSquare[2], epSquare; + 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; @@ -304,12 +299,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 +404,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 +436,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 +469,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)); }