X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fposition.h;h=fced8e0c974c8a50c1921954ca62e1177975af46;hp=6351f58003557274955c7d69b7fd254c7d084c44;hb=e304db9d1ecf6a2318708483c90fadecf4fac4ee;hpb=a358dfe934eeefc00ea9adb20d4a83c4cf4d4e1e diff --git a/src/position.h b/src/position.h index 6351f580..fced8e0c 100644 --- a/src/position.h +++ b/src/position.h @@ -37,7 +37,7 @@ struct CheckInfo { Bitboard dcCandidates; Bitboard pinned; - Bitboard checkSq[8]; + Bitboard checkSq[PIECE_TYPE_NB]; Square ksq; }; @@ -49,7 +49,7 @@ struct CheckInfo { struct StateInfo { Key pawnKey, materialKey; - Value npMaterial[2]; + Value npMaterial[COLOR_NB]; int castleRights, rule50, pliesFromNull; Score psqScore; Square epSquare; @@ -60,6 +60,14 @@ struct StateInfo { StateInfo* previous; }; +struct ReducedStateInfo { + Key pawnKey, materialKey; + Value npMaterial[COLOR_NB]; + int castleRights, rule50, pliesFromNull; + Score psqScore; + Square epSquare; +}; + /// The position data structure. A position consists of the following data: /// @@ -86,10 +94,9 @@ struct StateInfo { class Position { public: Position() {} - Position(const Position& p) { *this = p; } Position(const Position& p, Thread* t) { *this = p; thisThread = t; } Position(const std::string& f, bool c960, Thread* t) { from_fen(f, c960, t); } - void operator=(const Position&); + Position& operator=(const Position&); // Text input/output void from_fen(const std::string& fen, bool isChess960, Thread* th); @@ -133,6 +140,7 @@ public: // Properties of moves bool move_gives_check(Move m, const CheckInfo& ci) const; bool move_attacks_square(Move m, Square s) const; + bool move_is_legal(const Move m) const; bool pl_move_is_legal(Move m, Bitboard pinned) const; bool is_pseudo_legal(const Move m) const; bool is_capture(Move m) const; @@ -181,15 +189,11 @@ public: bool pos_is_ok(int* failedStep = NULL) const; void flip(); - // Global initialization - static void init(); - private: // Initialization helpers (used while setting up a position) void clear(); void put_piece(Piece p, Square s); void set_castle_right(Color c, Square rfrom); - bool move_is_legal(const Move m) const; // Helper template functions template void do_castle_move(Move m); @@ -205,17 +209,17 @@ private: Value compute_non_pawn_material(Color c) const; // Board and pieces - Piece board[64]; // [square] - Bitboard byTypeBB[8]; // [pieceType] - Bitboard byColorBB[2]; // [color] - int pieceCount[2][8]; // [color][pieceType] - Square pieceList[2][8][16]; // [color][pieceType][index] - int index[64]; // [square] + Piece board[SQUARE_NB]; + Bitboard byTypeBB[PIECE_TYPE_NB]; + Bitboard byColorBB[COLOR_NB]; + int pieceCount[COLOR_NB][PIECE_TYPE_NB]; + Square pieceList[COLOR_NB][PIECE_TYPE_NB][16]; + int index[SQUARE_NB]; // Other info - int castleRightsMask[64]; // [square] - Square castleRookSquare[2][2]; // [color][side] - Bitboard castlePath[2][2]; // [color][side] + int castleRightsMask[SQUARE_NB]; + Square castleRookSquare[COLOR_NB][CASTLING_SIDE_NB]; + Bitboard castlePath[COLOR_NB][CASTLING_SIDE_NB]; StateInfo startState; int64_t nodes; int startPosPly; @@ -223,14 +227,6 @@ private: Thread* thisThread; StateInfo* st; int chess960; - - // Static variables - static Score pieceSquareTable[16][64]; // [piece][square] - static Key zobrist[2][8][64]; // [color][pieceType][square]/[piece count] - static Key zobEp[8]; // [file] - static Key zobCastle[16]; // [castleRight] - static Key zobSideToMove; - static Key zobExclusion; }; inline int64_t Position::nodes_searched() const { @@ -359,7 +355,7 @@ inline Key Position::key() const { } inline Key Position::exclusion_key() const { - return st->key ^ zobExclusion; + return st->key ^ Zobrist::exclusion; } inline Key Position::pawn_key() const { @@ -416,14 +412,14 @@ inline bool Position::is_chess960() const { inline bool Position::is_capture_or_promotion(Move m) const { assert(is_ok(m)); - return is_special(m) ? !is_castle(m) : !is_empty(to_sq(m)); + return type_of(m) ? type_of(m) != CASTLE : !is_empty(to_sq(m)); } inline bool Position::is_capture(Move m) const { // Note that castle is coded as "king captures the rook" assert(is_ok(m)); - return (!is_empty(to_sq(m)) && !is_castle(m)) || is_enpassant(m); + return (!is_empty(to_sq(m)) && type_of(m) != CASTLE) || type_of(m) == ENPASSANT; } inline PieceType Position::captured_piece_type() const {