X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fposition.cpp;h=3a0f8b1c90f8bba670b942488b87966092cefd69;hp=62749a913b75cfaa5e317c43bd8879e7370009f6;hb=c2fc80e5d16339266b5bf6687fa843ff65de3b3e;hpb=e1919384a23fe728422f995369161efa192380db diff --git a/src/position.cpp b/src/position.cpp index 62749a91..3a0f8b1c 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -92,17 +92,19 @@ CheckInfo::CheckInfo(const Position& pos) { } -/// Position::operator=() creates a copy of 'pos'. We want the new born Position +/// Position::copy() creates a copy of 'pos'. We want the new born Position /// object do not depend on any external data so we detach state pointer from /// the source one. -Position& Position::operator=(const Position& pos) { +void Position::copy(const Position& pos, Thread* th) { memcpy(this, &pos, sizeof(Position)); startState = *st; st = &startState; + thisThread = th; nodes = 0; - return *this; + + assert(pos_is_ok()); } @@ -110,7 +112,7 @@ Position& Position::operator=(const Position& pos) { /// string. This function is not very robust - make sure that input FENs are /// correct (this is assumed to be the responsibility of the GUI). -void Position::from_fen(const string& fenStr, bool isChess960) { +void Position::from_fen(const string& fenStr, bool isChess960, Thread* th) { /* A FEN string defines a particular position using only the ASCII character set. @@ -226,6 +228,7 @@ void Position::from_fen(const string& fenStr, bool isChess960) { st->npMaterial[BLACK] = compute_non_pawn_material(BLACK); st->checkersBB = attackers_to(king_square(sideToMove)) & pieces(~sideToMove); chess960 = isChess960; + thisThread = th; assert(pos_is_ok()); } @@ -328,7 +331,7 @@ void Position::print(Move move) const { if (move) { - Position p(*this); + Position p(*this, thisThread); cout << "\nMove is: " << (sideToMove == BLACK ? ".." : "") << move_to_san(p, move); } @@ -895,8 +898,8 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI } // Prefetch pawn and material hash tables - prefetch((char*)Threads.this_thread()->pawnTable.entries[st->pawnKey]); - prefetch((char*)Threads.this_thread()->materialTable.entries[st->materialKey]); + prefetch((char*)thisThread->pawnTable.entries[st->pawnKey]); + prefetch((char*)thisThread->materialTable.entries[st->materialKey]); // Update incremental scores st->psqScore += psq_delta(piece, from, to); @@ -1538,9 +1541,10 @@ void Position::init() { void Position::flip() { // Make a copy of current position before to start changing - const Position pos(*this); + const Position pos(*this, thisThread); clear(); + thisThread = pos.this_thread(); // Board for (Square s = SQ_A1; s <= SQ_H8; s++)