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/>.
22 void Time::start_thinking(const unsigned int ply
)
27 polling
.interval
= 1000000;
30 // Compute time per move
31 if (remaining
!= time_per_move
) {
32 unsigned int n
= level_moves
;
33 n
= n
- (((ply
+ 1) / 2) % n
);
35 time_per_move
= remaining
/ n
;
37 assert(level_moves
> 0);
38 time_per_move
= level_time
/ level_moves
;
42 if (time_per_move
> 3000) {
43 coef_1
= 16; coef_2
= 15;
44 } else if (time_per_move
> 1000) {
45 coef_1
= 4; coef_2
= 3;
47 coef_1
= 5; coef_2
= 3;
51 bool Time::is_out_of_time() const
53 return coef_1
* elapsed() > coef_2
* allocated();
56 bool Time::poll(const unsigned int node_count
)
58 // Avoid wasting time by calling 'is_out_of_time()' too frequently
59 if (node_count
- polling
.previous
> polling
.interval
) {
60 polling
.previous
= node_count
;
61 abort_search
= is_out_of_time();