mirror of
https://github.com/HChaZZY/Stockfish.git
synced 2025-12-19 16:46:30 +08:00
Detach the state when copying a position
In Position we store a pointer to a StateInfo record kept outside of the Position object. When copying a position we copy also that pointer so after the copy we have two Position objects pointing to the same StateInfo record. This can be dangerous so fix by copying also the StateInfo record inside the new Position object and let the new st pointer point to it. This completely detach the copied Position from the original one. Also rename setStartState() as saveState() and clean up the API to state more clearly what the function does. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
@@ -138,8 +138,8 @@ public:
|
||||
void print(Move m = MOVE_NONE) const;
|
||||
|
||||
// Copying
|
||||
void copy(const Position &pos);
|
||||
void flipped_copy(const Position &pos);
|
||||
void copy(const Position& pos);
|
||||
void flipped_copy(const Position& pos);
|
||||
|
||||
// The piece on a given square
|
||||
Piece piece_on(Square s) const;
|
||||
@@ -250,7 +250,7 @@ public:
|
||||
bool square_is_weak(Square s, Color c) const;
|
||||
|
||||
// Doing and undoing moves
|
||||
void setStartState(const StateInfo& st);
|
||||
void saveState();
|
||||
void do_move(Move m, StateInfo& st);
|
||||
void do_move(Move m, StateInfo& st, Bitboard dcCandidates);
|
||||
void undo_move(Move m);
|
||||
|
||||
Reference in New Issue
Block a user