@@ -12,6 +12,7 @@ backwards), making the hidden target words harder to spot.
1212## 2. Goals & Non-Goals
1313
1414### Goals
15+
1516- Train an order-N Markov model from arbitrary reference text.
1617- Place a user-supplied set of target words on the lattice.
1718- Fill remaining cells using directional Markov predictions combined
@@ -20,14 +21,15 @@ backwards), making the hidden target words harder to spot.
2021 required).
2122
2223### Non-Goals
24+
2325- Server-side processing (everything runs client-side).
2426- Solving / auto-finding words (generation only, for now).
2527- Multi-language morphology (we operate on raw character sequences).
2628
2729## 3. Definitions
2830
2931| Term | Meaning |
30- | ----------------- | ---------------------------------------------------------------- |
32+ | --------------- | -------------------------------------------------------------- |
3133| Lattice / Grid | 2D array of cells, each holding a single character. |
3234| Direction | One of 8 unit vectors: N, S, E, W, NE, NW, SE, SW. |
3335| Order (N) | Number of preceding characters used as Markov context. |
@@ -64,6 +66,7 @@ manifest.webmanifest
6466## 5. Component Specifications
6567
6668### 5.1 MarkovModel
69+
6770- ` train(text, order) ` : builds nested frequency maps
6871 ` context -> { char -> count } ` .
6972- ` predict(context) ` : returns a normalised ` Map<char, prob> ` .
@@ -72,43 +75,49 @@ manifest.webmanifest
7275- Serialisable to/from JSON for caching.
7376
7477### 5.2 Grid & Directions
78+
7579- ` Grid(width, height) ` stores cells; ` get/set(x, y) ` , ` inBounds(x, y) ` .
7680- ` directions.js ` exports the 8 vectors and a helper to read the
7781 context string of length ≤ N preceding a cell along a direction.
7882
7983### 5.3 Placement
84+
8085- Randomly position each target word along a random direction,
8186 rejecting placements that conflict with already-placed letters
8287 (unless overlapping letters match).
8388- Mark placed cells as ** locked** (never overwritten by the filler).
8489
8590### 5.4 Fill Order (Adjacency)
91+
8692- Maintain a priority queue of empty cells keyed by adjacency score.
8793- Cells with more filled neighbours are filled first; ties broken
8894 randomly. Re-score neighbours after each fill.
8995
9096### 5.5 Prediction Combination
97+
9198For a target empty cell, for each of the 8 directions that has a
9299defined (non-empty) preceding context, request a prediction. Then
93100combine the resulting distributions using a configurable method:
94101
95- | Combiner | Description |
96- | ------------ | --------------------------------------------------------- |
97- | ` product ` | Multiply probabilities (logarithmic, AND-like). |
98- | ` sum ` | Average / weighted sum (OR-like). |
99- | ` max ` | Take the strongest single directional vote. |
100- | ` vote ` | Each direction votes for its argmax; majority wins. |
102+ | Combiner | Description |
103+ | --------- | --------------------------------------------------- |
104+ | ` product ` | Multiply probabilities (logarithmic, AND-like). |
105+ | ` sum ` | Average / weighted sum (OR-like). |
106+ | ` max ` | Take the strongest single directional vote. |
107+ | ` vote ` | Each direction votes for its argmax; majority wins. |
101108
102109The combined distribution is sampled (or argmax-selected per config)
103110to choose the cell's letter.
104111
105112### 5.6 UI
113+
106114- Controls: grid size, Markov order, combiner method, sampling mode,
107115 reference text input/upload, target word list.
108116- Render grid (highlight locked target letters in debug mode).
109117- Regenerate / export (text, PNG) actions.
110118
111119### 5.7 PWA
120+
112121- ` manifest.webmanifest ` + service worker caching app shell for
113122 offline use. Installable on desktop/mobile.
114123
@@ -131,13 +140,13 @@ while empty cells remain:
131140
132141## 7. Configuration Defaults
133142
134- | Option | Default |
135- | -------------- | ------------- |
136- | grid size | 15 × 15 |
137- | order (N) | 3 |
138- | combiner | ` product ` |
139- | sampling | ` weighted ` |
140- | back-off | enabled |
143+ | Option | Default |
144+ | --------- | ---------- |
145+ | grid size | 15 × 15 |
146+ | order (N) | 3 |
147+ | combiner | ` product ` |
148+ | sampling | ` weighted ` |
149+ | back-off | enabled |
141150
142151## 8. Implementation Plan (Milestones)
143152
@@ -151,11 +160,13 @@ while empty cells remain:
1511607 . ** M7 — Polish** : presets, sample reference texts, accessibility.
152161
153162## 9. Testing Strategy
163+
154164- Unit tests for model back-off, combiner math, placement conflicts.
155165- Property test: every locked target word is readable post-fill.
156166- Visual/manual QA for generated grid plausibility.
157167
158168## 10. Stretch Goals
169+
159170- Per-direction weighting of contributions.
160171- Difficulty estimation heuristics.
161- - Shareable puzzle URLs (encode grid + word list).
172+ - Shareable puzzle URLs (encode grid + word list).
0 commit comments