From fb35f0739fb8b5c6cd806d86383ee064e51e5c24 Mon Sep 17 00:00:00 2001 From: Anton Stefer <59652072+antonstefer@users.noreply.github.com> Date: Thu, 9 Apr 2026 18:46:00 +0200 Subject: [PATCH 01/24] feat: add axis field for multi-ordered-category constraints (phase 1) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Introduce an `ordered` flag on Category and a required `axis` field on comparative constraints (before, left_of, next_to, not_next_to, between, not_between, exact_distance). `isPosition` is removed in favor of `ordered: true` — at least one category per grid must be ordered, and the auto-added House category fills that role when users provide none. This is phase 1 of 5: the schema changes and test migration land now, but the encoder, generator, deducer, and renderer still use row-based logic. Phase 1 compensates by identity-pinning the first ordered category in randomSolution, encodeBase, and createState so rows and ranks agree for the default axis. Phase 2 will switch to rank-forbidding encoding and remove the identity pinning. Key additions: - Category gains `ordered?: boolean` in a discriminated union that makes `numericValues` and `orderingPhrases` only legal on ordered categories. - `positionAdjective` now requires `valueSuffix` via a union type. - New axis.ts module: resolveAxis, orderedCategories, axisRank, displayAxisCategory, validateConstraints. - Grid gains optional `displayAxis` hint (presentation concern). - Grid loses `positionLabels` (derived on demand from first ordered category's values). - SpatialWords keeps `atPosition` for the at_position render path. - `renderSamePosition` gains a new rule: when one side has `positionAdjective` and the other is in an ordered category, render with the ordered value as subject and the adjective verb — recovering the classical Color+House "The first house is red" idiom from a plain same_position constraint. - default-config.ts splits DEFAULT_CONFIG into DEFAULT_CATEGORIES, DEFAULT_SPATIAL_WORDS, DEFAULT_POSITION_NOUN, DEFAULT_POSITION_PREPOSITION, and exports `defaultHouseCategory(size)` for the auto-add. - Generator's buildGrid auto-prepends the default House category as the first ordered slot (preserving total category count when the user asks for N categories without providing their own). - logic-grid-ai: theme.ts schema and prompt replace `isPosition` with `ordered`, validation.ts rejects themes with no ordered category. - Demo: PuzzleGrid and puzzle-state use `displayAxisCategory` instead of the removed `findPositionCategory`. Multi-axis is not yet functional — the encoder/deducer/renderer only consume the default (first ordered) axis in Phase 1. Phases 2-5 add unified rank-forbidding encoding, multi-axis enumeration, rank-space deduction, and per-axis rendering. --- packages/demo/src/lib/PuzzleGrid.svelte | 10 +- packages/demo/src/lib/puzzle-state.svelte.ts | 18 +- packages/demo/src/routes/+page.svelte | 16 +- packages/logic-grid-ai/src/rewrite.test.ts | 2 +- packages/logic-grid-ai/src/theme.test.ts | 1 + packages/logic-grid-ai/src/theme.ts | 23 +- packages/logic-grid-ai/src/validation.test.ts | 27 +- packages/logic-grid-ai/src/validation.ts | 17 +- .../src/__snapshots__/index.test.ts.snap | 18 +- packages/logic-grid/src/axis.ts | 88 +++ .../logic-grid/src/clues/constraints.test.ts | 39 +- packages/logic-grid/src/clues/constraints.ts | 43 +- .../logic-grid/src/clues/templates.test.ts | 748 +++++------------- packages/logic-grid/src/clues/templates.ts | 34 +- .../logic-grid/src/deduce/constraints.test.ts | 238 ++++-- packages/logic-grid/src/deduce/constraints.ts | 13 +- packages/logic-grid/src/deduce/index.test.ts | 2 +- .../logic-grid/src/deduce/propagate.test.ts | 32 +- packages/logic-grid/src/deduce/state.test.ts | 17 +- packages/logic-grid/src/deduce/state.ts | 10 + .../logic-grid/src/deduce/structural.test.ts | 4 +- packages/logic-grid/src/default-config.ts | 298 +++---- packages/logic-grid/src/difficulty.test.ts | 52 +- packages/logic-grid/src/encoding.test.ts | 62 +- packages/logic-grid/src/encoding.ts | 16 +- packages/logic-grid/src/generator.test.ts | 104 +-- packages/logic-grid/src/generator.ts | 236 +++--- packages/logic-grid/src/grid-utils.test.ts | 84 +- packages/logic-grid/src/grid-utils.ts | 12 +- packages/logic-grid/src/index.test.ts | 7 +- packages/logic-grid/src/index.ts | 14 +- packages/logic-grid/src/solver.test.ts | 59 +- packages/logic-grid/src/test-helpers.ts | 33 +- packages/logic-grid/src/types.ts | 105 ++- 34 files changed, 1176 insertions(+), 1306 deletions(-) create mode 100644 packages/logic-grid/src/axis.ts diff --git a/packages/demo/src/lib/PuzzleGrid.svelte b/packages/demo/src/lib/PuzzleGrid.svelte index ceb8689..6d5ecad 100644 --- a/packages/demo/src/lib/PuzzleGrid.svelte +++ b/packages/demo/src/lib/PuzzleGrid.svelte @@ -1,5 +1,5 @@