Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
official-stockfish
GitHub Repository: official-stockfish/Stockfish
Path: blob/master/src/timeman.h
376 views
1
/*
2
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
3
Copyright (C) 2004-2025 The Stockfish developers (see AUTHORS file)
4
5
Stockfish is free software: you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation, either version 3 of the License, or
8
(at your option) any later version.
9
10
Stockfish is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
14
15
You should have received a copy of the GNU General Public License
16
along with this program. If not, see <http://www.gnu.org/licenses/>.
17
*/
18
19
#ifndef TIMEMAN_H_INCLUDED
20
#define TIMEMAN_H_INCLUDED
21
22
#include <cstdint>
23
24
#include "misc.h"
25
26
namespace Stockfish {
27
28
class OptionsMap;
29
enum Color : int8_t;
30
31
namespace Search {
32
struct LimitsType;
33
}
34
35
// The TimeManagement class computes the optimal time to think depending on
36
// the maximum available time, the game move number, and other parameters.
37
class TimeManagement {
38
public:
39
void init(Search::LimitsType& limits,
40
Color us,
41
int ply,
42
const OptionsMap& options,
43
double& originalTimeAdjust);
44
45
TimePoint optimum() const;
46
TimePoint maximum() const;
47
template<typename FUNC>
48
TimePoint elapsed(FUNC nodes) const {
49
return useNodesTime ? TimePoint(nodes()) : elapsed_time();
50
}
51
TimePoint elapsed_time() const { return now() - startTime; };
52
53
void clear();
54
void advance_nodes_time(std::int64_t nodes);
55
56
private:
57
TimePoint startTime;
58
TimePoint optimumTime;
59
TimePoint maximumTime;
60
61
std::int64_t availableNodes = -1; // When in 'nodes as time' mode
62
bool useNodesTime = false; // True if we are in 'nodes as time' mode
63
};
64
65
} // namespace Stockfish
66
67
#endif // #ifndef TIMEMAN_H_INCLUDED
68
69