void set_non_pv_scores(const Position& pos);
void sort() { insertion_sort<RootMove, Base::iterator>(begin(), end()); }
- void sort_multipv(int n) { insertion_sort<RootMove, Base::iterator>(begin(), begin() + n); }
+ void sort_multipv(int n) { insertion_sort<RootMove, Base::iterator>(begin(), begin() + n + 1); }
};
wait_for_stop_or_ponderhit();
cout << "bestmove " << bookMove << endl;
- return true;
+ return !QuitRequest;
}
}
std::string name = Options["Search Log Filename"].value<std::string>();
LogFile.open(name.c_str(), std::ios::out | std::ios::app);
- LogFile << "Searching: " << pos.to_fen()
+ LogFile << "Searching: " << pos.to_fen(Options["UCI_Chess960"].value<bool>())
<< "\ninfinite: " << infinite
<< " ponder: " << ponder
<< " time: " << myTime
<< move_to_san(pos, ponderMove) // Works also with MOVE_NONE
<< endl;
+ // Return from think() with unchanged position
+ pos.undo_move(bestMove);
+
LogFile.close();
}
Iteration = 1;
// Send initial RootMoveList scoring (iteration 1)
- cout << set960(pos.is_chess960()) // Is enough to set once at the beginning
+ cout << set960(Options["UCI_Chess960"].value<bool>()) // Is enough to set once at the beginning
<< "info depth " << Iteration
<< "\n" << rml[0].pv_info_to_uci(pos, alpha, beta) << endl;
// Write PV lines to transposition table, in case the relevant entries
// have been overwritten during the search.
- for (int i = 0; i < MultiPV; i++)
+ for (int i = 0; i < Min(MultiPV, (int)rml.size()); i++)
rml[i].insert_pv_in_tt(pos);
return alpha;
}
- // current_search_time() returns the number of milliseconds which have passed
- // since the beginning of the current search.
+ // init_ss_array() does a fast reset of the first entries of a SearchStack
+ // array and of all the excludedMove and skipNullMove entries.
- int current_search_time() {
+ void init_ss_array(SearchStack* ss, int size) {
- return get_system_time() - SearchStartTime;
+ for (int i = 0; i < size; i++, ss++)
+ {
+ ss->excludedMove = MOVE_NONE;
+ ss->skipNullMove = false;
+ ss->reduction = DEPTH_ZERO;
+ ss->sp = NULL;
+
+ if (i < 3)
+ ss->killers[0] = ss->killers[1] = ss->mateKiller = MOVE_NONE;
+ }
}
return s.str();
}
- // nps() computes the current nodes/second count.
+
+ // current_search_time() returns the number of milliseconds which have passed
+ // since the beginning of the current search.
+
+ int current_search_time() {
+
+ return get_system_time() - SearchStartTime;
+ }
+
+
+ // nps() computes the current nodes/second count
int nps(const Position& pos) {
static int lastInfoTime;
int t = current_search_time();
- bool stillAtFirstMove = FirstRootMove
- && !AspirationFailLow
- && t > TimeMgr.available_time();
-
- bool noMoreTime = t > TimeMgr.maximum_time()
- || stillAtFirstMove;
-
// Poll for input
if (data_available())
{
// should continue searching but switching from pondering to normal search.
Pondering = false;
- if ( Iteration >= 3 && UseTimeManagement
- && (noMoreTime || StopOnPonderhit))
+ if (StopOnPonderhit)
StopRequest = true;
}
}
if (Pondering)
return;
- if ( (Iteration >= 3 && UseTimeManagement && noMoreTime)
- || (ExactMaxTime && t >= ExactMaxTime)
- || (Iteration >= 3 && MaxNodes && pos.nodes_searched() >= MaxNodes))
- StopRequest = true;
- }
-
-
- // init_ss_array() does a fast reset of the first entries of a SearchStack
- // array and of all the excludedMove and skipNullMove entries.
-
- void init_ss_array(SearchStack* ss, int size) {
+ bool stillAtFirstMove = FirstRootMove
+ && !AspirationFailLow
+ && t > TimeMgr.available_time();
- for (int i = 0; i < size; i++, ss++)
- {
- ss->excludedMove = MOVE_NONE;
- ss->skipNullMove = false;
- ss->reduction = DEPTH_ZERO;
- ss->sp = NULL;
+ bool noMoreTime = t > TimeMgr.maximum_time()
+ || stillAtFirstMove;
- if (i < 3)
- ss->killers[0] = ss->killers[1] = ss->mateKiller = MOVE_NONE;
- }
+ if ( (UseTimeManagement && noMoreTime)
+ || (ExactMaxTime && t >= ExactMaxTime)
+ || (MaxNodes && pos.nodes_searched() >= MaxNodes)) // FIXME
+ StopRequest = true;
}
// the UCI protocol: When pondering, the engine is not allowed to give a
// "bestmove" before the GUI sends it a "stop" or "ponderhit" command.
// We simply wait here until one of these commands is sent, and return,
- // after which the bestmove and pondermove will be printed (in id_loop()).
+ // after which the bestmove and pondermove will be printed.
void wait_for_stop_or_ponderhit() {
while (true)
{
+ // Wait for a command from stdin
if (!std::getline(std::cin, command))
command = "quit";