diff options
author | Tim Ledbetter <timledbetter@gmail.com> | 2023-04-26 19:03:48 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-04-28 05:55:51 +0200 |
commit | 482f7f977573799dbbd7e88fb5f2df1eb19b8fae (patch) | |
tree | 242bd19d1915fbf7472aafe8dbd8612b0eb558ae /Userland/Games/Chess | |
parent | 536f6b8b3467e5b0a15bce29b7375e1e2a0cc2d6 (diff) | |
download | serenity-482f7f977573799dbbd7e88fb5f2df1eb19b8fae.zip |
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.
Diffstat (limited to 'Userland/Games/Chess')
-rw-r--r-- | Userland/Games/Chess/ChessWidget.cpp | 3 | ||||
-rw-r--r-- | Userland/Games/Chess/Engine.h | 9 |
2 files changed, 12 insertions, 0 deletions
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<u32>() % 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(); |