X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fposition.cpp;h=318f0f2c51ad94fb98c9648aa269f4fd19d4319f;hp=47b08ec0ad3044600d0f583fc67d930b59f246cb;hb=676b2c8435502409145491f2f86454f11f99dae8;hpb=b1f57e92cea7bd36126ef8c26928d8991b74baef diff --git a/src/position.cpp b/src/position.cpp index 47b08ec0..318f0f2c 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -96,13 +96,14 @@ CheckInfo::CheckInfo(const Position& pos) { /// 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::operator=(const Position& pos) { memcpy(this, &pos, sizeof(Position)); startState = *st; st = &startState; nodes = 0; - return *this; + + assert(pos_is_ok()); } @@ -110,7 +111,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 +227,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()); } @@ -895,8 +897,8 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI } // Prefetch pawn and material hash tables - prefetch((char*)this_thread->pawnTable.entries[st->pawnKey]); - prefetch((char*)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); @@ -1537,20 +1539,20 @@ void Position::init() { void Position::flip() { - // Make a copy of current position before to start changing const Position pos(*this); clear(); - // Board + sideToMove = ~pos.side_to_move(); + thisThread = pos.this_thread(); + nodes = pos.nodes_searched(); + chess960 = pos.is_chess960(); + startPosPly = pos.startpos_ply_counter(); + for (Square s = SQ_A1; s <= SQ_H8; s++) if (!pos.square_empty(s)) put_piece(Piece(pos.piece_on(s) ^ 8), ~s); - // Side to move - sideToMove = ~pos.side_to_move(); - - // Castling rights if (pos.can_castle(WHITE_OO)) set_castle_right(BLACK, ~pos.castle_rook_square(WHITE_OO)); if (pos.can_castle(WHITE_OOO)) @@ -1560,22 +1562,14 @@ void Position::flip() { if (pos.can_castle(BLACK_OOO)) set_castle_right(WHITE, ~pos.castle_rook_square(BLACK_OOO)); - // En passant square if (pos.st->epSquare != SQ_NONE) st->epSquare = ~pos.st->epSquare; - // Checkers - st->checkersBB = attackers_to(king_square(sideToMove)) & pieces(~sideToMove); - - // Hash keys st->key = compute_key(); st->pawnKey = compute_pawn_key(); st->materialKey = compute_material_key(); - - // Incremental scores st->psqScore = compute_psq_score(); - - // Material + st->checkersBB = attackers_to(king_square(sideToMove)) & pieces(~sideToMove); st->npMaterial[WHITE] = compute_non_pawn_material(WHITE); st->npMaterial[BLACK] = compute_non_pawn_material(BLACK);