- if (token == "quit" || token == "stop")
- {
- Search::Signals.stop = true;
- Threads.wait_for_search_finished(); // Cannot quit while threads are running
- }
-
- else if (token == "ponderhit")
- {
- // The opponent has played the expected move. GUI sends "ponderhit" if
- // we were told to ponder on the same move the opponent has played. We
- // should continue searching but switching from pondering to normal search.
- 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;
-
- else if (token == "position")
- set_position(pos, is);
-
- else if (token == "setoption")
- set_option(is);
-
- else if (token == "perft")
- perft(pos, is);
-
- else if (token == "d")
- pos.print();
-
- else if (token == "flip")
- pos.flip_me();
-
- 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()
- << "\npawn key: " << pos.pawn_key() << endl;
-
- else if (token == "uci")
- cout << "id name " << engine_info(true)
- << "\n" << Options
- << "\nuciok" << endl;
- else
- cout << "Unknown command: " << cmd << endl;
-
- if (!args.empty()) // Command line arguments have one-shot behaviour
- {
- Threads.wait_for_search_finished();
- break;
- }
- }
-}
-
-
-namespace {
-
- // set_position() is called when engine receives the "position" UCI
- // command. The function sets up the position described in the given
- // fen string ("fen") or the starting position ("startpos") and then
- // makes the moves given in the following move list ("moves").
-
- void set_position(Position& pos, istringstream& is) {