@fgv/ts-sudoku-lib 5.0.1-0 → 5.0.1-2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/debug_killer.js +50 -0
  2. package/debug_test.js +88 -0
  3. package/dist/ts-sudoku-lib.d.ts +1505 -42
  4. package/lib/index.d.ts +3 -2
  5. package/lib/index.js +5 -3
  6. package/lib/packlets/collections/collections.d.ts +15 -8
  7. package/lib/packlets/collections/collections.js +41 -11
  8. package/lib/packlets/collections/data/puzzles.json +28 -33
  9. package/lib/packlets/common/common.d.ts +15 -0
  10. package/lib/packlets/common/common.js +25 -0
  11. package/lib/packlets/common/converters.d.ts +0 -6
  12. package/lib/packlets/common/converters.js +17 -22
  13. package/lib/packlets/common/ids.d.ts +8 -1
  14. package/lib/packlets/common/ids.js +83 -10
  15. package/lib/packlets/common/index.d.ts +3 -2
  16. package/lib/packlets/common/index.js +5 -2
  17. package/lib/packlets/common/logging.d.ts +7 -0
  18. package/lib/packlets/common/logging.js +35 -0
  19. package/lib/packlets/common/puzzle.d.ts +23 -13
  20. package/lib/packlets/common/puzzle.js +51 -25
  21. package/lib/packlets/common/puzzleDefinitions.d.ts +127 -0
  22. package/lib/packlets/common/puzzleDefinitions.js +251 -0
  23. package/lib/packlets/common/puzzleSession.d.ts +8 -0
  24. package/lib/packlets/common/puzzleSession.js +12 -0
  25. package/lib/packlets/common/puzzleState.js +3 -0
  26. package/lib/packlets/files/converters.d.ts +27 -0
  27. package/lib/packlets/files/converters.js +71 -0
  28. package/lib/packlets/{file/converters.d.ts → files/filesystem.d.ts} +3 -8
  29. package/lib/packlets/{file/converters.js → files/filesystem.js} +5 -14
  30. package/lib/packlets/files/index.d.ts +5 -0
  31. package/lib/packlets/{file → files}/index.js +3 -1
  32. package/lib/packlets/files/model.d.ts +32 -0
  33. package/lib/packlets/hints/baseHintProvider.d.ts +103 -0
  34. package/lib/packlets/hints/baseHintProvider.js +203 -0
  35. package/lib/packlets/hints/explanations.d.ts +105 -0
  36. package/lib/packlets/hints/explanations.js +276 -0
  37. package/lib/packlets/hints/hiddenSingles.d.ts +81 -0
  38. package/lib/packlets/hints/hiddenSingles.js +237 -0
  39. package/lib/packlets/hints/hintRegistry.d.ts +95 -0
  40. package/lib/packlets/hints/hintRegistry.js +226 -0
  41. package/lib/packlets/hints/hints.d.ts +144 -0
  42. package/lib/packlets/hints/hints.js +316 -0
  43. package/lib/packlets/hints/index.d.ts +10 -0
  44. package/lib/packlets/hints/index.js +55 -0
  45. package/lib/packlets/hints/interfaces.d.ts +121 -0
  46. package/lib/packlets/{file/model.js → hints/interfaces.js} +1 -1
  47. package/lib/packlets/hints/nakedSingles.d.ts +57 -0
  48. package/lib/packlets/hints/nakedSingles.js +202 -0
  49. package/lib/packlets/hints/puzzleSessionHints.d.ts +306 -0
  50. package/lib/packlets/hints/puzzleSessionHints.js +499 -0
  51. package/lib/packlets/hints/types.d.ts +102 -0
  52. package/lib/packlets/hints/types.js +46 -0
  53. package/lib/packlets/puzzles/anyPuzzle.d.ts +3 -3
  54. package/lib/packlets/puzzles/anyPuzzle.js +1 -1
  55. package/lib/packlets/puzzles/index.d.ts +4 -2
  56. package/lib/packlets/puzzles/index.js +20 -3
  57. package/lib/packlets/puzzles/internal/combinationCache.d.ts +29 -0
  58. package/lib/packlets/puzzles/internal/combinationCache.js +79 -0
  59. package/lib/packlets/puzzles/internal/combinationGenerator.d.ts +34 -0
  60. package/lib/packlets/puzzles/internal/combinationGenerator.js +146 -0
  61. package/lib/packlets/puzzles/internal/possibilityAnalyzer.d.ts +25 -0
  62. package/lib/packlets/puzzles/internal/possibilityAnalyzer.js +125 -0
  63. package/lib/packlets/puzzles/killerCombinations.d.ts +90 -0
  64. package/lib/packlets/puzzles/killerCombinations.js +226 -0
  65. package/lib/packlets/puzzles/killerCombinationsTypes.d.ts +17 -0
  66. package/lib/packlets/puzzles/killerCombinationsTypes.js +26 -0
  67. package/lib/packlets/puzzles/killerSudokuPuzzle.d.ts +2 -2
  68. package/lib/packlets/puzzles/killerSudokuPuzzle.js +15 -11
  69. package/lib/packlets/puzzles/sudokuPuzzle.d.ts +2 -2
  70. package/lib/packlets/puzzles/sudokuXPuzzle.d.ts +2 -2
  71. package/lib/packlets/puzzles/sudokuXPuzzle.js +8 -4
  72. package/package.json +5 -5
  73. package/sample-12x12-puzzle.js +72 -0
  74. package/sample-4x4-puzzles.js +68 -0
  75. package/sample-6x6-puzzle.js +61 -0
  76. package/temp_12x12_cells.txt +12 -0
  77. package/temp_correct.txt +12 -0
  78. package/test-grid-sizes.js +132 -0
  79. package/lib/packlets/common/model.d.ts +0 -15
  80. package/lib/packlets/file/index.d.ts +0 -4
  81. package/lib/packlets/file/model.d.ts +0 -9
  82. /package/lib/packlets/{common → files}/model.js +0 -0
@@ -0,0 +1,12 @@
1
+ ..1.6.2.A7..
2
+ 62.5B....1..
3
+ .8....C3B.62
4
+ A97.2.6..B5.
5
+ .5......37C.
6
+ 3B....7...9.
7
+ 57B.4.....1.
8
+ 8.....A.9...
9
+ .4..97...6..
10
+ .1C.......B.
11
+ 4....2.C....
12
+ ....5C..7126
@@ -0,0 +1,132 @@
1
+ #!/usr/bin/env node
2
+
3
+ // Test script to verify all grid sizes work correctly
4
+ const { PuzzleDefinitionFactory, STANDARD_CONFIGS } = require('./lib/packlets/common');
5
+ const Puzzles = require('./lib/packlets/puzzles');
6
+
7
+ console.log('🧩 Testing Variable Grid Size Support\n');
8
+
9
+ // Test all standard configurations
10
+ const configurations = [
11
+ { name: '4x4', config: STANDARD_CONFIGS.puzzle4x4, expectedMax: 4, cells: '.'.repeat(16) },
12
+ { name: '6x6', config: STANDARD_CONFIGS.puzzle6x6, expectedMax: 6, cells: '.'.repeat(36) },
13
+ { name: '9x9', config: STANDARD_CONFIGS.puzzle9x9, expectedMax: 9, cells: '.'.repeat(81) },
14
+ { name: '12x12', config: STANDARD_CONFIGS.puzzle12x12, expectedMax: 12, cells: '.'.repeat(144) }
15
+ ];
16
+
17
+ let allTestsPassed = true;
18
+
19
+ for (const { name, config, expectedMax, cells } of configurations) {
20
+ console.log(`📐 Testing ${name} grid...`);
21
+
22
+ try {
23
+ // Create puzzle definition
24
+ const puzzleDefResult = PuzzleDefinitionFactory.create(config, {
25
+ description: `Test ${name} Sudoku`,
26
+ type: 'sudoku',
27
+ level: 1,
28
+ cells: cells
29
+ });
30
+
31
+ if (puzzleDefResult.isFailure()) {
32
+ console.error(` ❌ Failed to create ${name} definition: ${puzzleDefResult.message}`);
33
+ allTestsPassed = false;
34
+ continue;
35
+ }
36
+
37
+ const puzzleDef = puzzleDefResult.value;
38
+
39
+ // Verify calculations
40
+ const expectedRows = config.cageHeightInCells * config.boardHeightInCages;
41
+ const expectedCols = config.cageWidthInCells * config.boardWidthInCages;
42
+ const expectedTotal = (expectedMax * (expectedMax + 1)) / 2;
43
+
44
+ if (puzzleDef.totalRows !== expectedRows) {
45
+ console.error(` ❌ Wrong row count: expected ${expectedRows}, got ${puzzleDef.totalRows}`);
46
+ allTestsPassed = false;
47
+ }
48
+
49
+ if (puzzleDef.totalColumns !== expectedCols) {
50
+ console.error(` ❌ Wrong column count: expected ${expectedCols}, got ${puzzleDef.totalColumns}`);
51
+ allTestsPassed = false;
52
+ }
53
+
54
+ if (puzzleDef.maxValue !== expectedMax) {
55
+ console.error(` ❌ Wrong max value: expected ${expectedMax}, got ${puzzleDef.maxValue}`);
56
+ allTestsPassed = false;
57
+ }
58
+
59
+ if (puzzleDef.basicCageTotal !== expectedTotal) {
60
+ console.error(` ❌ Wrong cage total: expected ${expectedTotal}, got ${puzzleDef.basicCageTotal}`);
61
+ allTestsPassed = false;
62
+ }
63
+
64
+ // Debug: Log section IDs being generated
65
+ console.log(` Cage dimensions: ${config.cageWidthInCells}x${config.cageHeightInCells}`);
66
+ console.log(` Board dimensions: ${config.boardWidthInCages}x${config.boardHeightInCages}`);
67
+
68
+ // Create actual puzzle
69
+ const puzzleResult = Puzzles.Sudoku.create(puzzleDef);
70
+ if (puzzleResult.isFailure()) {
71
+ console.error(` ❌ Failed to create ${name} puzzle: ${puzzleResult.message}`);
72
+ allTestsPassed = false;
73
+ continue;
74
+ }
75
+
76
+ const puzzle = puzzleResult.value;
77
+
78
+ // Verify puzzle properties
79
+ if (puzzle.numRows !== expectedRows || puzzle.numColumns !== expectedCols) {
80
+ console.error(` ❌ Puzzle dimensions mismatch`);
81
+ allTestsPassed = false;
82
+ }
83
+
84
+ console.log(
85
+ ` ✅ ${name}: ${expectedRows}x${expectedCols} grid, max value ${expectedMax}, cage total ${expectedTotal}`
86
+ );
87
+ } catch (error) {
88
+ console.error(` ❌ Error testing ${name}: ${error.message}`);
89
+ allTestsPassed = false;
90
+ }
91
+ }
92
+
93
+ // Test Sudoku X with 9x9
94
+ console.log(`\n🔥 Testing Sudoku X (9x9 with diagonal constraints)...`);
95
+ try {
96
+ const sudokuXDef = PuzzleDefinitionFactory.create(STANDARD_CONFIGS.puzzle9x9, {
97
+ description: 'Test Sudoku X',
98
+ type: 'sudoku-x',
99
+ level: 1,
100
+ cells: '.'.repeat(81)
101
+ });
102
+
103
+ if (sudokuXDef.isSuccess()) {
104
+ const puzzleResult = Puzzles.SudokuX.create(sudokuXDef.value);
105
+ if (puzzleResult.isSuccess()) {
106
+ const puzzle = puzzleResult.value;
107
+
108
+ // Check for diagonal cages
109
+ const x1Result = puzzle.getCage('X1');
110
+ const x2Result = puzzle.getCage('X2');
111
+
112
+ if (x1Result.isSuccess() && x2Result.isSuccess()) {
113
+ console.log(` ✅ Sudoku X: 9x9 grid with diagonal constraints (X1 & X2 cages)`);
114
+ } else {
115
+ console.error(` ❌ Sudoku X missing diagonal cages`);
116
+ allTestsPassed = false;
117
+ }
118
+ } else {
119
+ console.error(` ❌ Failed to create Sudoku X puzzle: ${puzzleResult.message}`);
120
+ allTestsPassed = false;
121
+ }
122
+ } else {
123
+ console.error(` ❌ Failed to create Sudoku X definition: ${sudokuXDef.message}`);
124
+ allTestsPassed = false;
125
+ }
126
+ } catch (error) {
127
+ console.error(` ❌ Error testing Sudoku X: ${error.message}`);
128
+ allTestsPassed = false;
129
+ }
130
+
131
+ console.log(`\n${allTestsPassed ? '🎉 All grid size tests passed!' : '💥 Some tests failed'}`);
132
+ process.exit(allTestsPassed ? 0 : 1);
@@ -1,15 +0,0 @@
1
- import { PuzzleType } from './common';
2
- /**
3
- * Description of a single puzzle.
4
- * @public
5
- */
6
- export interface IPuzzleDescription {
7
- id?: string;
8
- description: string;
9
- type: PuzzleType;
10
- level: number;
11
- rows: number;
12
- cols: number;
13
- cells: string;
14
- }
15
- //# sourceMappingURL=model.d.ts.map
@@ -1,4 +0,0 @@
1
- import * as Converters from './converters';
2
- import * as Model from './model';
3
- export { Converters, Model };
4
- //# sourceMappingURL=index.d.ts.map
@@ -1,9 +0,0 @@
1
- import { IPuzzleDescription } from '../common';
2
- /**
3
- * Parsed file containing a collection of puzzles.
4
- * @public
5
- */
6
- export interface IPuzzlesFile {
7
- puzzles: IPuzzleDescription[];
8
- }
9
- //# sourceMappingURL=model.d.ts.map
File without changes