1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 12:07:45 +00:00

Solitaire: Make auto_move_eligible_cards_to_foundations() iterative

This doesn't need to be recursive, so let's make it not so.
This commit is contained in:
Sam Atkins 2022-09-29 11:27:17 +01:00 committed by Sam Atkins
parent 5186e617bd
commit ff175389ab

View file

@ -486,8 +486,8 @@ bool Game::attempt_to_move_card_to_foundations(CardStack& from)
void Game::auto_move_eligible_cards_to_foundations() void Game::auto_move_eligible_cards_to_foundations()
{ {
while (true) {
bool card_was_moved = false; bool card_was_moved = false;
for (auto& to_check : stacks()) { for (auto& to_check : stacks()) {
if (to_check.type() != CardStack::Type::Normal && to_check.type() != CardStack::Type::Play) if (to_check.type() != CardStack::Type::Normal && to_check.type() != CardStack::Type::Play)
continue; continue;
@ -496,9 +496,9 @@ void Game::auto_move_eligible_cards_to_foundations()
card_was_moved = true; card_was_moved = true;
} }
// If at least one card was moved, check again to see if now any additional cards can now be moved if (!card_was_moved)
if (card_was_moved) break;
auto_move_eligible_cards_to_foundations(); }
} }
void Game::paint_event(GUI::PaintEvent& event) void Game::paint_event(GUI::PaintEvent& event)