Modern Apps git

← Modern-Apps.git

games: a crossword word wins when any full occurrence is crossed

Commit
73f7c88b3e6ada09a410d52197ce6fd9bba94eed
Author
Vayun Mathur <[email protected]>
When
2026-12-01 12:43 UTC (5 days ago)
Parents
7fc0df3
winsWith demanded EVERY recorded occurrence of a word be
filled (letterPositions all), but words play as strings:
submission, rendering, incidentalWords and revealHint all
treat a word as found when one full occurrence is covered.
Board CAT.CAT with COW/ABS/TRE crossed out: CAT's first
occurrence fully crossed, its second untouched โ€”
incidentalWords reported every remaining word complete yet
winsWith stayed false, so a fully-crossed board never won.

The quantifier is now any over occurrences, consistent with
the rest of the model (the no-positions fallback is
preserved). Four regression tests (duplicate-occurrence
board, win via one covered occurrence, no win when none is
complete, a traced word counts once) โ€” the key one failed
pre-fix at exactly that assertion. Dictionary, scoring and
generation were audited and cleared (8,000 designed assets
and 200 generated boards checked). Verified:
:games:wordmaker:testDevUnitTest 165 pass; lint BUILD
SUCCESSFUL.

Diff

games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/data/CrosswordData.kt
diff --git a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/data/CrosswordData.kt b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/data/CrosswordData.ktindex e2e321d1f6..10d219fcc5 100644--- a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/data/CrosswordData.kt+++ b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/data/CrosswordData.kt@@ -22,7 +22,12 @@ data class CrosswordData(             letterPositions[it]?.flatten().orEmpty()         }         return (solutionWords - foundWords).all { word ->-            letterPositions[word]?.all { foundPositions.containsAll(it) } ?: true+            // A word is a string, not one of its occurrences: tracing it once reveals+            // every occurrence on the board (see CrosswordBoard), and incidentalWords+            // likewise credits it when any single occurrence is filled in by crossing+            // words. Requiring every occurrence to be covered would leave a word that+            // occurs twice unwinnable-by-coverage even when one occurrence is complete.+            letterPositions[word]?.any { foundPositions.containsAll(it) } ?: true         }     } 
games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/data/CrosswordDuplicateOccurrenceTest.kt
diff --git a/games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/data/CrosswordDuplicateOccurrenceTest.kt b/games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/data/CrosswordDuplicateOccurrenceTest.ktnew file mode 100644index 0000000000..66e57dd27f--- /dev/null+++ b/games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/data/CrosswordDuplicateOccurrenceTest.kt@@ -0,0 +1,54 @@+package com.vayunmathur.games.wordmaker.data++import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertFalse+import kotlin.test.assertTrue++/**+ * Regression: a solution word that occurs twice on a board is a single word โ€”+ * tracing it once reveals both occurrences, and [CrosswordData.incidentalWords]+ * credits it when any one occurrence is filled in by crossing words.+ * [CrosswordData.winsWith] must agree: it used to demand that every occurrence+ * be covered, so the board below could never register as won by coverage.+ */+class CrosswordDuplicateOccurrenceTest {++    // CAT occurs at (0,0)-(0,2) and again at (0,4)-(0,6). The first occurrence+    // is crossed at every letter by COW, ABS and TRE; OBR and WSE are the+    // horizontal by-products of those crossings. The second CAT is untouched.+    private val board = CrosswordData.fromString(+        "CAT.CAT\n" ++            "OBR....\n" ++            "WSE....",+    )!!++    @Test fun duplicateWordHasBothOccurrencesRecorded() {+        assertEquals(2, board.letterPositions["CAT"]!!.size)+        assertEquals(+            setOf("CAT", "COW", "ABS", "TRE", "OBR", "WSE"),+            board.solutionWords,+        )+    }++    @Test fun winsWithCountsAWordCoveredAtAnyOneOccurrence() {+        val crossingWords = setOf("COW", "ABS", "TRE")+        // Every word still unfound is already fully filled in: CAT through its+        // first occurrence, OBR and WSE through the crossing words themselves.+        assertEquals(setOf("CAT", "OBR", "WSE"), board.incidentalWords(crossingWords))+        assertTrue(board.winsWith(crossingWords))+    }++    @Test fun winsWithStillRequiresCoverageWhenNoOccurrenceIsComplete() {+        // Without TRE, CAT's first occurrence is missing its T at (0,2) and its+        // second occurrence is untouched, so the board is not won.+        assertFalse(board.winsWith(setOf("COW", "ABS")))+        assertFalse("CAT" in board.incidentalWords(setOf("COW", "ABS")))+    }++    @Test fun winsWithCountsTracedDuplicateWordOnce() {+        // Tracing CAT once finds the word, wherever it was traced.+        assertTrue(board.winsWith(board.solutionWords))+        assertTrue(board.winsWith(setOf("CAT", "COW", "ABS", "TRE", "OBR", "WSE")))+    }+}