Modern Apps git

← Modern-Apps.git

games: a fast fill swipe no longer guesses blanks its own stroke proved empty

Commit
316250762f97a9af82acb89cfbf71fd6f5140a08
Author
Vayun Mathur <[email protected]>
When
2026-12-01 13:11 UTC (5 days ago)
Parents
d5d819d
extend walks every skipped cell inside one pointer event,
but auto-crosses were only re-derived at commit. Mid-walk,
a blank in a row the stroke itself had just completed was
still judged from the stale autoCrossed set and guessed โ€”
provably wrongly, since a line whose fills equal its clue
sum has all picture cells filled. The identical drag
delivered cell-by-cell stepped over those cells: one
physical drag cost a heart or not depending purely on
pointer-event sampling.

Non-deciding fill cells are now also skipped when
autoCrossedCells (computed from the fills as they stand
mid-walk) proves them blank; the deciding first cell still
attempts even an X, and a not-yet-provable blank still
costs its heart (existing tests unchanged). Generation,
completion and restore were audited and cleared (the
solver was brute-force checked). Verified:
:games:nonogram:testDevUnitTest 154 tests and lint pass.

Diff

games/nonogram/src/main/java/com/vayunmathur/games/nonogram/domain/NonogramStrokes.kt
diff --git a/games/nonogram/src/main/java/com/vayunmathur/games/nonogram/domain/NonogramStrokes.kt b/games/nonogram/src/main/java/com/vayunmathur/games/nonogram/domain/NonogramStrokes.ktindex 6f7c81e20b..d78eb0131f 100644--- a/games/nonogram/src/main/java/com/vayunmathur/games/nonogram/domain/NonogramStrokes.kt+++ b/games/nonogram/src/main/java/com/vayunmathur/games/nonogram/domain/NonogramStrokes.kt@@ -58,7 +58,10 @@ data class StrokeStep(val game: NonogramGameState, val stroke: Stroke)  *  - Every cell between the last position and the new one is walked, so a fast swipe that skips  *    cells between two pointer events still marks them, and each cell is handled at most once.  *  - Fill strokes only paint blank cells after the first: an X the player placed protects its cell- *    from a sweep (tapping an X in fill mode still attempts it, as before).+ *    from a sweep (tapping an X in fill mode still attempts it, as before). A cell that an earlier+ *    cell of this same stroke has just auto-crossed โ€” by completing its row or column โ€” is protected+ *    the same way, so a fast swipe that walks several cells in one move cannot guess a blank the+ *    board already proves empty, and a drag's outcome never depends on pointer sampling.  *  - A wrong fill reveals that cell, costs one heart and stops the stroke, so one stroke can never  *    cost more than one heart.  */@@ -119,8 +122,17 @@ object NonogramStrokes {      private fun apply(game: NonogramGameState, action: StrokeAction, index: Int, deciding: Boolean) =         when (action) {-            StrokeAction.FILL ->-                if (deciding || game.markAt(index) == CellMark.BLANK) NonogramMoves.guess(game, index) else game+            StrokeAction.FILL -> when {+                deciding -> NonogramMoves.guess(game, index)+                game.markAt(index) != CellMark.BLANK -> game+                // An earlier fill in this stroke may have completed this+                // cell's row or column: the ViewModel only re-derives+                // auto-crosses when the stroke step commits, which is+                // after a multi-cell walk, so the walk itself must not+                // guess a cell that is already provably blank.+                index in NonogramClues.autoCrossedCells(game) -> game+                else -> NonogramMoves.guess(game, index)+            }             StrokeAction.CROSS -> when {                 game.markAt(index) == CellMark.BLANK -> NonogramMoves.setNote(game, index, true)                 // Already crossed, but only automatically: this stroke's note promotes it.
games/nonogram/src/test/java/com/vayunmathur/games/nonogram/domain/NonogramStrokesTest.kt
diff --git a/games/nonogram/src/test/java/com/vayunmathur/games/nonogram/domain/NonogramStrokesTest.kt b/games/nonogram/src/test/java/com/vayunmathur/games/nonogram/domain/NonogramStrokesTest.ktindex 490e5a36d2..a0476b22d8 100644--- a/games/nonogram/src/test/java/com/vayunmathur/games/nonogram/domain/NonogramStrokesTest.kt+++ b/games/nonogram/src/test/java/com/vayunmathur/games/nonogram/domain/NonogramStrokesTest.kt@@ -131,6 +131,36 @@ class NonogramStrokesTest {         assertTrue(idx(1, 2) !in s.game.filled)     } +    @Test fun fillStrokeStepsOverBlanksOfARowItCompletesMidDrag() {+        // Row 0 is "###..": filling its third cell completes the row, so+        // the two trailing blanks are auto-crossable from that moment on.+        // A single fast swipe that walks them in the same extend must step+        // over them exactly like a slow cell-by-cell drag whose commits+        // derive the auto-crosses between pointer events: no heart, no+        // reveal, and the outcome cannot depend on pointer sampling.+        val topRow = NonogramPuzzle.from(+            5,+            listOf(+                "###..",+                ".....",+                ".....",+                ".....",+                "....#",+            ).joinToString("").map { it == '#' },+        )+        val start = NonogramGameState(+            topRow, emptySet(), emptySet(), emptySet(), STARTING_HEARTS, GameMode.CASUAL, 1,+        )+        val swiped = stroke(start, MarkMode.FILL, idx(0, 0), idx(0, 4))+        assertEquals(setOf(idx(0, 0), idx(0, 1), idx(0, 2)), swiped.game.filled)+        assertEquals(emptySet(), swiped.game.revealedBlanks)+        assertEquals(STARTING_HEARTS, swiped.game.hearts, "a blank the completed row proves empty must not cost a heart")+        val stepped = stroke(start, MarkMode.FILL, idx(0, 0), idx(0, 1), idx(0, 2), idx(0, 3), idx(0, 4))+        assertEquals(swiped.game.filled, stepped.game.filled)+        assertEquals(swiped.game.revealedBlanks, stepped.game.revealedBlanks)+        assertEquals(swiped.game.hearts, stepped.game.hearts)+    }+     @Test fun nothingHappensOnceTheGameIsOver() {         val over = game(hearts = 0)         val s = stroke(over, MarkMode.FILL, idx(1, 0), idx(1, 4))