- // handle_command() takes a text string as input, uses a
- // UCIInputParser object to parse this text string as a UCI command,
- // and calls the appropriate functions. In addition to the UCI
- // commands, the function also supports a few debug commands.
-
- void handle_command(const std::string &command) {
-
- UCIInputParser uip(command);
- std::string token = uip.get_next_token();
-
- if(token == "quit") {
- OpeningBook.close();
- stop_threads();
- quit_eval();
- exit(0);
- }
- else if(token == "uci") {
- std::cout << "id name " << engine_name() << std::endl;
- std::cout << "id author Tord Romstad" << std::endl;
- print_uci_options();
- std::cout << "uciok" << std::endl;
- }
- else if(token == "ucinewgame") {
- TT.clear();
- Position::init_piece_square_tables();
- RootPosition.from_fen(StartPosition);
- }
- else if(token == "isready")
- std::cout << "readyok" << std::endl;
- else if(token == "position")
- set_position(uip);
- else if(token == "setoption")
- set_option(uip);
- else if(token == "go")
- go(uip);
-
- // The remaining commands are for debugging purposes only.
- // Perhaps they should be removed later in order to reduce the
- // size of the program binary.
- else if(token == "d")
- RootPosition.print();
- else if(token == "flip") {
- Position p(RootPosition);
- RootPosition.flipped_copy(p);
- }
- else if(token == "eval") {
- EvalInfo ei;
- std::cout << "Incremental mg: " << RootPosition.mg_value()
- << std::endl;
- std::cout << "Incremental eg: " << RootPosition.eg_value()
- << std::endl;
- std::cout << "Full eval: "
- << evaluate(RootPosition, ei, 0)
- << std::endl;
- }
- else if(token == "key") {
- std::cout << "key: " << RootPosition.get_key()
- << " material key: " << RootPosition.get_material_key()
- << " pawn key: " << RootPosition.get_pawn_key()
- << std::endl;
+ // go() is called when engine receives the "go" UCI command. The function sets
+ // the thinking time and other parameters from the input string, and starts
+ // the search.
+
+ void go(const Position& pos, istringstream& is) {
+
+ Search::LimitsType limits;
+ string token;
+
+ while (is >> token)
+ {
+ if (token == "searchmoves")
+ while (is >> token)
+ limits.searchmoves.push_back(move_from_uci(pos, token));
+
+ else if (token == "wtime") is >> limits.time[WHITE];
+ else if (token == "btime") is >> limits.time[BLACK];
+ else if (token == "winc") is >> limits.inc[WHITE];
+ else if (token == "binc") is >> limits.inc[BLACK];
+ else if (token == "movestogo") is >> limits.movestogo;
+ else if (token == "depth") is >> limits.depth;
+ else if (token == "nodes") is >> limits.nodes;
+ else if (token == "movetime") is >> limits.movetime;
+ else if (token == "mate") is >> limits.mate;
+ else if (token == "infinite") limits.infinite = true;
+ else if (token == "ponder") limits.ponder = true;