summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Atkins <atkinssj@serenityos.org>2022-09-29 11:27:17 +0100
committerSam Atkins <atkinssj@gmail.com>2022-10-10 16:16:01 +0100
commitff175389aba66100ee707fbfba758142a8ba9865 (patch)
treee53026fdee6b65385cb511f377d15be4b99dd0ea
parent5186e617bd231acaacf970cb289450de03ef86aa (diff)
downloadserenity-ff175389aba66100ee707fbfba758142a8ba9865.zip
Solitaire: Make `auto_move_eligible_cards_to_foundations()` iterative
This doesn't need to be recursive, so let's make it not so.
-rw-r--r--Userland/Games/Solitaire/Game.cpp22
1 files changed, 11 insertions, 11 deletions
diff --git a/Userland/Games/Solitaire/Game.cpp b/Userland/Games/Solitaire/Game.cpp
index d424e59785..fc61d00e69 100644
--- a/Userland/Games/Solitaire/Game.cpp
+++ b/Userland/Games/Solitaire/Game.cpp
@@ -486,19 +486,19 @@ bool Game::attempt_to_move_card_to_foundations(CardStack& from)
void Game::auto_move_eligible_cards_to_foundations()
{
- bool card_was_moved = false;
-
- for (auto& to_check : stacks()) {
- if (to_check.type() != CardStack::Type::Normal && to_check.type() != CardStack::Type::Play)
- continue;
+ while (true) {
+ bool card_was_moved = false;
+ for (auto& to_check : stacks()) {
+ if (to_check.type() != CardStack::Type::Normal && to_check.type() != CardStack::Type::Play)
+ continue;
+
+ if (attempt_to_move_card_to_foundations(to_check))
+ card_was_moved = true;
+ }
- if (attempt_to_move_card_to_foundations(to_check))
- card_was_moved = true;
+ if (!card_was_moved)
+ break;
}
-
- // If at least one card was moved, check again to see if now any additional cards can now be moved
- if (card_was_moved)
- auto_move_eligible_cards_to_foundations();
}
void Game::paint_event(GUI::PaintEvent& event)