X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fposition.cpp;h=480a92ec9cfcd1a7e3850aea8fbc94f61c570ece;hp=6e6bf38b3dda159a5703386f3d7e1fe192d693ab;hb=5b1316f7bbb259b87cecc276e4a1ce78b1a0e51b;hpb=3376c68f4bb83dc9fd874eb9d710dab09609ae54 diff --git a/src/position.cpp b/src/position.cpp index 6e6bf38b..480a92ec 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -315,9 +315,10 @@ void Position::print(Move m) const { /// Position::copy() creates a copy of the input position. -void Position::copy(const Position &pos) { +void Position::copy(const Position& pos) { memcpy(this, &pos, sizeof(Position)); + saveState(); // detach and copy state info } @@ -1607,15 +1608,16 @@ int Position::see(Square from, Square to) const { } -/// Position::setStartState() copies the content of the argument +/// Position::saveState() copies the content of the current state /// inside startState and makes st point to it. This is needed /// when the st pointee could become stale, as example because /// the caller is about to going out of scope. -void Position::setStartState(const StateInfo& s) { +void Position::saveState() { - startState = s; + startState = *st; st = &startState; + st->previous = NULL; // as a safe guard } @@ -1966,7 +1968,7 @@ void Position::init_piece_square_tables() { /// the white and black sides reversed. This is only useful for debugging, /// especially for finding evaluation symmetry bugs. -void Position::flipped_copy(const Position &pos) { +void Position::flipped_copy(const Position& pos) { assert(pos.is_ok()); @@ -2091,7 +2093,7 @@ bool Position::is_ok(int* failedStep) const { // Is there more than 2 checkers? if (failedStep) (*failedStep)++; - if (debugCheckerCount && count_1s(st->checkersBB) > 2) + if (debugCheckerCount && count_1s(st->checkersBB) > 2) return false; // Bitboards OK? @@ -2166,7 +2168,7 @@ bool Position::is_ok(int* failedStep) const { if (debugPieceCounts) for (Color c = WHITE; c <= BLACK; c++) for (PieceType pt = PAWN; pt <= KING; pt++) - if (pieceCount[c][pt] != count_1s(pieces_of_color_and_type(c, pt))) + if (pieceCount[c][pt] != count_1s(pieces_of_color_and_type(c, pt))) return false; if (failedStep) (*failedStep)++;