- // 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 s = uip.get_next_token();
-
- if(s == "quit") {
- OpeningBook.close();
- stop_threads();
- quit_eval();
- exit(0);
- }
- else if(s == "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(s == "ucinewgame") {
- TT.clear();
- Position::init_piece_square_tables();
- RootPosition.from_fen(StartPosition);
- }
- else if(s == "isready")
- std::cout << "readyok" << std::endl;
- else if(s == "position")
- set_position(uip);
- else if(s == "setoption")
- set_option(uip);
- else if(s == "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(s == "d")
- RootPosition.print();
- else if(s == "flip") {
- Position p(RootPosition);
- RootPosition.flipped_copy(p);
- }
- else if(s == "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(s == "key") {
- std::cout << "key: " << RootPosition.get_key()
- << " material key: " << RootPosition.get_material_key()
- << " pawn key: " << RootPosition.get_pawn_key()
- << std::endl;
- }
- else {
- std::cout << "Unknown command: " << command << std::endl;
- while(!uip.at_end_of_line()) {
- std::cout << uip.get_next_token() << std::endl;
- }
- }
- }
+ // set_option() is called when Stockfish receives the "setoption" UCI
+ // command. The input parameter is a UCIParser. It is assumed
+ // that this parser has consumed the first token of the UCI command
+ // ("setoption"), and is ready to read the second token ("name", if
+ // the input is well-formed).