From: Marco Costalba Date: Wed, 20 Jul 2011 08:01:12 +0000 (+0200) Subject: Use st->gamePly to store fullMoves X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=3185c36a6554390d9061f1d74eb16a6c39caefb4 Use st->gamePly to store fullMoves This allow to retire do_setup_move() and also to simplify draw detection logic becuase now we always have: Min(st->rule50, st->gamePly) = st->rule50 This was already true when starting from starting position, but now is true even when starting from a FEN string because now we take in account fullmove number in counting gamePly so that it is always. st->rule50 <= st->gamePly No functional change. Signed-off-by: Marco Costalba --- diff --git a/src/position.cpp b/src/position.cpp index 28fa3695..bc9b5e0e 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 >> st->gamePly; + + // Convert from fullmove starting from 1 to ply starting from 0, + // handle also common incorrect FEN with fullmove = 0. + st->gamePly = Max(2 * (st->gamePly - 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 + (st->gamePly - 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. @@ -1528,7 +1515,6 @@ void Position::clear() { castleRightsMask[sq] = ALL_CASTLES; } sideToMove = WHITE; - fullMoves = 1; nodes = 0; } @@ -1670,7 +1656,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) { diff --git a/src/position.h b/src/position.h index 431d059c..14e6b95c 100644 --- a/src/position.h +++ b/src/position.h @@ -163,7 +163,6 @@ public: bool pawn_is_passed(Color c, Square s) const; // Doing and undoing moves - void do_setup_move(Move m, StateInfo& st); void do_move(Move m, StateInfo& st); void do_move(Move m, StateInfo& st, const CheckInfo& ci, bool moveIsCheck); void undo_move(Move m); @@ -190,7 +189,7 @@ public: template bool is_draw() const; // Number of plies from starting position - int startpos_ply_counter() const; + int game_ply() const; // Other properties of the position bool opposite_colored_bishops() const; @@ -257,7 +256,6 @@ private: StateInfo startState; int64_t nodes; Color sideToMove; - int fullMoves; int threadID; StateInfo* st; int chess960; @@ -423,8 +421,8 @@ inline bool Position::move_is_passed_pawn_push(Move m) const { && pawn_is_passed(c, move_to(m)); } -inline int Position::startpos_ply_counter() const { - return Max(2 * (fullMoves - 1), 0) + int(sideToMove == BLACK); +inline int Position::game_ply() const { + return st->gamePly; } inline bool Position::opposite_colored_bishops() const { diff --git a/src/search.cpp b/src/search.cpp index aec64345..29f57385 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -393,7 +393,7 @@ bool think(Position& pos, const SearchLimits& limits, Move searchMoves[]) { NodesSincePoll = 0; current_search_time(get_system_time()); Limits = limits; - TimeMgr.init(Limits, pos.startpos_ply_counter()); + TimeMgr.init(Limits, pos.game_ply()); // Set output steram in normal or chess960 mode cout << set960(pos.is_chess960()); diff --git a/src/uci.cpp b/src/uci.cpp index fb24bb26..b17cf089 100644 --- a/src/uci.cpp +++ b/src/uci.cpp @@ -144,13 +144,13 @@ namespace { } else return; - // Parse move list (if any) SetupState.clear(); + // Parse move list (if any) while (up >> token && (m = move_from_uci(pos, token)) != MOVE_NONE) { SetupState.push_back(StateInfo()); - pos.do_setup_move(m, SetupState.back()); + pos.do_move(m, SetupState.back()); } }