@fgv/ts-sudoku-lib 5.0.1-1 → 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,50 @@
1
+ const path = require('path');
2
+
3
+ // Add the lib directory to require paths
4
+ const libPath = path.join(__dirname, 'lib');
5
+ require.main.paths.unshift(libPath);
6
+
7
+ try {
8
+ const Puzzles = require('./lib/packlets/puzzles');
9
+
10
+ const puzzleDesc = {
11
+ id: 'test-killer',
12
+ description: 'Test killer sudoku puzzle',
13
+ type: 'killer-sudoku',
14
+ level: 1,
15
+ rows: 9,
16
+ cols: 9,
17
+ cells: [
18
+ 'ABCCCDDDE',
19
+ 'ABFFGGGDE',
20
+ 'HIJKGGLLL',
21
+ 'HIJKMGLNN',
22
+ 'HOPPMQQNR',
23
+ 'OOSTMUVWR',
24
+ 'SSSTTUVWR',
25
+ 'XYTTTZZab',
26
+ 'XYYYcccab',
27
+ '|A11,B09,C09,D20,E16,F17,G30,H17,I13,J09,K11,L16,M16,N11,O16,P07,Q11,R10,S14,T39,U08,V17,W16,X06,Y26,Z06,a09,b09,c11'
28
+ ].join('')
29
+ };
30
+
31
+ console.log('Creating puzzle...');
32
+ const puzzle = Puzzles.Killer.create(puzzleDesc);
33
+
34
+ if (puzzle.isSuccess()) {
35
+ console.log('Success! Analyzing killer cages:');
36
+ const killerCages = puzzle.value.cages.filter((cage) => cage.id.startsWith('K'));
37
+ killerCages.forEach((cage) => {
38
+ console.log(
39
+ `- ${cage.id}: ${cage.numCells} cells, total ${cage.total}, cells: [${Array.from(cage.cellIds).join(
40
+ ','
41
+ )}]`
42
+ );
43
+ });
44
+ } else {
45
+ console.error('Puzzle creation failed:', puzzle.message);
46
+ }
47
+ } catch (error) {
48
+ console.error('Error:', error.message);
49
+ console.error('Stack:', error.stack);
50
+ }
package/debug_test.js ADDED
@@ -0,0 +1,88 @@
1
+ const path = require('path');
2
+ const libPath = path.join(__dirname, 'lib');
3
+ require.main.paths.unshift(libPath);
4
+
5
+ try {
6
+ const Puzzles = require('./lib/packlets/puzzles');
7
+ const { PuzzleSession } = require('./lib/packlets/common');
8
+ const { KillerCombinations } = require('./lib/packlets/puzzles');
9
+
10
+ function createSimpleKillerCage(cageSize, total, containedValues = []) {
11
+ const existingPuzzleDesc = {
12
+ id: 'test-killer',
13
+ description: 'Test killer sudoku puzzle',
14
+ type: 'killer-sudoku',
15
+ level: 1,
16
+ rows: 9,
17
+ cols: 9,
18
+ cells: [
19
+ 'ABCCCDDDE',
20
+ 'ABFFGGGDE',
21
+ 'HIJKGGLLL',
22
+ 'HIJKMGLNN',
23
+ 'HOPPMQQNR',
24
+ 'OOSTMUVWR',
25
+ 'SSSTTUVWR',
26
+ 'XYTTTZZab',
27
+ 'XYYYcccab',
28
+ '|A11,B09,C09,D20,E16,F17,G30,H17,I13,J09,K11,L16,M16,N11,O16,P07,Q11,R10,S14,T39,U08,V17,W16,X06,Y26,Z06,a09,b09,c11'
29
+ ].join('')
30
+ };
31
+
32
+ const puzzle = Puzzles.Killer.create(existingPuzzleDesc);
33
+ if (puzzle.isFailure()) throw new Error(puzzle.message);
34
+
35
+ const session = PuzzleSession.create(puzzle.value);
36
+ if (session.isFailure()) throw new Error(session.message);
37
+
38
+ // Apply contained values if provided
39
+ if (containedValues.length > 0) {
40
+ const cageA = puzzle.value.getCage('KA');
41
+ if (cageA.isFailure()) throw new Error(cageA.message);
42
+ const cellIds = Array.from(cageA.value.cellIds);
43
+ containedValues.forEach((value, index) => {
44
+ if (index < cellIds.length) {
45
+ const result = session.value.updateCellValue(cellIds[index], value);
46
+ if (result.isFailure()) throw new Error(result.message);
47
+ }
48
+ });
49
+ }
50
+
51
+ // For this simple test, we'll use cage KA
52
+ const cage = puzzle.value.getCage('KA');
53
+ if (cage.isFailure()) throw new Error(cage.message);
54
+
55
+ return { puzzle: puzzle.value, state: session.value.state, cage: cage.value };
56
+ }
57
+
58
+ console.log('Testing cage KA with one cell filled with 5...');
59
+ const { puzzle, state, cage } = createSimpleKillerCage(2, 11, [5]);
60
+
61
+ console.log('Cage info:', {
62
+ id: cage.id,
63
+ total: cage.total,
64
+ numCells: cage.numCells,
65
+ cellIds: Array.from(cage.cellIds)
66
+ });
67
+
68
+ console.log('Cell states:');
69
+ Array.from(cage.cellIds).forEach((cellId) => {
70
+ const contents = state.getCellContents(cellId);
71
+ if (contents.isSuccess()) {
72
+ console.log(` ${cellId}:`, contents.value);
73
+ }
74
+ });
75
+
76
+ const result = KillerCombinations.getCellPossibilities(puzzle, state, cage);
77
+ if (result.isSuccess()) {
78
+ console.log('Possibilities:');
79
+ result.value.forEach((values, cellId) => {
80
+ console.log(` ${cellId}: [${values.join(',')}]`);
81
+ });
82
+ } else {
83
+ console.error('Failed to get possibilities:', result.message);
84
+ }
85
+ } catch (error) {
86
+ console.error('Error:', error.message);
87
+ console.error('Stack:', error.stack);
88
+ }