X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fposition.cpp;h=922a96fd8bdee8e23c4df7e1382ca486985a961c;hp=28fa369548b12d3a8b30e7a214d3374a622f4ac8;hb=eabba1119f45f2ac8a3a6248bd1c1d9868d7af5c;hpb=3d8140a54101a50860ba2e3eb0f2d6cce68bfe47 diff --git a/src/position.cpp b/src/position.cpp index 28fa3695..922a96fd 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -190,7 +190,11 @@ void Position::from_fen(const string& fenStr, bool isChess960) { } // 5-6. Halfmove clock and fullmove number - fen >> std::skipws >> st->rule50 >> fullMoves; + fen >> std::skipws >> st->rule50 >> startPosPly; + + // Convert from fullmove starting from 1 to ply starting from 0, + // handle also common incorrect FEN with fullmove = 0. + startPosPly = Max(2 * (startPosPly - 1), 0) + int(sideToMove == BLACK); // Various initialisations chess960 = isChess960; @@ -310,7 +314,7 @@ const string Position::to_fen() const { fen << '-'; fen << (ep_square() == SQ_NONE ? " -" : " " + square_to_string(ep_square())) - << " " << st->rule50 << " " << fullMoves; + << " " << st->rule50 << " " << 1 + (startPosPly - int(sideToMove == BLACK)) / 2; return fen.str(); } @@ -759,23 +763,6 @@ bool Position::move_gives_check(Move m, const CheckInfo& ci) const { } -/// Position::do_setup_move() makes a permanent move on the board. It should -/// be used when setting up a position on board. You can't undo the move. - -void Position::do_setup_move(Move m, StateInfo& newSt) { - - assert(move_is_ok(m)); - - // Update the number of full moves after black's move - if (sideToMove == BLACK) - fullMoves++; - - do_move(m, newSt); - - assert(is_ok()); -} - - /// Position::do_move() makes a move, and saves all information necessary /// to a StateInfo object. The move is assumed to be legal. Pseudo-legal /// moves should be filtered out before this function is called. @@ -799,10 +786,10 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI // pointer to point to the new, ready to be updated, state. struct ReducedStateInfo { Key pawnKey, materialKey; - int castleRights, rule50, gamePly, pliesFromNull; - Square epSquare; - Score value; Value npMaterial[2]; + int castleRights, rule50, pliesFromNull; + Score value; + Square epSquare; }; memcpy(&newSt, st, sizeof(ReducedStateInfo)); @@ -816,7 +803,6 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI // Increment the 50 moves rule draw counter. Resetting it to zero in the // case of non-reversible moves is taken care of later. st->rule50++; - st->gamePly++; st->pliesFromNull++; if (move_is_castle(m)) @@ -1352,7 +1338,6 @@ void Position::do_null_move(StateInfo& backupSt) { sideToMove = opposite_color(sideToMove); st->epSquare = SQ_NONE; st->rule50++; - st->gamePly++; st->pliesFromNull = 0; st->value += (sideToMove == WHITE) ? TempoValue : -TempoValue; @@ -1377,7 +1362,6 @@ void Position::undo_null_move() { // Update the necessary information sideToMove = opposite_color(sideToMove); st->rule50--; - st->gamePly--; assert(is_ok()); } @@ -1528,7 +1512,6 @@ void Position::clear() { castleRightsMask[sq] = ALL_CASTLES; } sideToMove = WHITE; - fullMoves = 1; nodes = 0; } @@ -1670,7 +1653,7 @@ bool Position::is_draw() const { // Draw by repetition? if (!SkipRepetition) { - int i = 4, e = Min(Min(st->gamePly, st->rule50), st->pliesFromNull); + int i = 4, e = Min(st->rule50, st->pliesFromNull); if (i <= e) {