- // 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 call 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(StartFEN, false, 0); // The root position
- string cmd, token;
-
- while (token != "quit")
- {
- if (!getline(cin, cmd)) // Block here waiting for input
- cmd = "quit";
-
- istringstream is(cmd);
-
- is >> skipws >> token;
-
- 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 == "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;
- }
-}
-