Modern Apps git

← Modern-Apps.git

pipes: hint "fill every cell" when pairs join but cells stay empty (#ux-audit)

Commit
5fdbfd7b6b2cf85e86034f555a9977629a35b85e
Author
Vayun Mathur <[email protected]>
When
2026-11-13 01:28 UTC (23 days ago)
Parents
d1b4320
Symptom: with every pair of dots connected but a few cells still
empty, nothing happened: no win, no message. New players read it as
a bug or did not know the rule.

Root cause: checkWin silently returned when cellOwner did not cover
every cell, and the screen had no way to explain why the level was
not solved.

Fix:
- New BoardStatus in domain/BoardState.kt: everyPairConnected (via
  StrokeRules.isComplete, so triplets count only when every dot is
  visited), isSolved (connected and full) and needsFill (connected,
  not full). checkWin now uses isSolved; the rule is unchanged.
- GameBoardUiState.showFillHint, set by GameScreen when the level is
  not won, no stroke is in progress (so it does not flicker mid-drag)
  and needsFill holds.
- GameBoardScreen's status line shows "Every pair is connected. Fill
  every cell to finish." in that state, as a polite live region so
  TalkBack reads it too.

User-visible effect: the board explains the missing step instead of
looking stuck.

Verification: new BoardStatusTest (solved board; connected with an
uncovered cell needs the hint and is not solved; an unconnected pair
or an empty board shows no hint); PipesScreensTest asserts the hint
appears only when showFillHint is set. Existing win tests (hex, daily
sets) exercise the refactored checkWin.

Diff

games/pipes/src/main/java/com/vayunmathur/games/pipes/domain/BoardState.kt
diff --git a/games/pipes/src/main/java/com/vayunmathur/games/pipes/domain/BoardState.kt b/games/pipes/src/main/java/com/vayunmathur/games/pipes/domain/BoardState.ktindex 7d6f1c7684..b6fec9b2f2 100644--- a/games/pipes/src/main/java/com/vayunmathur/games/pipes/domain/BoardState.kt+++ b/games/pipes/src/main/java/com/vayunmathur/games/pipes/domain/BoardState.kt@@ -65,3 +65,21 @@ object BoardEdits {         return out     } }++/** Pure questions about how far a [BoardState] is from solved. */+object BoardStatus {+    /** Every colour's line joins its dots (all of them, for triplets). */+    fun everyPairConnected(level: LevelData, state: BoardState): Boolean =+        level.endpoints.all { StrokeRules.isComplete(level, it.colorIndex, state.paths[it.colorIndex].orEmpty()) }++    /** Solved: every pair connected and every cell covered. */+    fun isSolved(level: LevelData, state: BoardState): Boolean =+        state.cellOwner.size == level.cells.size && everyPairConnected(level, state)++    /**+     * Every pair is connected but some cells are still empty: the one state where the+     * board looks finished yet does not count, so the player needs telling.+     */+    fun needsFill(level: LevelData, state: BoardState): Boolean =+        state.cellOwner.size < level.cells.size && everyPairConnected(level, state)+}
games/pipes/src/main/java/com/vayunmathur/games/pipes/platform/PipesUiContract.kt
diff --git a/games/pipes/src/main/java/com/vayunmathur/games/pipes/platform/PipesUiContract.kt b/games/pipes/src/main/java/com/vayunmathur/games/pipes/platform/PipesUiContract.ktindex cb0047f3e1..b3d4550fb1 100644--- a/games/pipes/src/main/java/com/vayunmathur/games/pipes/platform/PipesUiContract.kt+++ b/games/pipes/src/main/java/com/vayunmathur/games/pipes/platform/PipesUiContract.kt@@ -46,6 +46,8 @@ data class GameBoardUiState(     val moves: Int = 0,     val bestScore: Int? = null,     val canUndo: Boolean = false,+    /** Every pair is connected but cells are still empty: show the "fill every cell" hint. */+    val showFillHint: Boolean = false, )  /**
games/pipes/src/main/java/com/vayunmathur/games/pipes/platform/PipesViewModel.kt
diff --git a/games/pipes/src/main/java/com/vayunmathur/games/pipes/platform/PipesViewModel.kt b/games/pipes/src/main/java/com/vayunmathur/games/pipes/platform/PipesViewModel.ktindex 085d993db4..12fcb10725 100644--- a/games/pipes/src/main/java/com/vayunmathur/games/pipes/platform/PipesViewModel.kt+++ b/games/pipes/src/main/java/com/vayunmathur/games/pipes/platform/PipesViewModel.kt@@ -7,6 +7,7 @@ import com.vayunmathur.games.pipes.data.CellPos import com.vayunmathur.games.pipes.data.CompletedLevelsRepository import com.vayunmathur.games.pipes.domain.BoardEdits import com.vayunmathur.games.pipes.domain.BoardState+import com.vayunmathur.games.pipes.domain.BoardStatus import com.vayunmathur.games.pipes.domain.DailyLevels import com.vayunmathur.games.pipes.domain.ProgressCodec import com.vayunmathur.games.pipes.domain.SavedProgress@@ -325,18 +326,7 @@ class PipesViewModel(application: Application) : AndroidViewModel(application),     private fun checkWin() {         val s = _uiState.value         val levelData = s.levelData ?: return-        val gameState = s.gameState--        if (gameState.cellOwner.size != levelData.cells.size) return--        val allConnected = levelData.endpoints.all { ep ->-            val path = gameState.paths[ep.colorIndex] ?: return-            path.size >= 2 && path.first() in ep.cells &&-                (if (ep.cells.size == 2) path.last() in ep.cells - path.first()-                else ep.cells.all { it in path } && path.last() in ep.cells)-        }--        if (allConnected) onLevelWon()+        if (BoardStatus.isSolved(levelData, s.gameState)) onLevelWon()     }      private fun onLevelWon() {
games/pipes/src/main/java/com/vayunmathur/games/pipes/ui/GameBoardScreen.kt
diff --git a/games/pipes/src/main/java/com/vayunmathur/games/pipes/ui/GameBoardScreen.kt b/games/pipes/src/main/java/com/vayunmathur/games/pipes/ui/GameBoardScreen.ktindex 4f1a9a68ca..b8cb981982 100644--- a/games/pipes/src/main/java/com/vayunmathur/games/pipes/ui/GameBoardScreen.kt+++ b/games/pipes/src/main/java/com/vayunmathur/games/pipes/ui/GameBoardScreen.kt@@ -93,10 +93,24 @@ fun GameBoardScreen(     } } -/** The solved message once the level is won; announced by TalkBack as it appears. */+/**+ * The solved message once the level is won, or the "fill every cell" hint when every pair+ * is joined but the board is not full. Both are announced by TalkBack as they appear.+ */ @Composable private fun StatusLine(state: GameBoardUiState) {-    if (!state.isLevelWon) return+    if (!state.isLevelWon) {+        if (state.showFillHint) {+            Text(+                text = stringResource(R.string.fill_every_cell_hint),+                style = MaterialTheme.typography.bodyMedium,+                color = MaterialTheme.colorScheme.onSurfaceVariant,+                textAlign = TextAlign.Center,+                modifier = Modifier.semantics { liveRegion = LiveRegionMode.Polite },+            )+        }+        return+    }     Text(         text = pluralStringResource(R.plurals.level_solved_moves, state.moves, state.moves),         style = MaterialTheme.typography.titleMedium,
games/pipes/src/main/java/com/vayunmathur/games/pipes/ui/GameScreen.kt
diff --git a/games/pipes/src/main/java/com/vayunmathur/games/pipes/ui/GameScreen.kt b/games/pipes/src/main/java/com/vayunmathur/games/pipes/ui/GameScreen.ktindex dc8b3eda15..ec16d30b03 100644--- a/games/pipes/src/main/java/com/vayunmathur/games/pipes/ui/GameScreen.kt+++ b/games/pipes/src/main/java/com/vayunmathur/games/pipes/ui/GameScreen.kt@@ -10,6 +10,7 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import com.vayunmathur.games.pipes.Route import com.vayunmathur.games.pipes.data.LevelPack+import com.vayunmathur.games.pipes.domain.BoardStatus import com.vayunmathur.games.pipes.platform.GameBoardUiState import com.vayunmathur.games.pipes.platform.PipesGameState import com.vayunmathur.games.pipes.platform.PipesViewModel@@ -32,5 +33,5 @@ fun GameScreen(backStack: NavBackStack<Route>, viewModel: PipesViewModel, packIn     if (levels == null || levelData == null) { Box(Modifier.fillMaxSize(), Alignment.Center) { CircularProgressIndicator() }; return }     val isReady = uiState.packIndex == packIndex && uiState.levelIndex == levelIndex && uiState.levelData != null     val currentLevelStats = levelStats[levelData.id]-    GameBoardScreen(state = GameBoardUiState(levelData = if (isReady) uiState.levelData!! else levelData, levelIndex = levelIndex, maxLevelIndex = levels.lastIndex, gameState = if (isReady) uiState.gameState else PipesGameState(), activeColor = if (isReady && uiState.leftStart) uiState.activeColor else null, activePath = if (isReady) uiState.activePath else emptyList(), isLevelWon = isReady && uiState.isLevelWon, isCompleted = currentLevelStats != null, colorblind = colorblind, moves = if (isReady) viewModel.getCurrentMoves() else 0, bestScore = currentLevelStats?.bestScore, canUndo = isReady && uiState.history.isNotEmpty()), actions = viewModel, onBack = { backStack.pop() }, onBackToPacks = { while (backStack.backStack.size > 1 && backStack.last() !is Route.PackSelector) backStack.pop() }, onLevelChange = { newIndex -> val clamped = newIndex.coerceIn(0, levels.lastIndex); backStack.setLast(if (isDaily) Route.DailyGame(clamped) else Route.Game(packIndex, clamped)) })+    GameBoardScreen(state = GameBoardUiState(levelData = if (isReady) uiState.levelData!! else levelData, levelIndex = levelIndex, maxLevelIndex = levels.lastIndex, gameState = if (isReady) uiState.gameState else PipesGameState(), activeColor = if (isReady && uiState.leftStart) uiState.activeColor else null, activePath = if (isReady) uiState.activePath else emptyList(), isLevelWon = isReady && uiState.isLevelWon, isCompleted = currentLevelStats != null, colorblind = colorblind, moves = if (isReady) viewModel.getCurrentMoves() else 0, bestScore = currentLevelStats?.bestScore, canUndo = isReady && uiState.history.isNotEmpty(), showFillHint = isReady && !uiState.isLevelWon && uiState.activeColor == null && BoardStatus.needsFill(levelData, uiState.gameState)), actions = viewModel, onBack = { backStack.pop() }, onBackToPacks = { while (backStack.backStack.size > 1 && backStack.last() !is Route.PackSelector) backStack.pop() }, onLevelChange = { newIndex -> val clamped = newIndex.coerceIn(0, levels.lastIndex); backStack.setLast(if (isDaily) Route.DailyGame(clamped) else Route.Game(packIndex, clamped)) }) }
games/pipes/src/main/res/values/strings.xml
diff --git a/games/pipes/src/main/res/values/strings.xml b/games/pipes/src/main/res/values/strings.xmlindex 3239dc6d60..cdc1ee9d11 100644--- a/games/pipes/src/main/res/values/strings.xml+++ b/games/pipes/src/main/res/values/strings.xml@@ -20,4 +20,6 @@     </plurals>     <!-- GameBoardScreen: Button shown after solving the last level of a pack; returns to the pack list. Verb phrase -->     <string name="back_to_packs">Back to packs</string>+    <!-- GameBoardScreen: Hint shown when every pair of dots is connected but some cells are still empty, so the level is not solved yet. Sentence -->+    <string name="fill_every_cell_hint">Every pair is connected. Fill every cell to finish.</string> </resources>
games/pipes/src/test/java/com/vayunmathur/games/pipes/domain/BoardStatusTest.kt
diff --git a/games/pipes/src/test/java/com/vayunmathur/games/pipes/domain/BoardStatusTest.kt b/games/pipes/src/test/java/com/vayunmathur/games/pipes/domain/BoardStatusTest.ktnew file mode 100644index 0000000000..56638a2a74--- /dev/null+++ b/games/pipes/src/test/java/com/vayunmathur/games/pipes/domain/BoardStatusTest.kt@@ -0,0 +1,49 @@+package com.vayunmathur.games.pipes.domain++import com.vayunmathur.games.pipes.data.CellPos+import com.vayunmathur.games.pipes.data.EndpointPair+import com.vayunmathur.games.pipes.data.LevelData+import com.vayunmathur.games.pipes.data.computeAdjacency+import kotlin.test.Test+import kotlin.test.assertFalse+import kotlin.test.assertTrue++class BoardStatusTest {+    private fun p(r: Int, c: Int) = CellPos(r, c)+    private val cells = buildSet { for (r in 0 until 2) for (c in 0 until 3) add(p(r, c)) }++    /** 2x3: red (0,0)-(0,2) on top, blue (1,0)-(1,2) below. */+    private val level = LevelData(+        "b", 2, 3, cells, computeAdjacency(cells), null,+        listOf(EndpointPair(0, listOf(p(0, 0), p(0, 2))), EndpointPair(1, listOf(p(1, 0), p(1, 2)))),+        emptySet(), 2,+    )++    private fun board(vararg paths: Pair<Int, List<CellPos>>) =+        BoardState(paths.toMap(), BoardEdits.owners(level, paths.toMap()))++    @Test fun fullAndConnectedIsSolved() {+        val b = board(0 to listOf(p(0, 0), p(0, 1), p(0, 2)), 1 to listOf(p(1, 0), p(1, 1), p(1, 2)))+        assertTrue(BoardStatus.isSolved(level, b))+        assertFalse(BoardStatus.needsFill(level, b))+    }++    @Test fun connectedWithEmptyCellsNeedsFill() {+        // Same pairs plus a seventh cell (2,1) that neither line covers.+        val holeLevel = level.copy(+            cells = cells + p(2, 1),+            adjacency = computeAdjacency(cells + p(2, 1)),+        )+        val paths = mapOf(0 to listOf(p(0, 0), p(0, 1), p(0, 2)), 1 to listOf(p(1, 0), p(1, 1), p(1, 2)))+        val b = BoardState(paths, BoardEdits.owners(holeLevel, paths))+        assertTrue(BoardStatus.needsFill(holeLevel, b))+        assertFalse(BoardStatus.isSolved(holeLevel, b))+    }++    @Test fun anUnconnectedPairNeedsNoFillHint() {+        val b = board(0 to listOf(p(0, 0), p(0, 1), p(0, 2)), 1 to listOf(p(1, 0), p(1, 1)))+        assertFalse(BoardStatus.needsFill(level, b))+        assertFalse(BoardStatus.isSolved(level, b))+        assertFalse(BoardStatus.needsFill(level, BoardState()))+    }+}
games/pipes/src/test/java/com/vayunmathur/games/pipes/ui/PipesScreensTest.kt
diff --git a/games/pipes/src/test/java/com/vayunmathur/games/pipes/ui/PipesScreensTest.kt b/games/pipes/src/test/java/com/vayunmathur/games/pipes/ui/PipesScreensTest.ktindex 7656be5e7e..7f8e93a3f6 100644--- a/games/pipes/src/test/java/com/vayunmathur/games/pipes/ui/PipesScreensTest.kt+++ b/games/pipes/src/test/java/com/vayunmathur/games/pipes/ui/PipesScreensTest.kt@@ -169,6 +169,16 @@ class PipesScreensTest {         rule.onNodeWithText(str(UiR.string.next_level)).performClick()         assertEquals(2, levelChange)         rule.onNodeWithText(ctx.resources.getQuantityString(R.plurals.level_solved_moves, 0, 0)).assertIsDisplayed()+        rule.onNodeWithText(str(R.string.fill_every_cell_hint)).assertDoesNotExist()+        // Every pair joined but cells left empty: the hint replaces the silence+        screen.value = {+            PipesTheme {+                GameBoardScreen(+                    GameBoardUiState(level, levelIndex = 1, maxLevelIndex = 3, showFillHint = true, canUndo = true),+                    actions, onBack = {}, onLevelChange = {})+            }+        }+        rule.onNodeWithText(str(R.string.fill_every_cell_hint)).assertIsDisplayed()         // Won on the last level: no next button, but a solved message and a way back to the packs         var toPacks = 0         screen.value = {