games-arrows: require mirrors on boards that have them
- Commit
8a160e3e3b86b40bbe2c36e4f55dee64fbf28789- Author
- Vayun Mathur <[email protected]>
- When
- 2026-12-06 05:41 UTC (5 hours ago)
- Parents
48eafba
Owner feedback: generated Arrows levels used their mirrors without ever needing them. The old gate only tracked mirror use (a mirror lying on some arrow's exit route); measured on levels 11-60 before this change, all 164 mirrors were used yet only 12 of 50 boards were unclearable without their mirrors, and no board had every mirror individually load-bearing. Define necessity mechanically in ArrowsAnalysis: a board requires its mirrors when ArrowsRules.solve clears it as-is and cannot clear it with every mirror removed (mirrors removed, not blocked, is the disabled form; a mirrorless board vacuously does not require mirrors). Board metrics gain requiresMirrors and requiredMirrorCount (mirrors whose individual removal breaks the board) beside the existing mirrorUseCount, so use and necessity can no longer be conflated. ArrowsGenerator now rejects any mirror board that fails that gate, on top of the unchanged unused-mirror, opening-cap, dependency-depth and solver-clearability checks. Candidate scoring steers toward the shape that makes the gate reachable: a forced bounce (mirror route clear, straight route blocked by placed arrows), with a further bonus for the chokepoint where the candidate's body also blocks an existing arrow's straight route, so mirrorless the two arrows block each other while the bounce breaks the cycle. Mirror concessions in generateSeeded never drop to zero when mirrors were asked for, so levels and dailies that should have redirectors keep at least one (now load-bearing) mirror; mirror frequency is otherwise unchanged. Tutorial alignment needs no ViewModel change: difficultyForLevel already maps CASUAL <11, STANDARD <40, EXPERT >=40 and mirrors arrive at level 11 in STANDARD, so the first single-mirror boards are gated forced bounces the player cannot ignore, with the existing one-time redirector hint on top. Tests: ArrowsMirrorNecessityTest pins handcrafted decorative vs load-bearing boards, per-tier generated necessity (clearable with mirrors, unclearable without), the first mirror levels, the ladder, dailies, mirrorless boards and determinism; GeneratedBoardPropertiesTest gains the same necessity property over its shared ladder. Measured after the change on levels 11-60 with the game's own mapping: 50/50 mirror boards require their mirrors (29/29 STANDARD, 21/21 EXPERT), mirror counts unchanged at 164, 62 of them individually load-bearing. Verified: ./gradlew :games:arrows:lint :games:arrows:lintVitalRelease :games:arrows:testDevUnitTest (158 tests, 0 failures) in the worktree. ktlintCheck fails across the module on untouched files at origin/main (pre-existing; the required Android lint gates are green).
Diff
games/arrows/AGENTS.md
diff --git a/games/arrows/AGENTS.md b/games/arrows/AGENTS.mdindex 808b98b910..e6bdcb5523 100644--- a/games/arrows/AGENTS.md+++ b/games/arrows/AGENTS.md@@ -14,7 +14,7 @@ _Install: ./install games/arrows (dev by default)._ **Purpose:** Order-clearing arrow puzzle — every arrow must fly off unblocked; redirectors from level 11; daily board + 3-hearts escape overlay. 100% offline. **Game shape (shared across MA games):** `ui/` board + screens → `platform/*ViewModel` (+ `UiContract`) → `domain/` pure rules/generator (+ solver where present) → `data/` progress store; achievements via `platform/*AchievementsManager` (:library) → `:sdk:games` → hub; daily boards via `:library:work`. **Entry points:** `Route` → `MainActivity.kt` → `Navigation.kt` → `platform/ArrowsViewModel.kt` → `domain/ArrowsRules.kt`.-**Gotchas:** Every generated board must be clearable — generator changes need solvability checks.+**Gotchas:** Every generated board must be clearable — generator changes need solvability checks. Every generated board with mirrors must also be unclearable without them (`ArrowsAnalysis.requiresMirrors`, checked with the real solver in the generator gate and in `ArrowsMirrorNecessityTest`/`GeneratedBoardPropertiesTest`); mirror *use* (`mirrorUseCount`) alone does not satisfy this. ## Key files ### Root — entry + navigation@@ -24,8 +24,8 @@ _Install: ./install games/arrows (dev by default)._ ### data/ + domain/ — progress + pure rules - com/vayunmathur/games/arrows/data/ArrowModels.kt - com/vayunmathur/games/arrows/data/ArrowsDataStore.kt-- com/vayunmathur/games/arrows/domain/ArrowsGenerator.kt — reverse-removal-order generator; accepts `ArrowsDifficulty` (opening cap, dependency-depth floor, piece length, depth-weighted candidate scoring) and verifies boards with `ArrowsRules.solve`-- com/vayunmathur/games/arrows/domain/ArrowsAnalysis.kt — `ArrowsDifficulty` tiers, `ArrowsBoardMetrics`/`dependencyDepth` analysis, and the level-to-difficulty mapping+- com/vayunmathur/games/arrows/domain/ArrowsGenerator.kt — reverse-removal-order generator; accepts `ArrowsDifficulty` (opening cap, dependency-depth floor, piece length, depth-weighted candidate scoring), steers candidates toward forced bounces at mirror chokepoints, and verifies boards with `ArrowsRules.solve`. A board with mirrors is rejected unless `ArrowsAnalysis.requiresMirrors` holds; boards without mirrors are unaffected, and asked-for mirrors are never conceded to zero+- com/vayunmathur/games/arrows/domain/ArrowsAnalysis.kt — `ArrowsDifficulty` tiers, `ArrowsBoardMetrics`/`dependencyDepth` analysis, mirror necessity (`requiresMirrors`: clearable with mirrors, unclearable with all mirrors removed per `ArrowsRules.solve`; `requiredMirrorCount`: individually load-bearing mirrors — use on a route is not necessity), and the level-to-difficulty mapping (CASUAL <11, STANDARD <40, EXPERT ≥40; mirrors arrive at level 11 in STANDARD, so the first single-mirror boards teach a forced bounce) - com/vayunmathur/games/arrows/domain/ArrowsRules.kt ### platform/ — ViewModel + achievements - com/vayunmathur/games/arrows/platform/ArrowsViewModel.kt
games/arrows/src/main/java/com/vayunmathur/games/arrows/domain/ArrowsAnalysis.kt
diff --git a/games/arrows/src/main/java/com/vayunmathur/games/arrows/domain/ArrowsAnalysis.kt b/games/arrows/src/main/java/com/vayunmathur/games/arrows/domain/ArrowsAnalysis.ktindex 3277f3745e..0f67a55c5f 100644--- a/games/arrows/src/main/java/com/vayunmathur/games/arrows/domain/ArrowsAnalysis.kt+++ b/games/arrows/src/main/java/com/vayunmathur/games/arrows/domain/ArrowsAnalysis.kt@@ -24,6 +24,10 @@ data class ArrowsBoardMetrics( val blockedCount: Int, val dependencyDepth: Int, val mirrorUseCount: Int,+ /** Mirrors whose individual removal makes the board unclearable. */+ val requiredMirrorCount: Int,+ /** Whether the board as a whole cannot be cleared with every mirror removed. */+ val requiresMirrors: Boolean, ) object ArrowsAnalysis {@@ -49,9 +53,42 @@ object ArrowsAnalysis { blockedCount = puzzle.pieces.size - open, dependencyDepth = dependencyDepth(puzzle), mirrorUseCount = usedMirrors,+ requiredMirrorCount = requiredMirrorCount(puzzle),+ requiresMirrors = requiresMirrors(puzzle), ) } + /** The same board with every mirror removed: arrows fly straight, mirrors neither bend nor block. */+ fun withoutMirrors(puzzle: ArrowsPuzzle): ArrowsPuzzle = puzzle.copy(mirrors = emptyMap())++ /**+ * Whether [puzzle] needs its mirrors, mechanically: it is clearable as it stands+ * ([ArrowsRules.solve] finds an order) and not clearable at all once every mirror is removed.+ *+ * This is strictly stronger than a mirror being *used* (lying on some arrow's route). A used+ * mirror can still be decoration: the arrow that bends through it may also have a straight way+ * out once its blockers leave, so the board clears either way. Measured on the pre-gate ladder+ * (levels 11-60), every one of 164 mirrors was used, yet only 12 of 50 boards were unclearable+ * without their mirrors. Boards with no mirrors vacuously do not require mirrors.+ */+ fun requiresMirrors(puzzle: ArrowsPuzzle): Boolean =+ puzzle.mirrors.isNotEmpty() &&+ ArrowsRules.solve(puzzle) != null &&+ ArrowsRules.solve(withoutMirrors(puzzle)) == null++ /**+ * How many mirrors are individually load-bearing: removing that mirror alone (the rest kept)+ * makes the board unclearable. A board can require mirrors collectively with no single mirror+ * counting here (each remaining mirror can substitute for a removed one), so the generator gate+ * is [requiresMirrors], and this count is the per-mirror diagnostic beside it.+ */+ fun requiredMirrorCount(puzzle: ArrowsPuzzle): Int {+ if (puzzle.mirrors.isEmpty() || ArrowsRules.solve(puzzle) == null) return 0+ return puzzle.mirrors.keys.count { mirror ->+ ArrowsRules.solve(puzzle.copy(mirrors = puzzle.mirrors - mirror)) == null+ }+ }+ /** * Longest chain A -> B -> C ... where each arrow's cells lie on the next arrow's exit * route (so the next cannot leave until this one does). Cycles are cut by the visited set.
games/arrows/src/main/java/com/vayunmathur/games/arrows/domain/ArrowsGenerator.kt
diff --git a/games/arrows/src/main/java/com/vayunmathur/games/arrows/domain/ArrowsGenerator.kt b/games/arrows/src/main/java/com/vayunmathur/games/arrows/domain/ArrowsGenerator.ktindex dcf0fc634e..0af974cdd7 100644--- a/games/arrows/src/main/java/com/vayunmathur/games/arrows/domain/ArrowsGenerator.kt+++ b/games/arrows/src/main/java/com/vayunmathur/games/arrows/domain/ArrowsGenerator.kt@@ -17,9 +17,10 @@ import kotlin.random.Random * alternative (paint a board, then search for an order) fails for the overwhelming majority of random * layouts. *- * On top of that, two properties are steered for rather than left to chance, because random boards give- * neither: every mirror lies on some arrow's route, and only a handful of arrows can leave at the start.- * See [chooseCandidate].+ * On top of that, three properties are steered for rather than left to chance, because random boards give+ * none of them: every mirror lies on some arrow's route, a board with mirrors cannot be cleared once+ * they are removed ([ArrowsAnalysis.requiresMirrors]), and only a handful of arrows can leave at the+ * start. See [chooseCandidate]. * * A generated board can still have many solutions; nothing here tries to make the order unique. */@@ -67,7 +68,10 @@ object ArrowsGenerator { * 2. only then place fewer mirrors. * * Mirrors are never allowed to go *unused*, whatever the round — that was the whole point of the- * exercise. Fewer redirectors that all matter beats four where one is scenery.+ * exercise. Fewer redirectors that all matter beats four where one is scenery. They are also+ * never dropped to zero when any were asked for: a level (or daily) that is supposed to have+ * redirectors must keep at least one, and the necessity gate in [build] then guarantees that+ * one is load-bearing rather than scenery. */ fun generateSeeded( cols: Int,@@ -98,11 +102,13 @@ object ArrowsGenerator { } else { difficulty }+ val roundMirrors = (mirrorCount - concession.fewerMirrors)+ .coerceAtLeast(if (mirrorCount > 0) 1 else 0) generate( cols = cols, rows = rows, targetPieces = targetPieces,- mirrorCount = (mirrorCount - concession.fewerMirrors).coerceAtLeast(0),+ mirrorCount = roundMirrors, rng = Random(seed + round * SEED_STRIDE), openSlack = concession.openSlack, difficulty = effective,@@ -172,8 +178,11 @@ object ArrowsGenerator { val pieces = mutableListOf<ArrowPiece>() // Escape paths depend only on the board's geometry, never on which arrows are present, so each- // one can be kept from when its arrow was placed instead of being recomputed.+ // one can be kept from when its arrow was placed instead of being recomputed. The mirrorless+ // ("straight") twin of each path is kept beside it: the gap between the two is what candidate+ // scoring uses to steer boards toward needing their mirrors. val paths = mutableListOf<Set<Int>>()+ val straightPaths = mutableListOf<Set<Int>>() val unusedMirrors = mirrors.keys.toMutableSet() var failures = 0 @@ -185,6 +194,7 @@ object ArrowsGenerator { undrawable = undrawable, blocking = blocking, paths = paths,+ straightPaths = straightPaths, unusedMirrors = unusedMirrors, id = pieces.size, rng = rng,@@ -197,6 +207,7 @@ object ArrowsGenerator { } pieces += chosen.piece paths += chosen.path+ straightPaths += chosen.straightPath undrawable += chosen.piece.cells blocking += chosen.piece.cells unusedMirrors -= chosen.path@@ -222,12 +233,18 @@ object ArrowsGenerator { ) { return null }+ // Necessity gate: a board with mirrors must need them. Lying on some arrow's route (the+ // unused-mirror check above) is not enough — if the board still clears with every mirror+ // removed, the mirrors are decoration the player can ignore, so the board is discarded.+ // Boards without mirrors are unaffected.+ if (mirrors.isNotEmpty() && !ArrowsAnalysis.requiresMirrors(puzzle)) return null return puzzle } private class Candidate( val piece: ArrowPiece, val path: Set<Int>,+ val straightPath: Set<Int>, ) /**@@ -239,8 +256,17 @@ object ArrowsGenerator { * * Scoring, in order of weight: * - routing through a mirror nothing uses yet, since a board with one left over is discarded outright;+ * - the chokepoint shape that makes mirrors necessary (see below);+ * - a forced bounce on its own: the candidate bends through a mirror because its straight route+ * is blocked by arrows already placed, so the bend — not the straight line — is what lets it out; * - crossing existing escape paths, which is what pins other arrows and holds the opening down. *+ * The chokepoint is a forced bounce whose body also lies on an existing arrow's straight route.+ * Without mirrors the two arrows then block each other (a cycle no removal order can break),+ * while with mirrors the new arrow bends away and leaves, freeing the other. Preferring that+ * shape is what makes the necessity gate in [build] reachable often enough to generate against;+ * the gate itself, checked with the real solver, is what guarantees it.+ * * Deliberately *not* scored: pinning only those arrows that can currently leave. It sounds like the * sharper objective, and measurably is not — chasing it concentrates arrows into the same region, which * starves later placements and leaves boards short of the arrow floor more often than it tightens them.@@ -250,12 +276,14 @@ object ArrowsGenerator { undrawable: Set<Int>, blocking: Set<Int>, paths: List<Set<Int>>,+ straightPaths: List<Set<Int>>, unusedMirrors: Set<Int>, id: Int, rng: Random, maxLength: Int = MAX_LENGTH, depthWeight: Int = 1, ): Candidate? {+ val straightGeometry = ArrowsAnalysis.withoutMirrors(geometry) var best: Candidate? = null var bestScore = Int.MIN_VALUE repeat(CANDIDATES_PER_PIECE) {@@ -267,13 +295,28 @@ object ArrowsGenerator { // insertion order a solution - and must not be turned back into itself, which a mirror can // do. An arrow blocked by its own tail can never leave, at which point the board is unwinnable. if (path.any { it in blocking || it in piece.cells }) return@repeat+ val straightPath =+ ArrowsRules.exitPath(straightGeometry, piece.head, piece.direction).orEmpty() var score = 0 if (path.any { it in unusedMirrors }) score += MIRROR_SCORE+ // Forced bounce: the mirror route is clear, but the straight route runs into arrows+ // already placed (or the piece's own body) — without the bend this arrow could not+ // leave past them. The chokepoint adds the return edge: this piece's body also sits+ // on an existing arrow's straight route, so mirrorless the two block each other.+ val usesMirror = path.any { it in geometry.mirrors }+ val straightBlocked =+ straightPath.any { it in blocking || it in piece.cells }+ if (usesMirror && straightBlocked) {+ score += FORCED_BOUNCE_SCORE+ if (straightPaths.any { existing -> piece.cells.any { it in existing } }) {+ score += CHOKEPOINT_SCORE+ }+ } score += depthWeight * paths.count { existing -> piece.cells.any { it in existing } } if (score > bestScore) { bestScore = score- best = Candidate(piece, path.toSet())+ best = Candidate(piece, path.toSet(), straightPath.toSet()) } } return best@@ -352,6 +395,12 @@ object ArrowsGenerator { /** Outweighs any amount of blocking: a board with an unused mirror is discarded outright. */ private const val MIRROR_SCORE = 100 + /** A candidate that can only leave by bending through a mirror, not straight. */+ private const val FORCED_BOUNCE_SCORE = 60++ /** A forced bounce that also blocks an existing arrow's straight route: the necessity shape. */+ private const val CHOKEPOINT_SCORE = 100+ /** Give up on a board once this many placement attempts in a row have failed. */ private const val MAX_CONSECUTIVE_FAILURES = 200
games/arrows/src/test/java/com/vayunmathur/games/arrows/domain/ArrowsMirrorNecessityTest.kt
diff --git a/games/arrows/src/test/java/com/vayunmathur/games/arrows/domain/ArrowsMirrorNecessityTest.kt b/games/arrows/src/test/java/com/vayunmathur/games/arrows/domain/ArrowsMirrorNecessityTest.ktnew file mode 100644index 0000000000..ff2ea923db--- /dev/null+++ b/games/arrows/src/test/java/com/vayunmathur/games/arrows/domain/ArrowsMirrorNecessityTest.kt@@ -0,0 +1,226 @@+package com.vayunmathur.games.arrows.domain++import com.vayunmathur.games.arrows.data.ArrowPiece+import com.vayunmathur.games.arrows.data.ArrowsPuzzle+import com.vayunmathur.games.arrows.data.DAILY_ARROWS+import com.vayunmathur.games.arrows.data.DAILY_BOARD+import com.vayunmathur.games.arrows.data.DAILY_MIRRORS+import com.vayunmathur.games.arrows.data.Direction+import com.vayunmathur.games.arrows.data.MIRROR_FIRST_LEVEL+import com.vayunmathur.games.arrows.data.Mirror+import com.vayunmathur.games.arrows.data.arrowCountForLevel+import com.vayunmathur.games.arrows.data.boardSizeForLevel+import com.vayunmathur.games.arrows.data.mirrorCountForLevel+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertFalse+import kotlin.test.assertNotNull+import kotlin.test.assertNull+import kotlin.test.assertTrue++/**+ * Mirror necessity, as opposed to mirror use: a mirror can lie on an arrow's route and still be+ * decoration, because that arrow may also have a straight way out. These tests pin the mechanical+ * definition — clearable with mirrors, unclearable with every mirror removed, both judged by+ * [ArrowsRules.solve] — on handcrafted boards, and then on generated boards per tier.+ */+class ArrowsMirrorNecessityTest {++ private val cols = 5+ private val rows = 5++ private fun at(row: Int, col: Int) = row * cols + col++ /** An arrow that bends up through a `/` mirror, but could equally fly straight off the board. */+ private fun decorativeBoard(): ArrowsPuzzle {+ val piece = ArrowPiece(0, listOf(at(2, 1), at(2, 2)), Direction.RIGHT)+ return ArrowsPuzzle(cols, rows, listOf(piece), mapOf(at(2, 3) to Mirror.FORWARD))+ }++ /**+ * Two arrows facing each other across a `/` mirror. Straight, each runs into the other and+ * neither can ever leave; through the mirror the left one turns up and the right one down.+ */+ private fun loadBearingBoard(): ArrowsPuzzle {+ val left = ArrowPiece(0, listOf(at(2, 0), at(2, 1)), Direction.RIGHT)+ val right = ArrowPiece(1, listOf(at(2, 4), at(2, 3)), Direction.LEFT)+ return ArrowsPuzzle(cols, rows, listOf(left, right), mapOf(at(2, 2) to Mirror.FORWARD))+ }++ @Test+ fun aUsedMirrorCanStillBeDecoration() {+ val puzzle = decorativeBoard()+ val metrics = ArrowsAnalysis.metrics(puzzle)+ // The mirror is genuinely used: the arrow's route runs through it.+ assertEquals(1, metrics.mirrorUseCount)+ assertNotNull(ArrowsRules.solve(puzzle))+ // But the board also clears with the mirror removed, so it is not required.+ assertNotNull(ArrowsRules.solve(ArrowsAnalysis.withoutMirrors(puzzle)))+ assertFalse(ArrowsAnalysis.requiresMirrors(puzzle))+ assertEquals(0, metrics.requiredMirrorCount)+ assertFalse(metrics.requiresMirrors)+ }++ @Test+ fun aMirrorThatBreaksAStandoffIsLoadBearing() {+ val puzzle = loadBearingBoard()+ assertNotNull(ArrowsRules.solve(puzzle), "the bounce should clear the standoff")+ assertNull(+ ArrowsRules.solve(ArrowsAnalysis.withoutMirrors(puzzle)),+ "facing arrows with no bend can never leave",+ )+ assertTrue(ArrowsAnalysis.requiresMirrors(puzzle))+ val metrics = ArrowsAnalysis.metrics(puzzle)+ assertTrue(metrics.requiresMirrors)+ assertEquals(1, metrics.requiredMirrorCount, "the only mirror is the load-bearing one")+ }++ @Test+ fun aBoardWithNoMirrorsDoesNotRequireMirrors() {+ val puzzle = ArrowsPuzzle(+ cols, rows,+ listOf(ArrowPiece(0, listOf(at(2, 1), at(2, 2)), Direction.RIGHT)),+ )+ assertNotNull(ArrowsRules.solve(puzzle))+ assertFalse(ArrowsAnalysis.requiresMirrors(puzzle))+ assertEquals(0, ArrowsAnalysis.requiredMirrorCount(puzzle))+ }++ @Test+ fun anUnclearableBoardDoesNotCountAsRequiringMirrors() {+ // Necessity is "clearable with, unclearable without" — an impossible board proves nothing.+ val left = ArrowPiece(0, listOf(at(2, 0), at(2, 1)), Direction.RIGHT)+ val right = ArrowPiece(1, listOf(at(2, 4), at(2, 3)), Direction.LEFT)+ val puzzle = ArrowsPuzzle(cols, rows, listOf(left, right))+ assertNull(ArrowsRules.solve(puzzle))+ assertFalse(ArrowsAnalysis.requiresMirrors(puzzle))+ }++ @Test+ fun everyGeneratedMirrorBoardPerTierRequiresItsMirrors() {+ for (difficulty in ArrowsDifficulty.entries) {+ var mirrorBoards = 0+ for (seed in 0 until 6) {+ val puzzle = assertNotNull(+ ArrowsGenerator.generateSeeded(+ cols = 7,+ rows = 9,+ targetPieces = 14,+ mirrorCount = 2,+ seed = 41_000L + seed * 733L,+ difficulty = difficulty,+ ),+ "$difficulty seed $seed produced nothing",+ )+ assertNotNull(ArrowsRules.solve(puzzle), "$difficulty seed $seed with mirrors")+ if (puzzle.mirrors.isEmpty()) continue+ mirrorBoards+++ assertTrue(+ ArrowsAnalysis.requiresMirrors(puzzle),+ "$difficulty seed $seed has mirrors the board does not need",+ )+ assertNull(+ ArrowsRules.solve(ArrowsAnalysis.withoutMirrors(puzzle)),+ "$difficulty seed $seed clears without its mirrors",+ )+ }+ assertTrue(mirrorBoards > 0, "$difficulty never emitted a mirror board")+ }+ }++ @Test+ fun mirrorlessGeneratedBoardsAreUnaffectedByTheGate() {+ val puzzle = assertNotNull(+ ArrowsGenerator.generateSeeded(+ cols = 6,+ rows = 8,+ targetPieces = 12,+ mirrorCount = 0,+ seed = 4242L,+ difficulty = ArrowsDifficulty.CASUAL,+ ),+ )+ assertTrue(puzzle.mirrors.isEmpty())+ assertNotNull(ArrowsRules.solve(puzzle))+ assertFalse(ArrowsAnalysis.requiresMirrors(puzzle))+ }++ @Test+ fun theFirstMirrorLevelsTeachAForcedBounce() {+ // Mirrors arrive at MIRROR_FIRST_LEVEL, which the level mapping puts in STANDARD (CASUAL is+ // the mirrorless run before it). The first mirror boards carry a single mirror, and the+ // gate makes that mirror the only way out — the bounce cannot be ignored while learning it.+ assertEquals(ArrowsDifficulty.CASUAL, ArrowsAnalysis.difficultyForLevel(MIRROR_FIRST_LEVEL - 1))+ assertEquals(ArrowsDifficulty.STANDARD, ArrowsAnalysis.difficultyForLevel(MIRROR_FIRST_LEVEL))+ for (level in MIRROR_FIRST_LEVEL until MIRROR_FIRST_LEVEL + 3) {+ val puzzle = assertNotNull(generateFor(level), "level $level produced nothing")+ assertEquals(1, puzzle.mirrors.size, "level $level should introduce one mirror at a time")+ assertTrue(ArrowsAnalysis.requiresMirrors(puzzle), "level $level mirror is decorative")+ assertEquals(+ 1,+ ArrowsAnalysis.requiredMirrorCount(puzzle),+ "level $level's single mirror should be load-bearing",+ )+ }+ }++ @Test+ fun ladderMirrorBoardsRequireTheirMirrorsAndKeepTheirMirrors() {+ var mirrorBoards = 0+ var mirrors = 0+ var required = 0+ for (level in MIRROR_FIRST_LEVEL..60) {+ val puzzle = assertNotNull(generateFor(level), "level $level produced nothing")+ assertNotNull(ArrowsRules.solve(puzzle), "level $level with mirrors")+ // Conditional rule: no board is owed mirrors, but a board that has them must need them,+ // and a ladder level that asks for mirrors keeps at least one.+ assertTrue(puzzle.mirrors.isNotEmpty(), "level $level lost all its mirrors")+ mirrorBoards+++ mirrors += puzzle.mirrors.size+ required += ArrowsAnalysis.requiredMirrorCount(puzzle)+ assertTrue(+ ArrowsAnalysis.requiresMirrors(puzzle),+ "level $level (${puzzle.mirrors.size} mirrors) clears without them",+ )+ assertNull(ArrowsRules.solve(ArrowsAnalysis.withoutMirrors(puzzle)), "level $level")+ }+ assertTrue(mirrorBoards > 0)+ assertTrue(required > 0, "no individually load-bearing mirror in $mirrors mirrors")+ }++ @Test+ fun dailyMirrorBoardsRequireTheirMirrors() {+ val (dailyCols, dailyRows) = DAILY_BOARD+ for (day in 20_300L..20_307L) {+ val puzzle = assertNotNull(+ ArrowsGenerator.generateSeeded(+ dailyCols, dailyRows, DAILY_ARROWS, DAILY_MIRRORS, seed = 1_300_000_000L + day,+ ),+ "no daily board for day $day",+ )+ assertTrue(puzzle.mirrors.isNotEmpty(), "daily $day lost its mirrors")+ assertTrue(ArrowsAnalysis.requiresMirrors(puzzle), "daily $day clears without its mirrors")+ }+ }++ @Test+ fun necessityGatePreservesDeterminism() {+ val first = assertNotNull(generateFor(23))+ val second = assertNotNull(generateFor(23))+ assertEquals(first.pieces, second.pieces)+ assertEquals(first.mirrors, second.mirrors)+ assertTrue(ArrowsAnalysis.requiresMirrors(first))+ }++ /** Uses the same size, count, mirror, seed and tier rules the game uses for a real level. */+ private fun generateFor(level: Int) = boardSizeForLevel(level).let { (cols, rows) ->+ ArrowsGenerator.generateSeeded(+ cols = cols,+ rows = rows,+ targetPieces = arrowCountForLevel(level),+ mirrorCount = mirrorCountForLevel(level),+ seed = level.toLong(),+ difficulty = ArrowsAnalysis.difficultyForLevel(level),+ )+ }+}
games/arrows/src/test/java/com/vayunmathur/games/arrows/domain/GeneratedBoardPropertiesTest.kt
diff --git a/games/arrows/src/test/java/com/vayunmathur/games/arrows/domain/GeneratedBoardPropertiesTest.kt b/games/arrows/src/test/java/com/vayunmathur/games/arrows/domain/GeneratedBoardPropertiesTest.ktindex 7364fe473b..81efc088ae 100644--- a/games/arrows/src/test/java/com/vayunmathur/games/arrows/domain/GeneratedBoardPropertiesTest.kt+++ b/games/arrows/src/test/java/com/vayunmathur/games/arrows/domain/GeneratedBoardPropertiesTest.kt@@ -11,6 +11,7 @@ import com.vayunmathur.games.arrows.data.mirrorCountForLevel import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertNotNull+import kotlin.test.assertNull import kotlin.test.assertTrue /**@@ -44,6 +45,24 @@ class GeneratedBoardPropertiesTest { } } + @Test+ fun everyBoardWithMirrorsRequiresThem() {+ // Use is not necessity: a board whose mirrors can all be removed and still clear ships+ // redirectors the player can ignore. Boards without mirrors owe nothing.+ for (level in ladder) {+ val puzzle = boardFor(level) ?: continue+ if (puzzle.mirrors.isEmpty()) continue+ assertTrue(+ ArrowsAnalysis.requiresMirrors(puzzle),+ "level $level has mirrors but clears without them",+ )+ assertNull(+ ArrowsRules.solve(ArrowsAnalysis.withoutMirrors(puzzle)),+ "level $level clears with its mirrors removed",+ )+ }+ }+ @Test fun mirrorsAreDroppedRatherThanLeftUnused() { // Relaxation may place fewer mirrors than asked for, but never more than it is allowed to drop.