mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 06:57: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:
parent
5186e617bd
commit
ff175389ab
1 changed files with 10 additions and 10 deletions
|
@ -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;
|
||||
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;
|
||||
|
||||
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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue