Modern Apps git

← Modern-Apps.git

unblockjam: a thick target block can no longer exit through a lower-row blocker

Commit
bb510d31a70690a961977139b33bce62da5b87fc
Author
Vayun Mathur <[email protected]>
When
2026-12-01 06:26 UTC (5 days ago)
Parents
51f8546
Only the target block's top row was checked for a clear exit
path, in two places. On a 6x6 board with a 3x2 target at
(0,2) and a fixed 1x1 wall at (5,3) — blocking the target's
lower row only — RushHourSolver.optimalMoves returned 1 and
dragging the target right fired onLevelWon, while stepBlock
already correctly refused the same move via rectangle
overlap: the input paths disagreed, and the solver called an
unsolvable board solved. Shipped packs all use one-row
targets, so shipped levels are unaffected, but multi-row
targets are legal in the board model.

isGoal now requires every row the target spans to be clear
to the edge, and exitExtension checks all rows the block
occupies rather than only its top. Three new tests pin:
fixed lower-row wall -> unsolvable, movable lower-row
blocker -> 2 moves, both rows clear -> 1; the drag test
asserts no win fires and the target stops against the
blocker. All 850 shipped levels were independently re-solved
and match. Verified: :games:unblockjam:testDevUnitTest 97
tests pass; :games:unblockjam:lint passes.

Diff

games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/domain/RushHourSolver.kt
diff --git a/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/domain/RushHourSolver.kt b/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/domain/RushHourSolver.ktindex 7639fb166f..4639d58bd3 100644--- a/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/domain/RushHourSolver.kt+++ b/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/domain/RushHourSolver.kt@@ -134,8 +134,12 @@ object RushHourSolver {         /** The main block can drive out when nothing sits between it and the right edge. */         fun isGoal(state: Long): Boolean {             fill(state, true)-            val clear = (positionOf(state, 0) + length[0] until width)-                .none { occupied[index(it, cross[0])] }+            // The main block may span several rows: every row it occupies must be clear to+            // the edge, not just the top one, or it would drive through a block sitting on+            // one of its lower rows.+            val clear = (positionOf(state, 0) + length[0] until width).all { x ->+                (cross[0] until cross[0] + crossLength[0]).none { occupied[index(x, it)] }+            }             fill(state, false)             return clear         }
games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/platform/BlockDragGestures.kt
diff --git a/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/platform/BlockDragGestures.kt b/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/platform/BlockDragGestures.ktindex da315a6f49..874610677f 100644--- a/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/platform/BlockDragGestures.kt+++ b/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/platform/BlockDragGestures.kt@@ -73,8 +73,13 @@ private fun exitExtension( ): Int {     if (!isHorizontal || !isMainBlock) return max     if (block.position.y != levelData.exit.y) return max+    // The main block may span several rows: every row it occupies must be clear to the+    // edge, not just the top one, or the drag range would extend through a block sitting+    // on one of its lower rows.     val pathClear = (max + axis.size until levelData.dimension.width).all { x ->-        !isOccupied(otherBlocks, x, block.position.y)+        (axis.perpPos until axis.perpPos + axis.perpSize).all { y ->+            !isOccupied(otherBlocks, x, y)+        }     }     return if (pathClear) levelData.exit.x else max }
games/unblockjam/src/test/java/com/vayunmathur/games/unblockjam/domain/ThickMainSolverTest.kt
diff --git a/games/unblockjam/src/test/java/com/vayunmathur/games/unblockjam/domain/ThickMainSolverTest.kt b/games/unblockjam/src/test/java/com/vayunmathur/games/unblockjam/domain/ThickMainSolverTest.ktnew file mode 100644index 0000000000..fdaeac69c0--- /dev/null+++ b/games/unblockjam/src/test/java/com/vayunmathur/games/unblockjam/domain/ThickMainSolverTest.kt@@ -0,0 +1,46 @@+package com.vayunmathur.games.unblockjam.domain++import com.vayunmathur.games.unblockjam.data.Block+import com.vayunmathur.games.unblockjam.data.Coord+import com.vayunmathur.games.unblockjam.data.Dimension+import com.vayunmathur.games.unblockjam.data.LevelData+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertNull++class ThickMainSolverTest {+    private fun level(blocks: List<Block>) = LevelData(+        id = "thick-main", dimension = Dimension(6, 6), exit = Coord(6, 2),+        blocks = blocks, optimalMoves = 0,+    )++    @Test+    fun lowerRowBlockerShouldMakeThickMainUnsolvable() {+        // Main is 3x2 at (0,2): occupies rows 2 and 3. A fixed 1x1 wall at (5,3)+        // blocks only the lower row. The exit path is NOT clear.+        val lvl = level(+            listOf(+                Block(Coord(0, 2), Dimension(3, 2), false),+                Block(Coord(5, 3), Dimension(1, 1), true),+            )+        )+        assertNull(RushHourSolver.optimalMoves(lvl), "expected unsolvable, solver must not drive through the wall on row 3")+    }++    @Test+    fun thickMainWithBothRowsClearWinsInOne() {+        val lvl = level(listOf(Block(Coord(0, 2), Dimension(3, 2), false)))+        assertEquals(1, RushHourSolver.optimalMoves(lvl))+    }++    @Test+    fun lowerRowBlockerThatMovesAwayShouldCostTwo() {+        val lvl = level(+            listOf(+                Block(Coord(0, 2), Dimension(3, 2), false),+                Block(Coord(5, 3), Dimension(1, 2), false),+            )+        )+        assertEquals(2, RushHourSolver.optimalMoves(lvl))+    }+}
games/unblockjam/src/test/java/com/vayunmathur/games/unblockjam/ui/components/ThickMainDragTest.kt
diff --git a/games/unblockjam/src/test/java/com/vayunmathur/games/unblockjam/ui/components/ThickMainDragTest.kt b/games/unblockjam/src/test/java/com/vayunmathur/games/unblockjam/ui/components/ThickMainDragTest.ktnew file mode 100644index 0000000000..a289b2e188--- /dev/null+++ b/games/unblockjam/src/test/java/com/vayunmathur/games/unblockjam/ui/components/ThickMainDragTest.kt@@ -0,0 +1,52 @@+package com.vayunmathur.games.unblockjam.ui.components++import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.size+import androidx.compose.ui.Modifier+import androidx.compose.ui.geometry.Offset+import androidx.compose.ui.platform.testTag+import androidx.compose.ui.test.junit4.createComposeRule+import androidx.compose.ui.test.onNodeWithTag+import androidx.compose.ui.test.performTouchInput+import androidx.compose.ui.test.swipe+import androidx.compose.ui.unit.dp+import com.vayunmathur.games.unblockjam.data.Block+import com.vayunmathur.games.unblockjam.data.Coord+import com.vayunmathur.games.unblockjam.data.Dimension+import com.vayunmathur.games.unblockjam.data.LevelData+import org.junit.Rule+import org.junit.runner.RunWith+import org.robolectric.RobolectricTestRunner+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertNotNull++@RunWith(RobolectricTestRunner::class)+class ThickMainDragTest {+    @get:Rule val rule = createComposeRule()++    @Test+    fun draggingThickMainIntoLowerRowWallDoesNotWin() {+        var changed: LevelData? = null+        var won = 0+        val level = LevelData(+            id = "thick-drag", dimension = Dimension(6, 6), exit = Coord(6, 2),+            blocks = listOf(+                Block(Coord(0, 2), Dimension(3, 2), false),+                Block(Coord(5, 3), Dimension(1, 1), true),+            ),+            optimalMoves = 1,+        )+        rule.setContent {+            Box(Modifier.size(360.dp)) {+                GameBoard(level, { changed = it }, { won++ }, isLevelWon = false, modifier = Modifier.testTag("board"))+            }+        }+        rule.onNodeWithTag("board").performTouchInput {+            swipe(Offset(height * 1.5f / 6f, height * 3f / 6f), Offset(width * 0.97f, height * 3f / 6f), 400)+        }+        assertEquals(0, won, "thick main must not drive through the wall on its lower row")+        val result = assertNotNull(changed)+        assertEquals(Coord(2, 2), result.blocks[0].position)+    }+}