Menu

Building a Deterministic 1-Per-Region Cat Sudoku Solver & Puzzle Generator in Vanilla JS
📰

Building a Deterministic 1-Per-Region Cat Sudoku Solver & Puzzle Generator in Vanilla JS

DEV Community: webdev·Henry·4 days ago
#kZMx8ODR
#devtowebdev#devto#dev#region#solver
Long article (729 words) — no AI summary yet.
Reading 0:00
15s threshold

When you build a region-partitioned grid logic puzzle (one piece per row, column, and colored region, with no pieces touching diagonally — the rule set behind Cat Sudoku , 1-Star Battle, and Queens-style puzzles), the hardest technical part isn't rendering the board. It's guaranteeing a single unique logical solution without making players guess.

Here is how the constraint solver and uniqueness refinement loop works in pure zero-dependency JavaScript, along with benchmark numbers across 150 generated 6×6, 8×8, and 9×9 boards.

1. Why Random Region Growth Fails Uniqueness

If you take an $N \times N$ grid, pick a valid non-touching placement of $N$ pieces (one per row and column, no 8-neighborhood collisions), and flood-fill $N$ connected colored regions outward from those pieces, you get a valid board — usually with 2 to 20+ unintended alternative solutions .

To guarantee uniqueness, we need two lightweight primitives:

Bitmask Backtracking Solver ( solveAll ) : Explores rows 0..N-1 using integer bitmasks…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.