fix(web): auto-complete now works with cards remaining in waste

check_auto_complete no longer requires the waste pile to be empty —
only the stock must be exhausted and all tableau cards face-up.
next_auto_complete_move checks the waste top card before scanning
tableau, and auto_complete_step falls back to draw() when no direct
foundation move is available so the waste drains automatically.

Fixes the end-game state where the player could see a clear win but
the auto-complete interval never fired because the waste was non-empty.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
funman300
2026-05-13 21:30:42 -07:00
parent d685224ce6
commit 1b7c4d92aa
4 changed files with 65 additions and 45 deletions
+12 -7
View File
@@ -412,17 +412,22 @@ impl SolitaireGame {
}
/// Apply one auto-complete move (only valid when `is_auto_completable`).
/// Returns the post-move snapshot or `null` when auto-complete is unavailable.
///
/// If no card can go directly to a foundation this step, advances the
/// waste by calling `draw()` so the next step can try again. Returns the
/// post-move snapshot, or `null` when no progress is possible.
pub fn auto_complete_step(&mut self) -> JsValue {
if !self.game.is_auto_completable {
return JsValue::NULL;
}
match self.game.next_auto_complete_move() {
Some((from, to)) => {
let _ = self.game.move_cards(from, to, 1);
self.ok_js()
}
None => JsValue::NULL,
if let Some((from, to)) = self.game.next_auto_complete_move() {
let _ = self.game.move_cards(from, to, 1);
return self.ok_js();
}
// No direct foundation move — advance through the waste.
match self.game.draw() {
Ok(()) => self.ok_js(),
Err(_) => JsValue::NULL,
}
}
}