1 /* Copyright (C) 2007-2012 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 clock
.moves
= ((ply
/ 2) % level
.moves
) + 1; // Used by allocated()
33 const int time_per_move
= allocated();
34 if (time_per_move
< 4 * 4) {
36 } else if (time_per_move
< 8 * 8) {
41 if (clock
.moves
== level
.moves
) { // Last move
46 std::cout << "# start_thinking(" << ply << ")" << std::endl;
47 std::cout << "#\tlevel = {" << level.moves << ", " << level.time << "}" << std::endl;
48 std::cout << "#\tclock = {" << clock.moves << ", " << clock.time << "}" << std::endl;
49 std::cout << "#\tratio = " << ratio << std::endl;
50 std::cout << "#\ttpm = " << time_per_move << std::endl;
54 inline bool Time::is_out_of_time() const
56 return ratio
* elapsed() > (ratio
- 1) * allocated();
59 bool Time::poll(const unsigned int node_count
)
61 // Avoid wasting time by calling 'is_out_of_time()' too frequently
62 if (node_count
- polling
.previous
> polling
.interval
) {
63 polling
.previous
= node_count
;
64 abort_search
= abort_search
|| is_out_of_time();