Fix Time header
[purplehaze.git] / src / time.h
bloba5dba3ad223038f5d3e6ac7d39948e6f14775922
1 /* Copyright (C) 2007-2011 Vincent Ollivier
3 * Purple Haze is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * Purple Haze is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #ifndef TIME_H
18 #define TIME_H
20 #include <assert.h>
21 #include <ctime>
23 class Time
25 private:
26 struct Polling {
27 unsigned int interval;
28 unsigned int previous;
29 Polling() : interval(50000), previous(0) {}
30 } polling;
32 struct Clock {
33 unsigned int moves;
34 unsigned int time; // Centiseconds
35 Clock(int m, int t) : moves(m), time(t) {}
36 } level, clock;
38 unsigned int ratio;
39 clock_t start;
40 bool abort_search;
42 bool is_out_of_time() const;
44 public:
45 Time(const int moves = 40, const int time = 5 * 60 * 100) :
46 level(moves, time),
47 clock(1, time),
48 abort_search(false)
51 void set_polling_interval(const unsigned int nodes) {
52 polling.interval = nodes;
54 void set_remaining(const unsigned int time) {
55 clock.time = time;
57 unsigned int allocated() const {
58 assert(level.moves >= clock.moves);
59 const unsigned int moves = level.moves - clock.moves + 1;
60 return clock.time / moves;
62 unsigned long long int elapsed() const {
63 const unsigned long long int clocks = std::clock() - start;
64 return 100 * clocks / CLOCKS_PER_SEC;
66 void abort() {
67 abort_search = true;
69 void start_thinking(const unsigned int ply);
70 bool poll(const unsigned int node_count);
73 #endif /* !TIME_H */