Modern Apps git

← Modern-Apps.git

solitaire: restore single-card guard on FreeCell cell drops (#owner-report)

Commit
d97faf9fae6cc6ae223b45136aa4bdce2290369f
Author
Vayun Mathur <[email protected]>
When
2026-11-12 20:34 UTC (23 days ago)
Parents
c9351ad
Symptom: DragAndViewModelTest.freeCellDropRejectsMultiCardDragOntoCell
fails on main. In FreeCell, dragging a multi-card run (grabbed at its
bottom card) and dropping it on an empty free cell moved the pile's
top card into the cell - a card the player never grabbed.

Root cause: the guard was added in a973af674 ("fix free-cell drop
moving wrong card") together with this regression test, but the merge
cc71db691 ("Merge fix/games-solitaire into main") resolved
SolitaireFreeCellOps.kt to the fix/games-solitaire side (c3a3f697b),
which predates the fix. The test survived the merge, the code did not.
So the code is wrong and the test is right.

Fix: handleFreeCellDropImpl's freecell branch again requires
isSingleCardDrag(sourceId), matching the foundation branch of the
same handler.

User-visible effect: dropping a FreeCell stack on a free cell is
rejected instead of silently moving a different card.

Verification: freeCellDropRejectsMultiCardDragOntoCell passes in
:games:solitaire:testDevUnitTest (container build, see branch report).

Diff

games/solitaire/src/main/java/com/vayunmathur/games/solitaire/platform/SolitaireFreeCellOps.kt
diff --git a/games/solitaire/src/main/java/com/vayunmathur/games/solitaire/platform/SolitaireFreeCellOps.kt b/games/solitaire/src/main/java/com/vayunmathur/games/solitaire/platform/SolitaireFreeCellOps.ktindex 5974fe7859..d6ec206461 100644--- a/games/solitaire/src/main/java/com/vayunmathur/games/solitaire/platform/SolitaireFreeCellOps.kt+++ b/games/solitaire/src/main/java/com/vayunmathur/games/solitaire/platform/SolitaireFreeCellOps.kt@@ -182,7 +182,10 @@ internal fun SolitaireViewModel.handleFreeCellDropImpl(sourceId: String, targetI     when {         targetId.startsWith("freecell_") -> {             val ci = targetId.removePrefix("freecell_").toInt()-            if (sourceId.startsWith("tableau_")) {+            // A free cell holds one card, so only a single-card drag may land+            // here; otherwise a stack drag would move the pile's top card,+            // which the player never grabbed.+            if (isSingleCardDrag(sourceId) && sourceId.startsWith("tableau_")) {                 val col = sourceId.removePrefix("tableau_").substringBefore("_").toInt()                 freeCellMoveToFreeCell(col, ci)             }