solitaire: board stays playable with autocomplete; tap stops it (#owner-report)
- Commit
7b5580f8e608d4093dc0eaf54edcf86526268431- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-12 20:47 UTC (23 days ago)
- Parents
31e9891
Request (owner report): "when autocomplete shows up, still allow the user to play if they want to". Findings: merely showing the Auto-complete button locked nothing in the view model, but once a run started every board input (card tap, drag, stock tap) called skipAutoCompleteToEnd(), i.e. any attempt to play on finished the whole game for the player instead. Under the old staged-flight model a tap or drag was also refused outright while any flight was in the air, which made the board feel locked around auto-complete hops. Fix: - Offering auto-complete locks nothing (now pinned by a test): tap, drag and stock all play normally while the button is shown, and no run starts until the button is pressed. - During a run, board input stops it (stopAutoComplete): steps taken so far stay applied, the hop in the air lands, nothing else moves, and the board is playable again with the offer back if it can still finish. The input that stops the run is consumed as the stop. - The button keeps its mid-run "Skip" role (finish instantly), and one undo still restores the pre-run board. User-visible effect: the player can ignore the Auto-complete offer and keep playing, and can interrupt a running auto-complete with a tap to take over. Verification: SolitaireAutoCompleteTest: tap/drag/stock mid-run stop the run after the in-flight hop, leave history at one entry and the board playable; offeredButNotStartedLocksNothing. :games:solitaire:testDevUnitTest in the container build.
Diff
games/solitaire/src/main/java/com/vayunmathur/games/solitaire/platform/SolitaireKlondikeOps.kt
diff --git a/games/solitaire/src/main/java/com/vayunmathur/games/solitaire/platform/SolitaireKlondikeOps.kt b/games/solitaire/src/main/java/com/vayunmathur/games/solitaire/platform/SolitaireKlondikeOps.ktindex c311353e6e..f5cfea5c26 100644--- a/games/solitaire/src/main/java/com/vayunmathur/games/solitaire/platform/SolitaireKlondikeOps.kt+++ b/games/solitaire/src/main/java/com/vayunmathur/games/solitaire/platform/SolitaireKlondikeOps.kt@@ -247,7 +247,9 @@ internal fun SolitaireViewModel.runAutoCompleteLoop(start: KlondikeState): Klond } /**- * Animated auto-complete entry: the button tap (and re-tap) lands here. A tap+ * Animated auto-complete entry: the button tap (and re-tap) lands here. Merely+ * offering the button locks nothing; only a started run pauses board input, and+ * board input then stops the run ([stopAutoComplete]). Re-tapping the button * mid-run skips straight to the finished board; otherwise the run applies one * step at a time and flies each foundation hop, continuing when that hop lands * ([landFlightImpl]). One history entry covers the whole run, so a single undo@@ -310,6 +312,17 @@ private fun autoCompleteStep(before: KlondikeState, after: KlondikeState): AutoC after.foundations[fi].size == before.foundations[fi].size + 1 }?.let { fi -> AutoCompleteStep(after.foundations[fi].last(), fi) } +/**+ * Stops a running auto-complete where it is: every step taken so far stays applied (one+ * undo still restores the pre-run board), the hop in the air lands, and the board is+ * playable again with the offer back if it can still finish. A tap, drag or stock tap+ * on the board mid-run lands here.+ */+internal fun SolitaireViewModel.stopAutoComplete() {+ autoCompleteRunningInternal.value = false+ autoCompleteFlightId = null+}+ /** * Skips the animation: runs the shared loop to the end on the live state. Hops * already in the air are left to land — their moves are applied already.
games/solitaire/src/main/java/com/vayunmathur/games/solitaire/platform/SolitaireViewModel.kt
diff --git a/games/solitaire/src/main/java/com/vayunmathur/games/solitaire/platform/SolitaireViewModel.kt b/games/solitaire/src/main/java/com/vayunmathur/games/solitaire/platform/SolitaireViewModel.ktindex 663e076d1a..8144485699 100644--- a/games/solitaire/src/main/java/com/vayunmathur/games/solitaire/platform/SolitaireViewModel.kt+++ b/games/solitaire/src/main/java/com/vayunmathur/games/solitaire/platform/SolitaireViewModel.kt@@ -156,8 +156,8 @@ class SolitaireViewModel(application: Application) : AndroidViewModel(applicatio // Public game operations live as extensions in SolitaireKlondikeOps.kt. override fun drawFromStock() {- // Any tap mid-run skips the animation straight to the finished board.- if (autoCompleteRunningInternal.value) { skipAutoCompleteToEnd(); return }+ // Input mid-run stops the run where it is; the board stays playable.+ if (autoCompleteRunningInternal.value) { stopAutoComplete(); return } drawFromStockImpl() } @@ -192,7 +192,7 @@ class SolitaireViewModel(application: Application) : AndroidViewModel(applicatio override fun autoMove(sourceId: String) = autoMoveImpl(sourceId) override fun requestAutoMove(sourceId: String, startPos: Offset, cardSize: IntSize): Boolean {- if (autoCompleteRunningInternal.value) { skipAutoCompleteToEnd(); return false }+ if (autoCompleteRunningInternal.value) { stopAutoComplete(); return false } return requestFlightImpl(sourceId, startPos, cardSize) } @@ -207,7 +207,7 @@ class SolitaireViewModel(application: Application) : AndroidViewModel(applicatio startPos: Offset, cardSize: IntSize, ): Boolean {- if (autoCompleteRunningInternal.value) { skipAutoCompleteToEnd(); return false }+ if (autoCompleteRunningInternal.value) { stopAutoComplete(); return false } return startDragImpl(sourceId, startPos, cardSize) }
games/solitaire/src/main/java/com/vayunmathur/games/solitaire/ui/GameBoardScreen.kt
diff --git a/games/solitaire/src/main/java/com/vayunmathur/games/solitaire/ui/GameBoardScreen.kt b/games/solitaire/src/main/java/com/vayunmathur/games/solitaire/ui/GameBoardScreen.ktindex 0c4385b31b..cf21efa7ec 100644--- a/games/solitaire/src/main/java/com/vayunmathur/games/solitaire/ui/GameBoardScreen.kt+++ b/games/solitaire/src/main/java/com/vayunmathur/games/solitaire/ui/GameBoardScreen.kt@@ -77,8 +77,10 @@ fun GameBoardScreen(state: SolitaireUiState, mode: GameMode, actions: SolitaireA when (mode) { GameMode.KLONDIKE -> state.klondike?.let { KlondikeBoard(it, actions, Modifier.align(Alignment.CenterHorizontally).widthIn(max = boardMaxWidth).fillMaxWidth())- // The button stays up mid-run as the skip switch: draining- // foundations can otherwise hide it under the player's tap.+ // Offering the button locks nothing: the board stays fully+ // playable. It stays up mid-run as the skip switch (draining+ // foundations can otherwise hide it under the player's tap),+ // and any tap on the board mid-run stops the run instead. val autoCompleteRunning by actions.autoCompleteRunning.collectAsState() if (canKlondikeAutoComplete(it) || autoCompleteRunning) { Button(onClick = { actions.klondikeAutoComplete() }, Modifier.align(Alignment.CenterHorizontally)) {
games/solitaire/src/test/java/com/vayunmathur/games/solitaire/platform/SolitaireAutoCompleteTest.kt
diff --git a/games/solitaire/src/test/java/com/vayunmathur/games/solitaire/platform/SolitaireAutoCompleteTest.kt b/games/solitaire/src/test/java/com/vayunmathur/games/solitaire/platform/SolitaireAutoCompleteTest.ktindex 821943db69..5c0a3914a9 100644--- a/games/solitaire/src/test/java/com/vayunmathur/games/solitaire/platform/SolitaireAutoCompleteTest.kt+++ b/games/solitaire/src/test/java/com/vayunmathur/games/solitaire/platform/SolitaireAutoCompleteTest.kt@@ -20,10 +20,11 @@ import org.robolectric.RobolectricTestRunner import org.robolectric.annotation.Config /**- * Animated Klondike auto-complete: the run stages one fast flight per step while a- * card position is known, applies the rest instantly, and any tap mid-run skips to- * the finished board. Every path must end on the same legal won board the instant- * loop produces, with a single history entry so one undo restores the pre-run board.+ * Animated Klondike auto-complete: the run applies each step and flies it while a card+ * position is known, and applies the rest instantly. Board input mid-run stops it where+ * it is, the button re-tap skips to the finished board, and merely offering it locks+ * nothing. A run to the end lands on the same legal won board as the instant loop, and+ * a single history entry lets one undo restore the pre-run board. */ @RunWith(RobolectricTestRunner::class) @Config(sdk = [34])@@ -109,39 +110,66 @@ class SolitaireAutoCompleteTest { assertTrue(k.foundations.all { it.size == 13 }) } - @Test fun tapMidRunSkipsToWin() {+ /** Starts a run whose first hop (the waste King) is in the air. */+ private fun startedRun(): SolitaireViewModel { val vm = vm() setK(vm, almostWon()) vm.registerCardPosition(Card(Suit.HEARTS, Rank.KING), Offset(10f, 10f))+ vm.registerCardPosition(Card(Suit.DIAMONDS, Rank.KING), Offset(20f, 20f)) vm.klondikeAutoComplete() assertTrue(vm.autoCompleteRunning.value)- assertFalse(vm.requestAutoMove("waste", Offset.Zero))- assertFalse(vm.autoCompleteRunning.value)- // The hop already in the air is left to land; its move is applied.- assertEquals(1, vm.flights.value.size)- assertTrue(vm.uiState.value.klondike!!.isWon)+ return vm } - @Test fun dragMidRunSkipsToWin() {- val vm = vm()- setK(vm, almostWon())- vm.registerCardPosition(Card(Suit.HEARTS, Rank.KING), Offset(10f, 10f))- vm.klondikeAutoComplete()- assertTrue(vm.autoCompleteRunning.value)- assertFalse(vm.startDrag("waste", Offset.Zero))+ /** After a stop: the hop that was flying lands, nothing else moves, the board plays on. */+ private fun assertStoppedAfterFirstHop(vm: SolitaireViewModel) { assertFalse(vm.autoCompleteRunning.value)- assertTrue(vm.uiState.value.klondike!!.isWon)+ val hop = vm.flights.value.single()+ vm.landFlight(hop.id)+ assertTrue(vm.flights.value.isEmpty())+ val k = vm.uiState.value.klondike!!+ assertFalse(k.isWon)+ assertEquals(13, k.foundations[0].size) // the hearts King that was flying+ assertEquals(listOf(Card(Suit.DIAMONDS, Rank.KING)), k.tableauPiles[0].faceUp)+ assertEquals(1, vm.uiState.value.history.size)+ // The offer is back, and the board takes ordinary moves again.+ assertTrue(canKlondikeAutoComplete(k))+ assertTrue(vm.requestAutoMove("tableau_0_0", Offset(1f, 1f)))+ assertEquals(13, vm.uiState.value.klondike!!.foundations[1].size)+ }++ @Test fun tapMidRunStopsTheRun() {+ val vm = startedRun()+ assertFalse(vm.requestAutoMove("tableau_1_0", Offset.Zero)) // the tap is the stop+ assertStoppedAfterFirstHop(vm) } - @Test fun stockTapMidRunSkipsToWin() {+ @Test fun dragMidRunStopsTheRun() {+ val vm = startedRun()+ assertFalse(vm.startDrag("tableau_1_0", Offset.Zero))+ assertStoppedAfterFirstHop(vm)+ }++ @Test fun stockTapMidRunStopsTheRun() {+ val vm = startedRun()+ vm.drawFromStock()+ assertEquals(listOf(Card(Suit.SPADES, Rank.KING)), vm.uiState.value.klondike!!.stock)+ assertStoppedAfterFirstHop(vm)+ }++ @Test fun offeredButNotStartedLocksNothing() { val vm = vm() setK(vm, almostWon())- vm.registerCardPosition(Card(Suit.HEARTS, Rank.KING), Offset(10f, 10f))- vm.klondikeAutoComplete()- assertTrue(vm.autoCompleteRunning.value)+ assertTrue(canKlondikeAutoComplete(vm.uiState.value.klondike!!))+ // Tap, stock and drag all play normally; no run starts.+ assertTrue(vm.requestAutoMove("waste", Offset.Zero))+ assertTrue(vm.uiState.value.klondike!!.waste.isEmpty()) vm.drawFromStock()+ assertEquals(listOf(Card(Suit.SPADES, Rank.KING)), vm.uiState.value.klondike!!.waste)+ assertTrue(vm.startDrag("tableau_0_0", Offset.Zero))+ vm.cancelDrag() assertFalse(vm.autoCompleteRunning.value)- assertTrue(vm.uiState.value.klondike!!.isWon)+ assertEquals(2, vm.uiState.value.klondike!!.moveCount) } @Test fun buttonRetapMidRunSkipsToWin() {