Fix TT lookup after search test case
[purplehaze.git] / src / time.h
blob76d7bdd6a076d5c4ee8499d3088bbfa368b17094
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 <stdio.h>
21 #include <time.h>
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 // Set the time to play the game
33 unsigned int level_moves;
34 unsigned int level_time; // In centi-seconds
36 // Set the time to play a move
37 clock_t start;
38 unsigned long long int time_per_move; // Calculated
39 unsigned int remaining; // Given by protocols like Xboard
40 int coef_1, coef_2;
42 bool abort_search;
44 public:
45 Time(unsigned int moves = 40, unsigned int time = 24000) :
46 level_moves(moves), level_time(time),
47 time_per_move(level_time / level_moves),
48 remaining(time_per_move),
49 abort_search(false)
52 void set_polling_interval(const unsigned int nodes) {
53 polling.interval = nodes;
55 void set_remaining(const unsigned int time) {
56 remaining = time;
58 unsigned long long int allocated() const {
59 return time_per_move;
61 unsigned long long int elapsed() const {
62 unsigned long long int clocks = clock() - start;
63 return 100 * clocks / CLOCKS_PER_SEC;
65 void start_thinking(const unsigned int ply);
66 bool is_out_of_time() const;
67 bool poll(const unsigned int node_count);
70 #endif /* !TIME_H */