using namespace std;
+extern void benchmark(istringstream& is);
+
namespace {
// FEN string of the initial position, normal chess
/// that we exit gracefully if the GUI dies unexpectedly. In addition to the UCI
/// commands, the function also supports a few debug commands.
-void uci_loop() {
+void uci_loop(const string& args) {
- Position pos(StartFEN, false, 0); // The root position
+ Position pos(StartFEN, false); // The root position
string cmd, token;
while (token != "quit")
{
- if (!getline(cin, cmd)) // Block here waiting for input
+ if (!args.empty())
+ cmd = args;
+
+ else if (!getline(cin, cmd)) // Block here waiting for input
cmd = "quit";
istringstream is(cmd);
if (token == "quit" || token == "stop")
{
Search::Signals.stop = true;
-
- if (token == "quit") // Cannot quit while threads are still running
- Threads.wait_for_search_finished();
+ Threads.wait_for_search_finished(); // Cannot quit while threads are running
}
else if (token == "ponderhit")
Search::Limits.ponder = false;
if (Search::Signals.stopOnPonderhit)
+ {
Search::Signals.stop = true;
+ Threads.wait_for_search_finished(); // Wake up if is sleeping
+ }
}
else if (token == "go")
go(pos, is);
+ else if (token == "ucinewgame")
+ { /* Avoid returning "Unknown command" */ }
+
else if (token == "isready")
cout << "readyok" << endl;
pos.print();
else if (token == "flip")
- pos.flip_me();
+ pos.flip();
else if (token == "eval")
cout << Eval::trace(pos) << endl;
+ else if (token == "bench")
+ benchmark(is);
+
else if (token == "key")
cout << "key: " << hex << pos.key()
<< "\nmaterial key: " << pos.material_key()
<< "\nuciok" << endl;
else
cout << "Unknown command: " << cmd << endl;
+
+ if (!args.empty()) // Command line arguments have one-shot behaviour
+ {
+ Threads.wait_for_search_finished();
+ break;
+ }
}
}
void go(Position& pos, istringstream& is) {
Search::LimitsType limits;
- std::set<Move> searchMoves;
+ vector<Move> searchMoves;
string token;
while (is >> token)
{
if (token == "wtime")
- is >> limits.times[WHITE];
+ is >> limits.time[WHITE];
else if (token == "btime")
- is >> limits.times[BLACK];
+ is >> limits.time[BLACK];
else if (token == "winc")
- is >> limits.incs[WHITE];
+ is >> limits.inc[WHITE];
else if (token == "binc")
- is >> limits.incs[BLACK];
+ is >> limits.inc[BLACK];
else if (token == "movestogo")
is >> limits.movestogo;
else if (token == "depth")
limits.ponder = true;
else if (token == "searchmoves")
while (is >> token)
- searchMoves.insert(move_from_uci(pos, token));
+ searchMoves.push_back(move_from_uci(pos, token));
}
Threads.start_searching(pos, limits, searchMoves);
int e = time.elapsed();
- std::cout << "\nNodes " << n
- << "\nTime (ms) " << e
- << "\nNodes/second " << int(n / (e / 1000.0)) << std::endl;
+ cout << "\nNodes " << n
+ << "\nTime (ms) " << e
+ << "\nNodes/second " << int(n / (e / 1000.0)) << endl;
}
}