瀏覽代碼

Chess: Send a quit command to ChessEngine when it is no longer in use

The chess GUI now instructs the ChessEngine to gracefully exit by
sending a UCI quit command.
Tim Ledbetter 2 年之前
父節點
當前提交
bf320e4826
共有 2 個文件被更改,包括 8 次插入3 次删除
  1. 6 2
      Userland/Games/Chess/Engine.cpp
  2. 2 1
      Userland/Games/Chess/Engine.h

+ 6 - 2
Userland/Games/Chess/Engine.cpp

@@ -13,8 +13,7 @@
 
 Engine::~Engine()
 {
-    if (m_pid != -1)
-        kill(m_pid, SIGINT);
+    quit();
 }
 
 Engine::Engine(StringView command)
@@ -66,3 +65,8 @@ void Engine::handle_bestmove(Chess::UCI::BestMoveCommand const& command)
 
     m_bestmove_callback = nullptr;
 }
+
+void Engine::quit()
+{
+    send_command(Chess::UCI::QuitCommand());
+}

+ 2 - 1
Userland/Games/Chess/Engine.h

@@ -33,6 +33,7 @@ public:
     }
 
 private:
+    void quit();
+
     Function<void(Chess::Move)> m_bestmove_callback;
-    pid_t m_pid { -1 };
 };