diff options
author | Gunnar Beutner <gbeutner@serenityos.org> | 2021-05-24 17:27:26 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-05-25 21:05:35 +0200 |
commit | e636ed43ebad685fc67f510b6c492418c0a572dd (patch) | |
tree | 7368448dca4e2b458b47a6e07a4de1f0fd7de6eb /Userland/Games | |
parent | ac1eba2f7cfff02d4558191ff9dcbc5eb8dfb440 (diff) | |
download | serenity-e636ed43ebad685fc67f510b6c492418c0a572dd.zip |
Hearts: Let the AI continuously play games
When there are no human players (toggled with Shift-F10) the AI will
continuously start new games when the current game has finished.
Diffstat (limited to 'Userland/Games')
-rw-r--r-- | Userland/Games/Hearts/Game.cpp | 14 | ||||
-rw-r--r-- | Userland/Games/Hearts/Game.h | 2 |
2 files changed, 15 insertions, 1 deletions
diff --git a/Userland/Games/Hearts/Game.cpp b/Userland/Games/Hearts/Game.cpp index efc550ff03..10554b9034 100644 --- a/Userland/Games/Hearts/Game.cpp +++ b/Userland/Games/Hearts/Game.cpp @@ -337,11 +337,23 @@ void Game::continue_game_after_delay(int interval_ms) void Game::advance_game() { - if (game_ended()) { + if (m_state == State::Play && game_ended()) { + m_state = State::GameEndedWaiting; on_status_change("Game ended."); + continue_game_after_delay(2000); return; } + if (m_state == State::GameEndedWaiting) { + m_state = State::GameEnded; + if (!m_players[0].is_human) + setup(move(m_players[0].name)); + return; + } + + if (m_state == State::GameEnded) + return; + if (m_state == State::PassingSelect) { if (!m_players[0].is_human) { select_cards_for_passing(); diff --git a/Userland/Games/Hearts/Game.h b/Userland/Games/Hearts/Game.h index 20e8385200..0447c656b0 100644 --- a/Userland/Games/Hearts/Game.h +++ b/Userland/Games/Hearts/Game.h @@ -77,6 +77,8 @@ private: PassingSelectConfirmed, PassingAccept, Play, + GameEndedWaiting, + GameEnded, }; State m_state { State::PassingSelect }; |