@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.
- package/debug_killer.js +50 -0
- package/debug_test.js +88 -0
- package/dist/ts-sudoku-lib.d.ts +1505 -42
- package/lib/index.d.ts +3 -2
- package/lib/index.js +5 -3
- package/lib/packlets/collections/collections.d.ts +15 -8
- package/lib/packlets/collections/collections.js +41 -11
- package/lib/packlets/collections/data/puzzles.json +28 -33
- package/lib/packlets/common/common.d.ts +15 -0
- package/lib/packlets/common/common.js +25 -0
- package/lib/packlets/common/converters.d.ts +0 -6
- package/lib/packlets/common/converters.js +17 -22
- package/lib/packlets/common/ids.d.ts +8 -1
- package/lib/packlets/common/ids.js +83 -10
- package/lib/packlets/common/index.d.ts +3 -2
- package/lib/packlets/common/index.js +5 -2
- package/lib/packlets/common/logging.d.ts +7 -0
- package/lib/packlets/common/logging.js +35 -0
- package/lib/packlets/common/puzzle.d.ts +23 -13
- package/lib/packlets/common/puzzle.js +51 -25
- package/lib/packlets/common/puzzleDefinitions.d.ts +127 -0
- package/lib/packlets/common/puzzleDefinitions.js +251 -0
- package/lib/packlets/common/puzzleSession.d.ts +8 -0
- package/lib/packlets/common/puzzleSession.js +12 -0
- package/lib/packlets/common/puzzleState.js +3 -0
- package/lib/packlets/files/converters.d.ts +27 -0
- package/lib/packlets/files/converters.js +71 -0
- package/lib/packlets/{file/converters.d.ts → files/filesystem.d.ts} +3 -8
- package/lib/packlets/{file/converters.js → files/filesystem.js} +5 -14
- package/lib/packlets/files/index.d.ts +5 -0
- package/lib/packlets/{file → files}/index.js +3 -1
- package/lib/packlets/files/model.d.ts +32 -0
- package/lib/packlets/hints/baseHintProvider.d.ts +103 -0
- package/lib/packlets/hints/baseHintProvider.js +203 -0
- package/lib/packlets/hints/explanations.d.ts +105 -0
- package/lib/packlets/hints/explanations.js +276 -0
- package/lib/packlets/hints/hiddenSingles.d.ts +81 -0
- package/lib/packlets/hints/hiddenSingles.js +237 -0
- package/lib/packlets/hints/hintRegistry.d.ts +95 -0
- package/lib/packlets/hints/hintRegistry.js +226 -0
- package/lib/packlets/hints/hints.d.ts +144 -0
- package/lib/packlets/hints/hints.js +316 -0
- package/lib/packlets/hints/index.d.ts +10 -0
- package/lib/packlets/hints/index.js +55 -0
- package/lib/packlets/hints/interfaces.d.ts +121 -0
- package/lib/packlets/{file/model.js → hints/interfaces.js} +1 -1
- package/lib/packlets/hints/nakedSingles.d.ts +57 -0
- package/lib/packlets/hints/nakedSingles.js +202 -0
- package/lib/packlets/hints/puzzleSessionHints.d.ts +306 -0
- package/lib/packlets/hints/puzzleSessionHints.js +499 -0
- package/lib/packlets/hints/types.d.ts +102 -0
- package/lib/packlets/hints/types.js +46 -0
- package/lib/packlets/puzzles/anyPuzzle.d.ts +3 -3
- package/lib/packlets/puzzles/anyPuzzle.js +1 -1
- package/lib/packlets/puzzles/index.d.ts +4 -2
- package/lib/packlets/puzzles/index.js +20 -3
- package/lib/packlets/puzzles/internal/combinationCache.d.ts +29 -0
- package/lib/packlets/puzzles/internal/combinationCache.js +79 -0
- package/lib/packlets/puzzles/internal/combinationGenerator.d.ts +34 -0
- package/lib/packlets/puzzles/internal/combinationGenerator.js +146 -0
- package/lib/packlets/puzzles/internal/possibilityAnalyzer.d.ts +25 -0
- package/lib/packlets/puzzles/internal/possibilityAnalyzer.js +125 -0
- package/lib/packlets/puzzles/killerCombinations.d.ts +90 -0
- package/lib/packlets/puzzles/killerCombinations.js +226 -0
- package/lib/packlets/puzzles/killerCombinationsTypes.d.ts +17 -0
- package/lib/packlets/puzzles/killerCombinationsTypes.js +26 -0
- package/lib/packlets/puzzles/killerSudokuPuzzle.d.ts +2 -2
- package/lib/packlets/puzzles/killerSudokuPuzzle.js +15 -11
- package/lib/packlets/puzzles/sudokuPuzzle.d.ts +2 -2
- package/lib/packlets/puzzles/sudokuXPuzzle.d.ts +2 -2
- package/lib/packlets/puzzles/sudokuXPuzzle.js +8 -4
- package/package.json +5 -5
- package/sample-12x12-puzzle.js +72 -0
- package/sample-4x4-puzzles.js +68 -0
- package/sample-6x6-puzzle.js +61 -0
- package/temp_12x12_cells.txt +12 -0
- package/temp_correct.txt +12 -0
- package/test-grid-sizes.js +132 -0
- package/lib/packlets/common/model.d.ts +0 -15
- package/lib/packlets/file/index.d.ts +0 -4
- package/lib/packlets/file/model.d.ts +0 -9
- /package/lib/packlets/{common → files}/model.js +0 -0
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
import { Result } from '@fgv/ts-utils';
|
|
2
|
+
import { ICellState, IRowColumn, ICell, PuzzleSession } from '../common';
|
|
3
|
+
import { HintSystem, IHintSystemConfig } from './hints';
|
|
4
|
+
import { ExplanationLevel, IHint, IHintGenerationOptions } from './types';
|
|
5
|
+
/**
|
|
6
|
+
* Configuration options for the PuzzleSessionHints integration.
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export interface IPuzzleSessionHintsConfig extends IHintSystemConfig {
|
|
10
|
+
readonly cacheTimeoutMs?: number;
|
|
11
|
+
readonly maxCacheEntries?: number;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Wrapper class that integrates hint functionality with PuzzleSession.
|
|
15
|
+
* Provides hint generation, application, and explanation capabilities while
|
|
16
|
+
* maintaining integration with existing state management and undo/redo functionality.
|
|
17
|
+
* @public
|
|
18
|
+
*/
|
|
19
|
+
export declare class PuzzleSessionHints {
|
|
20
|
+
private readonly _session;
|
|
21
|
+
private readonly _hintSystem;
|
|
22
|
+
private readonly _config;
|
|
23
|
+
private _hintCache;
|
|
24
|
+
/**
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
private constructor();
|
|
28
|
+
/**
|
|
29
|
+
* Creates a new PuzzleSessionHints wrapper for an existing PuzzleSession.
|
|
30
|
+
* @param session - The PuzzleSession to wrap
|
|
31
|
+
* @param config - Optional configuration for the hint system
|
|
32
|
+
* @returns Result containing the new PuzzleSessionHints wrapper
|
|
33
|
+
*/
|
|
34
|
+
static create(session: PuzzleSession, config?: IPuzzleSessionHintsConfig): Result<PuzzleSessionHints>;
|
|
35
|
+
/**
|
|
36
|
+
* Gets the wrapped PuzzleSession instance.
|
|
37
|
+
* @returns The underlying PuzzleSession
|
|
38
|
+
*/
|
|
39
|
+
get session(): PuzzleSession;
|
|
40
|
+
/**
|
|
41
|
+
* Gets the HintSystem instance.
|
|
42
|
+
* @returns The hint system
|
|
43
|
+
*/
|
|
44
|
+
get hintSystem(): HintSystem;
|
|
45
|
+
/**
|
|
46
|
+
* Gets the configuration.
|
|
47
|
+
* @returns The configuration
|
|
48
|
+
*/
|
|
49
|
+
get config(): IPuzzleSessionHintsConfig;
|
|
50
|
+
/**
|
|
51
|
+
* Gets the puzzle ID.
|
|
52
|
+
* @returns The puzzle ID
|
|
53
|
+
*/
|
|
54
|
+
get id(): string | undefined;
|
|
55
|
+
/**
|
|
56
|
+
* Gets the puzzle description.
|
|
57
|
+
* @returns The puzzle description
|
|
58
|
+
*/
|
|
59
|
+
get description(): string;
|
|
60
|
+
/**
|
|
61
|
+
* Gets the number of rows in the puzzle.
|
|
62
|
+
* @returns The number of rows
|
|
63
|
+
*/
|
|
64
|
+
get numRows(): number;
|
|
65
|
+
/**
|
|
66
|
+
* Gets the number of columns in the puzzle.
|
|
67
|
+
* @returns The number of columns
|
|
68
|
+
*/
|
|
69
|
+
get numColumns(): number;
|
|
70
|
+
/**
|
|
71
|
+
* Gets the current puzzle state.
|
|
72
|
+
* @returns The current state
|
|
73
|
+
*/
|
|
74
|
+
get state(): import('../common').PuzzleState;
|
|
75
|
+
/**
|
|
76
|
+
* Gets whether undo is possible.
|
|
77
|
+
* @returns true if undo is possible
|
|
78
|
+
*/
|
|
79
|
+
get canUndo(): boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Gets whether redo is possible.
|
|
82
|
+
* @returns true if redo is possible
|
|
83
|
+
*/
|
|
84
|
+
get canRedo(): boolean;
|
|
85
|
+
/**
|
|
86
|
+
* Checks if the puzzle is solved.
|
|
87
|
+
* @returns true if the puzzle is solved
|
|
88
|
+
*/
|
|
89
|
+
checkIsSolved(): boolean;
|
|
90
|
+
/**
|
|
91
|
+
* Checks if the puzzle is valid.
|
|
92
|
+
* @returns true if the puzzle is valid
|
|
93
|
+
*/
|
|
94
|
+
checkIsValid(): boolean;
|
|
95
|
+
/**
|
|
96
|
+
* Updates a cell value.
|
|
97
|
+
* @param spec - Cell specification
|
|
98
|
+
* @param value - New value
|
|
99
|
+
* @returns Result with this instance
|
|
100
|
+
*/
|
|
101
|
+
updateCellValue(spec: string | IRowColumn | ICell, value: number | undefined): Result<this>;
|
|
102
|
+
/**
|
|
103
|
+
* Updates cell notes.
|
|
104
|
+
* @param spec - Cell specification
|
|
105
|
+
* @param notes - New notes
|
|
106
|
+
* @returns Result with this instance
|
|
107
|
+
*/
|
|
108
|
+
updateCellNotes(spec: string | IRowColumn | ICell, notes: number[]): Result<this>;
|
|
109
|
+
/**
|
|
110
|
+
* Updates multiple cells.
|
|
111
|
+
* @param updates - Array of cell updates
|
|
112
|
+
* @returns Result with this instance
|
|
113
|
+
*/
|
|
114
|
+
updateCells(updates: ICellState[]): Result<this>;
|
|
115
|
+
/**
|
|
116
|
+
* Performs an undo operation.
|
|
117
|
+
* @returns Result with this instance
|
|
118
|
+
*/
|
|
119
|
+
undo(): Result<this>;
|
|
120
|
+
/**
|
|
121
|
+
* Performs a redo operation.
|
|
122
|
+
* @returns Result with this instance
|
|
123
|
+
*/
|
|
124
|
+
redo(): Result<this>;
|
|
125
|
+
/**
|
|
126
|
+
* Gets the best available hint for the current puzzle state.
|
|
127
|
+
* @param options - Optional hint generation options
|
|
128
|
+
* @returns Result containing the best hint
|
|
129
|
+
*/
|
|
130
|
+
getHint(options?: IHintGenerationOptions): Result<IHint>;
|
|
131
|
+
/**
|
|
132
|
+
* Gets all available hints for the current puzzle state.
|
|
133
|
+
* @param options - Optional hint generation options
|
|
134
|
+
* @returns Result containing array of hints
|
|
135
|
+
*/
|
|
136
|
+
getAllHints(options?: IHintGenerationOptions): Result<readonly IHint[]>;
|
|
137
|
+
/**
|
|
138
|
+
* Applies a hint to the puzzle, updating the state and adding to undo history.
|
|
139
|
+
* @param hint - The hint to apply
|
|
140
|
+
* @returns Result with this instance if successful
|
|
141
|
+
*/
|
|
142
|
+
applyHint(hint: IHint): Result<this>;
|
|
143
|
+
/**
|
|
144
|
+
* Gets hints that specifically affect a given cell.
|
|
145
|
+
* @param spec - Cell specification (ID, row/column, or cell object)
|
|
146
|
+
* @param options - Optional hint generation options
|
|
147
|
+
* @returns Result containing hints affecting the specified cell
|
|
148
|
+
*/
|
|
149
|
+
getHintsForCell(spec: string | IRowColumn | ICell, options?: IHintGenerationOptions): Result<readonly IHint[]>;
|
|
150
|
+
/**
|
|
151
|
+
* Gets a formatted explanation for a hint.
|
|
152
|
+
* @param hint - The hint to explain
|
|
153
|
+
* @param level - The explanation level (defaults to configured default)
|
|
154
|
+
* @returns Formatted explanation string
|
|
155
|
+
*/
|
|
156
|
+
getExplanation(hint: IHint, level?: ExplanationLevel): string;
|
|
157
|
+
/**
|
|
158
|
+
* Validates that a hint can be applied to the current state.
|
|
159
|
+
* @param hint - The hint to validate
|
|
160
|
+
* @returns Result indicating validation success or failure
|
|
161
|
+
*/
|
|
162
|
+
validateHint(hint: IHint): Result<void>;
|
|
163
|
+
/**
|
|
164
|
+
* Checks if hints are available for the current state.
|
|
165
|
+
* @param options - Optional hint generation options
|
|
166
|
+
* @returns Result containing boolean indicating availability
|
|
167
|
+
*/
|
|
168
|
+
hasHints(options?: IHintGenerationOptions): Result<boolean>;
|
|
169
|
+
/**
|
|
170
|
+
* Gets statistics about available hints.
|
|
171
|
+
* @param options - Optional hint generation options
|
|
172
|
+
* @returns Result containing hint statistics
|
|
173
|
+
*/
|
|
174
|
+
getHintStatistics(options?: IHintGenerationOptions): Result<{
|
|
175
|
+
totalHints: number;
|
|
176
|
+
hintsByTechnique: Map<string, number>;
|
|
177
|
+
hintsByDifficulty: Map<string, number>;
|
|
178
|
+
}>;
|
|
179
|
+
/**
|
|
180
|
+
* Gets a summary of the hint system capabilities.
|
|
181
|
+
* @returns System capabilities summary
|
|
182
|
+
*/
|
|
183
|
+
getSystemSummary(): string;
|
|
184
|
+
/**
|
|
185
|
+
* Gets the rows.
|
|
186
|
+
* @returns Array of row cages
|
|
187
|
+
*/
|
|
188
|
+
get rows(): import('../common').ICage[];
|
|
189
|
+
/**
|
|
190
|
+
* Gets the columns.
|
|
191
|
+
* @returns Array of column cages
|
|
192
|
+
*/
|
|
193
|
+
get cols(): import('../common').ICage[];
|
|
194
|
+
/**
|
|
195
|
+
* Gets the sections.
|
|
196
|
+
* @returns Array of section cages
|
|
197
|
+
*/
|
|
198
|
+
get sections(): import('../common').ICage[];
|
|
199
|
+
/**
|
|
200
|
+
* Gets all cages.
|
|
201
|
+
* @returns Array of all cages
|
|
202
|
+
*/
|
|
203
|
+
get cages(): import('../common').ICage[];
|
|
204
|
+
/**
|
|
205
|
+
* Gets all cells.
|
|
206
|
+
* @returns Array of all cells
|
|
207
|
+
*/
|
|
208
|
+
get cells(): ICell[];
|
|
209
|
+
/**
|
|
210
|
+
* Gets the next step index.
|
|
211
|
+
* @returns Next step index
|
|
212
|
+
*/
|
|
213
|
+
get nextStep(): number;
|
|
214
|
+
/**
|
|
215
|
+
* Gets the number of steps.
|
|
216
|
+
* @returns Number of steps
|
|
217
|
+
*/
|
|
218
|
+
get numSteps(): number;
|
|
219
|
+
/**
|
|
220
|
+
* Gets empty cells.
|
|
221
|
+
* @returns Array of empty cells
|
|
222
|
+
*/
|
|
223
|
+
getEmptyCells(): ICell[];
|
|
224
|
+
/**
|
|
225
|
+
* Gets invalid cells.
|
|
226
|
+
* @returns Array of invalid cells
|
|
227
|
+
*/
|
|
228
|
+
getInvalidCells(): ICell[];
|
|
229
|
+
/**
|
|
230
|
+
* Checks if a cell is valid.
|
|
231
|
+
* @param spec - Cell specification
|
|
232
|
+
* @returns true if valid
|
|
233
|
+
*/
|
|
234
|
+
cellIsValid(spec: string | IRowColumn | ICell): boolean;
|
|
235
|
+
/**
|
|
236
|
+
* Checks if a cell has a value.
|
|
237
|
+
* @param spec - Cell specification
|
|
238
|
+
* @returns true if cell has value
|
|
239
|
+
*/
|
|
240
|
+
cellHasValue(spec: string | IRowColumn | ICell): boolean;
|
|
241
|
+
/**
|
|
242
|
+
* Checks if a value is valid for a cell.
|
|
243
|
+
* @param spec - Cell specification
|
|
244
|
+
* @param value - Value to check
|
|
245
|
+
* @returns true if valid
|
|
246
|
+
*/
|
|
247
|
+
isValidForCell(spec: string | IRowColumn | ICell, value: number): boolean;
|
|
248
|
+
/**
|
|
249
|
+
* Gets a cell neighbor.
|
|
250
|
+
* @param spec - Cell specification
|
|
251
|
+
* @param direction - Navigation direction
|
|
252
|
+
* @param wrap - Wrap behavior
|
|
253
|
+
* @returns Result containing neighbor cell
|
|
254
|
+
*/
|
|
255
|
+
getCellNeighbor(spec: string | IRowColumn | ICell, direction: import('../common').NavigationDirection, wrap: import('../common').NavigationWrap): Result<ICell>;
|
|
256
|
+
/**
|
|
257
|
+
* Gets cell contents.
|
|
258
|
+
* @param spec - Cell specification
|
|
259
|
+
* @returns Result containing cell and contents
|
|
260
|
+
*/
|
|
261
|
+
getCellContents(spec: string | IRowColumn): Result<{
|
|
262
|
+
cell: ICell;
|
|
263
|
+
contents: import('../common').ICellContents;
|
|
264
|
+
}>;
|
|
265
|
+
/**
|
|
266
|
+
* Checks if a cage contains a value.
|
|
267
|
+
* @param spec - Cage specification
|
|
268
|
+
* @param value - Value to check
|
|
269
|
+
* @returns true if cage contains value
|
|
270
|
+
*/
|
|
271
|
+
cageContainsValue(spec: string | import('../common').ICage, value: number): boolean;
|
|
272
|
+
/**
|
|
273
|
+
* Gets contained values in a cage.
|
|
274
|
+
* @param spec - Cage specification
|
|
275
|
+
* @returns Set of contained values
|
|
276
|
+
*/
|
|
277
|
+
cageContainedValues(spec: string | import('../common').ICage): Set<number>;
|
|
278
|
+
/**
|
|
279
|
+
* Gets string representation of the puzzle.
|
|
280
|
+
* @returns Array of strings representing puzzle rows
|
|
281
|
+
*/
|
|
282
|
+
toStrings(): string[];
|
|
283
|
+
/**
|
|
284
|
+
* Generates a cache key for the current state and options.
|
|
285
|
+
* @param options - Hint generation options
|
|
286
|
+
* @returns Cache key
|
|
287
|
+
*/
|
|
288
|
+
private _generateCacheKey;
|
|
289
|
+
/**
|
|
290
|
+
* Gets cached hints if valid.
|
|
291
|
+
* @param options - Hint generation options
|
|
292
|
+
* @returns Cached hints or undefined
|
|
293
|
+
*/
|
|
294
|
+
private _getCachedHints;
|
|
295
|
+
/**
|
|
296
|
+
* Updates the cache with new hints.
|
|
297
|
+
* @param hints - Generated hints
|
|
298
|
+
* @param options - Generation options
|
|
299
|
+
*/
|
|
300
|
+
private _updateCache;
|
|
301
|
+
/**
|
|
302
|
+
* Invalidates the current hint cache.
|
|
303
|
+
*/
|
|
304
|
+
private _invalidateCache;
|
|
305
|
+
}
|
|
306
|
+
//# sourceMappingURL=puzzleSessionHints.d.ts.map
|