-namespace {
-
- // FEN string for the initial position
- const char* StarFEN = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
-
- // Keep track of position keys along the setup moves (from start position to the
- // position just before to start searching). This is needed by draw detection
- // where, due to 50 moves rule, we need to check at most 100 plies back.
- StateInfo StateRingBuf[102], *SetupState = StateRingBuf;
-
- void set_option(istringstream& up);
- void set_position(Position& pos, istringstream& up);
- void go(Position& pos, istringstream& up);
- void perft(Position& pos, istringstream& up);
-}
-
-
-/// Wait for a command from the user, parse this text string as an UCI command,
-/// and calls the appropriate functions. Also intercepts EOF from stdin to
-/// ensure 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() {
-
- Position pos(StarFEN, false, 0); // The root position
- string cmd, token;
- bool quit = false;
-
- while (!quit && getline(cin, cmd))
- {
- istringstream is(cmd);
-
- is >> skipws >> token;
-
- if (cmd == "quit" || cmd == "stop")
- {
- quit = (token == "quit");
- Search::Signals.stop = true;
- Threads[0].wake_up(); // In case is waiting for stop or ponderhit
- Threads.wait_end_of_search(); // Block here until search finishes
- }
-
- else if (cmd == "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; // FIXME racing
-
- if (Search::Signals.stopOnPonderhit)
- Search::Signals.stop = true;
-
- Threads[0].wake_up(); // In case is waiting for stop or ponderhit
- }
-
- else if (token == "go")
- go(pos, is);
-
- else if (token == "ucinewgame")
- pos.from_fen(StarFEN, false);
-
- 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")
- {
- read_evaluation_uci_options(pos.side_to_move());
- cout << trace_evaluate(pos) << endl;
- }