- else if (token == "key")
- sync_cout << "key: " << hex << pos.key()
- << "\nmaterial key: " << pos.material_key()
- << "\npawn key: " << pos.pawn_key() << sync_endl;
+void UCI::loop(int argc, char* argv[]) {
+
+ Position pos;
+ string token, cmd;
+ Thread* uiThread = new Thread();
+
+ pos.set(StartFEN, false, &States->back(), uiThread);
+
+ for (int i = 1; i < argc; ++i)
+ cmd += std::string(argv[i]) + " ";
+
+ do {
+ if (argc == 1 && !getline(cin, cmd)) // Block here waiting for input or EOF
+ cmd = "quit";
+
+ istringstream is(cmd);
+
+ token.clear(); // getline() could return empty or blank line
+ is >> skipws >> token;
+
+ // The GUI sends 'ponderhit' to tell us to ponder on the same move the
+ // opponent has played. In case Threads.stopOnPonderhit is set we are
+ // waiting for 'ponderhit' to stop the search (for instance because we
+ // already ran out of time), otherwise we should continue searching but
+ // switching from pondering to normal search.
+ if ( token == "quit"
+ || token == "stop"
+ || (token == "ponderhit" && Threads.stopOnPonderhit))
+ {
+ Threads.stop = true;
+ Threads.main()->start_searching(true); // Could be sleeping
+ }
+ else if (token == "ponderhit")
+ Threads.ponder = false; // Switch to normal search