12 std::cout.setf(std::ios::unitbuf);
14 m_thread = std::thread([
this] { runLoop(); });
18 if (m_thread.joinable()) {
24 static bool inputAvailable() {
27 FD_SET(STDIN_FILENO, &readfds);
28 timeval timeout = {.tv_sec = 0, .tv_usec = 0};
29 return select(STDIN_FILENO + 1, &readfds,
nullptr,
nullptr, &timeout) > 0;
34 while (!m_state->shouldQuit()) {
35 if (inputAvailable()) {
36 if (std::getline(std::cin, line)) {
38 m_state->signalQuit();
44 std::this_thread::sleep_for(std::chrono::milliseconds(10));
49 void processCommand(
const std::string& command) {
50 if (command ==
"uci") {
51 std::cout <<
"uciok\n";
52 }
else if (command.starts_with(
"position")) {
53 handlePosition(command);
54 }
else if (command.starts_with(
"go perft")) {
59 void handlePosition(
const std::string& command) {
60 m_state->applyToAllGames([&](
Game& game) {
61 if (command.find(
"startpos") != std::string::npos) {
63 }
else if (command.find(
"fen") != std::string::npos) {
67 size_t movesPos = command.find(
"moves");
68 if (movesPos != std::string::npos) {
69 std::istringstream iss(command.substr(movesPos + 6));
79 void handlePerft(
const std::string& ) {