Add pawn ending restriction on null move pruning
[purplehaze.git] / src / time.cpp
blob8e2035507b5aa3fe1b6dbbcc22af3a51bbf48296
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 #include <iostream>
19 #include "time.h"
20 #include "assert.h"
22 void Time::start_thinking(unsigned int ply)
24 starting_time = clock();
25 abort_search = false;
26 last_poll_nodes_count = 0;
27 polling_interval = 1000000;
28 if (remaining_time != allocated_time) {
29 unsigned int n = allowed_moves;
30 unsigned int remaining_moves = n - (((ply + 1) / 2) % n);
31 assert(remaining_moves > 0);
32 allocated_time = remaining_time / remaining_moves;
33 } else {
34 assert(allowed_moves > 0);
35 allocated_time = allowed_time / allowed_moves;
38 if (allocated_time > 3000) {
39 coef_1 = 16; coef_2 = 15;
40 } else if (allocated_time > 1000) {
41 coef_1 = 4; coef_2 = 3;
42 } else {
43 coef_1 = 5; coef_2 = 3;
47 bool Time::is_out_of_time()
49 if (coef_1 * get_elapsed_time() > coef_2 * get_allocated_time()) {
50 return true;
52 return false;
55 bool Time::poll(unsigned int nodes_count)
57 if (nodes_count - last_poll_nodes_count > polling_interval) {
58 last_poll_nodes_count = nodes_count;
59 abort_search = is_out_of_time();
61 return abort_search;