Add Game::is_dangerous() for Futility Pruning
[purplehaze.git] / src / time.h
bloba19ae2144876f4a6ded61ed8121f933f4406cdd1
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 // Set the time to play the game
27 unsigned int allowed_moves;
28 unsigned int allowed_time; // In centi-seconds
30 // Set the time to play a move
31 clock_t starting_time;
32 unsigned long long int allocated_time; // Calculated
33 unsigned int remaining_time; // Given by protocols like Xboard
34 int coef_1, coef_2;
36 unsigned int polling_interval;
37 unsigned int last_poll_nodes_count;
38 bool abort_search;
40 public:
41 Time() :
42 allowed_moves(40), allowed_time(24000),
43 allocated_time(allowed_time / allowed_moves),
44 remaining_time(allowed_time / allowed_moves),
45 polling_interval(500000), last_poll_nodes_count(0),
46 abort_search(false)
49 Time(unsigned int moves, unsigned int time) :
50 allowed_moves(moves), allowed_time(time),
51 allocated_time(allowed_time / allowed_moves),
52 remaining_time(allowed_time / allowed_moves),
53 polling_interval(500000), last_poll_nodes_count(0),
54 abort_search(false)
57 void set_polling_interval(unsigned int nodes) {
58 polling_interval = nodes;
60 void set_remaining_time(unsigned int time) {
61 remaining_time = time;
63 unsigned long long int get_allocated_time() const {
64 return allocated_time;
66 unsigned long long int get_elapsed_time() {
67 unsigned long long int elapsed = clock() - starting_time;
68 return 100 * elapsed / CLOCKS_PER_SEC;
70 void start_thinking(unsigned int ply);
71 bool is_out_of_time();
72 bool poll(unsigned int nodes_count);
75 #endif /* !TIME_H */