+ // Read option name (can contain spaces)
+ while (is >> token && token != "value")
+ name += string(" ", name.empty() ? 0 : 1) + token;
+
+ // Read option value (can contain spaces)
+ while (is >> token)
+ value += string(" ", value.empty() ? 0 : 1) + token;
+
+ if (Options.count(name))
+ Options[name] = value;
+ else
+ sync_cout << "No such option: " << name << sync_endl;
+ }
+
+
+ // go() is called when engine receives the "go" UCI command. The function sets
+ // the thinking time and other parameters from the input string, then starts
+ // the search.
+
+ void go(Position& pos, istringstream& is) {
+
+ Search::LimitsType limits;
+ string token;
+
+ limits.startTime = now(); // As early as possible!
+
+ while (is >> token)
+ if (token == "searchmoves")
+ while (is >> token)
+ limits.searchmoves.push_back(UCI::to_move(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 = 1;
+ else if (token == "ponder") limits.ponder = 1;
+
+ Threads.start_thinking(pos, States, limits);
+ }
+
+} // namespace
+
+
+/// UCI::loop() waits for a command from stdin, parses it and calls the appropriate
+/// function. Also intercepts EOF from stdin to ensure gracefully exiting if the
+/// GUI dies unexpectedly. When called with some command line arguments, e.g. to
+/// run 'bench', once the command is executed the function returns immediately.
+/// In addition to the UCI ones, also some additional debug commands are supported.