1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-07-15 21:39:14 +00:00

Cleanup poll()

Reshape this function in preparation
for future work.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba 2008-09-18 10:34:19 +01:00
parent 18860cce40
commit 5c4f6f6226

View file

@ -2136,62 +2136,64 @@ namespace {
// search. // search.
void poll() { void poll() {
int t, data;
static int lastInfoTime;
t = current_search_time(); static int lastInfoTime;
int t = current_search_time();
// Poll for input // Poll for input
data = Bioskey(); if (Bioskey())
if(data) { {
char input[256]; // We are line oriented, don't read single chars
if(fgets(input, 255, stdin) == NULL) std::string command;
strncpy(input, "quit\n", 5); if (!std::getline(std::cin, command))
if(strncmp(input, "quit", 4) == 0) { command = "quit";
AbortSearch = true;
PonderSearch = false;
Quit = true;
}
else if(strncmp(input, "stop", 4) == 0) {
AbortSearch = true;
PonderSearch = false;
}
else if(strncmp(input, "ponderhit", 9) == 0)
ponderhit();
}
if (command == "quit")
{
AbortSearch = true;
PonderSearch = false;
Quit = true;
}
else if(command == "stop")
{
AbortSearch = true;
PonderSearch = false;
}
else if(command == "ponderhit")
ponderhit();
}
// Print search information // Print search information
if(t < 1000) if (t < 1000)
lastInfoTime = 0; lastInfoTime = 0;
else if(lastInfoTime > t)
// HACK: Must be a new search where we searched less than else if (lastInfoTime > t)
// NodesBetweenPolls nodes during the first second of search. // HACK: Must be a new search where we searched less than
lastInfoTime = 0; // NodesBetweenPolls nodes during the first second of search.
else if(t - lastInfoTime >= 1000) { lastInfoTime = 0;
lastInfoTime = t;
lock_grab(&IOLock); else if (t - lastInfoTime >= 1000)
std::cout << "info nodes " << nodes_searched() << " nps " << nps() {
<< " time " << t << " hashfull " << TT.full() << std::endl; lastInfoTime = t;
lock_release(&IOLock); lock_grab(&IOLock);
if(ShowCurrentLine) std::cout << "info nodes " << nodes_searched() << " nps " << nps()
Threads[0].printCurrentLine = true; << " time " << t << " hashfull " << TT.full() << std::endl;
lock_release(&IOLock);
if (ShowCurrentLine)
Threads[0].printCurrentLine = true;
} }
// Should we stop the search? // Should we stop the search?
if(!PonderSearch && Iteration >= 2 && if (PonderSearch)
(!InfiniteSearch && (t > AbsoluteMaxSearchTime || return;
(RootMoveNumber == 1 &&
t > MaxSearchTime + ExtraSearchTime) ||
(!FailHigh && !fail_high_ply_1() && !Problem &&
t > 6*(MaxSearchTime + ExtraSearchTime)))))
AbortSearch = true;
if(!PonderSearch && ExactMaxTime && t >= ExactMaxTime) bool overTime = t > AbsoluteMaxSearchTime
AbortSearch = true; || (RootMoveNumber == 1 && t > MaxSearchTime + ExtraSearchTime)
|| ( !FailHigh && !fail_high_ply_1() && !Problem
&& t > 6*(MaxSearchTime + ExtraSearchTime));
if(!PonderSearch && Iteration >= 3 && MaxNodes if ( (Iteration >= 2 && (!InfiniteSearch && overTime))
&& nodes_searched() >= MaxNodes) || (ExactMaxTime && t >= ExactMaxTime)
AbortSearch = true; || (Iteration >= 3 && MaxNodes && nodes_searched() >= MaxNodes))
AbortSearch = true;
} }