From 482f7f977573799dbbd7e88fb5f2df1eb19b8fae Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Wed, 26 Apr 2023 19:03:48 +0100 Subject: 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. --- Userland/Games/Chess/ChessWidget.cpp | 3 +++ Userland/Games/Chess/Engine.h | 9 +++++++++ 2 files changed, 12 insertions(+) (limited to 'Userland/Games/Chess') diff --git a/Userland/Games/Chess/ChessWidget.cpp b/Userland/Games/Chess/ChessWidget.cpp index 0185c5b54a..99a92728e1 100644 --- a/Userland/Games/Chess/ChessWidget.cpp +++ b/Userland/Games/Chess/ChessWidget.cpp @@ -439,6 +439,9 @@ void ChessWidget::reset() m_board = Chess::Board(); m_side = (get_random() % 2) ? Chess::Color::White : Chess::Color::Black; m_drag_enabled = true; + if (m_engine) + m_engine->start_new_game(); + input_engine_move(); update(); } diff --git a/Userland/Games/Chess/Engine.h b/Userland/Games/Chess/Engine.h index efbfd5b463..7b86d50f8a 100644 --- a/Userland/Games/Chess/Engine.h +++ b/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(); -- cgit v1.2.3