Remove unused part of Search code
[purplehaze.git] / src / time.cpp
blob3607ec1a91c7cf6449738e62c2e08d4c015c737a
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 <cassert>
18 #include <iostream>
20 #include "time.h"
22 void Time::start_thinking(const unsigned int ply)
24 // Reset variables
25 start = std::clock();
26 abort_search = false;
27 polling.interval = 1000000;
28 polling.previous = 0;
30 clock.moves = ((ply / 2) % level.moves) + 1; // Used by allocated()
32 // Compute ratio
33 const int time_per_move = allocated();
34 if (time_per_move < 4 * 4) {
35 ratio = 4;
36 } else if (time_per_move < 8 * 8) {
37 ratio = 8;
38 } else {
39 ratio = 16;
41 if (clock.moves == level.moves) { // Last move
42 ratio /= 2;
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();
66 return abort_search;