pastilhas
07f07376be
feat: implement Phase 21 - replace with pattern-based generation
...
Replace Robatron's complex algorithm with simpler, always-valid approach:
Core Changes:
- src/useBoard/SudokuGenerator.ts: Complete rewrite
- Pattern-based generation (base pattern + structural shuffles)
- Generate complete solution first, then remove cells
- Validates all boards before returning (defensive)
- Class-based API: generate(), getPuzzle(), getSolution()
- Configurable difficulty: CELLS_TO_REMOVE = {easy: 40, medium: 50, hard: 60}
- ~130 lines vs 372 lines (much simpler)
- src/useBoard/SudokuRenderer.ts: NEW - Clean separation
- render(board, initialBoard): Displays current state
- renderEmpty(): Shows empty 9x9 grid
- Distinguishes 'given' vs 'user-entered' cells with CSS classes
- src/useBoard/useBoard.ts: Updated for class architecture
- Refs: generatorRef, rendererRef, boardRef, solutionRef
- Uses class instances for generation and rendering
- Clean separation of concerns
- src/useBoard/SudokuGenerator.test.ts: Unit tests
- Tests valid board generation (100x)
- Tests correct cell removal counts per difficulty
- Tests puzzle/solution consistency
Algorithm Benefits:
1. Always valid - starts with mathematically valid board
2. Always solvable - we keep the solution reference
3. Fast - no backtracking, just pattern + shuffle
4. Simple - easy to understand and maintain
5. Predictable - difficulty = cell count, not complexity
Pattern-Based Approach:
- Base pattern ensures valid structure
- Shuffle rows/cols within bands/stacks (preserves 3x3 boxes)
- Shuffle band/stack order
- Shuffle digit mapping (1-9)
- Result: Valid, random, unique board every time
Phase 21 complete. Next: Phase 30 (useGameStatus hook).
2025-10-22 18:39:55 +01:00
pastilhas
9292b83dd0
feat: prepare vim-sudoku for unified API implementation
...
- Archive previous implementation attempt (src -> src_failed)
- Create comprehensive IMPLEMENTATION_PLAN.md with phased approach
- Create IMPLEMENTATION.md to track implementation progress
- Update example app to match vim-maze patterns:
- Simplify UI to desktop-only (no mobile support)
- Add score metrics display (time, keystrokes, final score)
- Update instructions for sudoku-specific keys (hjkl, i for edit)
- Remove unnecessary mobile hooks
Phase 5 complete. Ready to begin Phase 10 (Setup & Core Types).
2025-10-22 18:08:33 +01:00