Explorar el Código

Chess: Send a ucinewgame command to the engine on starting a new game

This fixes an issue where the engine would crash when starting a new
game playing as white.
Tim Ledbetter hace 2 años
padre
commit
482f7f9775
Se han modificado 2 ficheros con 12 adiciones y 0 borrados
  1. 3 0
      Userland/Games/Chess/ChessWidget.cpp
  2. 9 0
      Userland/Games/Chess/Engine.h

+ 3 - 0
Userland/Games/Chess/ChessWidget.cpp

@@ -439,6 +439,9 @@ void ChessWidget::reset()
     m_board = Chess::Board();
     m_side = (get_random<u32>() % 2) ? Chess::Color::White : Chess::Color::Black;
     m_drag_enabled = true;
+    if (m_engine)
+        m_engine->start_new_game();
+
     input_engine_move();
     update();
 }

+ 9 - 0
Userland/Games/Chess/Engine.h

@@ -38,6 +38,15 @@ public:
         m_bestmove_callback = move(callback);
     }
 
+    void start_new_game()
+    {
+        if (!m_connected)
+            return;
+
+        Chess::UCI::UCINewGameCommand ucinewgame_command;
+        send_command(ucinewgame_command);
+    }
+
 private:
     void quit();
     void connect_to_engine_service();