/*1Stockfish, a UCI chess playing engine derived from Glaurung 2.12Copyright (C) 2004-2025 The Stockfish developers (see AUTHORS file)34Stockfish is free software: you can redistribute it and/or modify5it under the terms of the GNU General Public License as published by6the Free Software Foundation, either version 3 of the License, or7(at your option) any later version.89Stockfish is distributed in the hope that it will be useful,10but WITHOUT ANY WARRANTY; without even the implied warranty of11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12GNU General Public License for more details.1314You should have received a copy of the GNU General Public License15along with this program. If not, see <http://www.gnu.org/licenses/>.16*/1718#ifndef TIMEMAN_H_INCLUDED19#define TIMEMAN_H_INCLUDED2021#include <cstdint>2223#include "misc.h"2425namespace Stockfish {2627class OptionsMap;28enum Color : int8_t;2930namespace Search {31struct LimitsType;32}3334// The TimeManagement class computes the optimal time to think depending on35// the maximum available time, the game move number, and other parameters.36class TimeManagement {37public:38void init(Search::LimitsType& limits,39Color us,40int ply,41const OptionsMap& options,42double& originalTimeAdjust);4344TimePoint optimum() const;45TimePoint maximum() const;46template<typename FUNC>47TimePoint elapsed(FUNC nodes) const {48return useNodesTime ? TimePoint(nodes()) : elapsed_time();49}50TimePoint elapsed_time() const { return now() - startTime; };5152void clear();53void advance_nodes_time(std::int64_t nodes);5455private:56TimePoint startTime;57TimePoint optimumTime;58TimePoint maximumTime;5960std::int64_t availableNodes = -1; // When in 'nodes as time' mode61bool useNodesTime = false; // True if we are in 'nodes as time' mode62};6364} // namespace Stockfish6566#endif // #ifndef TIMEMAN_H_INCLUDED676869