Modern Apps git

← Modern-Apps.git

games-solitaire: clear stale waste selection on deal

Commit
7680e715f625d3f0396b3158b5568c968f32fe52
Author
Vayun Mathur <[email protected]>
When
2026-11-07 20:02 UTC (29 days ago)
Parents
6df9252
Symptom: in Pyramid, select the waste card, then tap the
stock to deal. The selection highlight stayed on the waste
slot, but the waste top was now a different card, so the
next tap could pair-remove a card the player never picked.

Root cause: pyramidDealStockImpl replaced the waste top in
its draw branch without touching selectedId, while the
recycle branch already cleared the selection. The "waste"
selection id names a slot, not a card, so it silently
retargeted on every deal.

Fix: when dealing, clear selectedId only if it is "waste";
a pyramid selection (pyr_r_c) names a fixed card and is
preserved across deals, matching player intent.

Verification: new regression test
pyramidDealClearsWasteSelectionOnly in SpiderPyramidOpsTest
(waste selection cleared and new waste top kept; pyramid
selection survives a deal). Ran
:games:solitaire:testDevUnitTest for DragAndViewModelTest and
SpiderPyramidOpsTest: BUILD SUCCESSFUL.

Diff

games/solitaire/src/main/java/com/vayunmathur/games/solitaire/platform/SolitairePyramidOps.kt
diff --git a/games/solitaire/src/main/java/com/vayunmathur/games/solitaire/platform/SolitairePyramidOps.kt b/games/solitaire/src/main/java/com/vayunmathur/games/solitaire/platform/SolitairePyramidOps.ktindex abcbc229bb..e0b384144c 100644--- a/games/solitaire/src/main/java/com/vayunmathur/games/solitaire/platform/SolitairePyramidOps.kt+++ b/games/solitaire/src/main/java/com/vayunmathur/games/solitaire/platform/SolitairePyramidOps.kt@@ -201,6 +201,10 @@ internal fun SolitaireViewModel.pyramidDealStockImpl() {         it.copy(pyramid = state.copy(             stock = state.stock.dropLast(1),             waste = state.waste + state.stock.last(),+            // Dealing replaces the waste top, so a "waste" selection+            // would silently retarget to the new card. Drop it (a+            // pyramid selection names a fixed card and survives).+            selectedId = if (state.selectedId == "waste") null else state.selectedId,             moveCount = state.moveCount + 1         ))     }
games/solitaire/src/test/java/com/vayunmathur/games/solitaire/platform/SpiderPyramidOpsTest.kt
diff --git a/games/solitaire/src/test/java/com/vayunmathur/games/solitaire/platform/SpiderPyramidOpsTest.kt b/games/solitaire/src/test/java/com/vayunmathur/games/solitaire/platform/SpiderPyramidOpsTest.ktindex 35b52c1a04..6fb50e6956 100644--- a/games/solitaire/src/test/java/com/vayunmathur/games/solitaire/platform/SpiderPyramidOpsTest.kt+++ b/games/solitaire/src/test/java/com/vayunmathur/games/solitaire/platform/SpiderPyramidOpsTest.kt@@ -275,6 +275,35 @@ class SpiderPyramidOpsTest {         assertEquals(0, vm.uiState.value.pyramid!!.moveCount)     } +    @Test fun pyramidDealClearsWasteSelectionOnly() {+        val vm = vm()+        val a = c(Suit.SPADES, Rank.ACE); val b = c(Suit.HEARTS, Rank.TWO)+        // A selected waste card is replaced by dealing: the selection+        // must not silently retarget to the newly dealt card.+        setP(+            vm,+            pyramidState(+                listOf(listOf(a), listOf(b, c(Suit.CLUBS, Rank.THREE))),+                stock = listOf(b), waste = listOf(a), selectedId = "waste",+            ),+        )+        vm.pyramidDealStock()+        var p = vm.uiState.value.pyramid!!+        assertEquals(listOf(a, b), p.waste)+        assertNull(p.selectedId)+        // A selected pyramid card names a fixed card: dealing keeps it.+        setP(+            vm,+            pyramidState(+                listOf(listOf(a), listOf(b, c(Suit.CLUBS, Rank.THREE))),+                stock = listOf(b), waste = listOf(a), selectedId = "pyr_1_0",+            ),+        )+        vm.pyramidDealStock()+        p = vm.uiState.value.pyramid!!+        assertEquals("pyr_1_0", p.selectedId)+    }+     @Test fun pyramidCardAtAndRemoveAndParse() {         val vm = vm()         val a = c(Suit.SPADES, Rank.ACE); val b = c(Suit.HEARTS, Rank.TWO)