@fgv/ts-sudoku-lib 2.0.2-alpha.0

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 (95) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +5 -0
  3. package/cspell.json +13 -0
  4. package/dist/ts-sudoku-lib.d.ts +763 -0
  5. package/dist/tsdoc-metadata.json +11 -0
  6. package/lib/index.d.ts +6 -0
  7. package/lib/index.d.ts.map +1 -0
  8. package/lib/index.js +59 -0
  9. package/lib/index.js.map +1 -0
  10. package/lib/packlets/collections/collections.d.ts +55 -0
  11. package/lib/packlets/collections/collections.d.ts.map +1 -0
  12. package/lib/packlets/collections/collections.js +137 -0
  13. package/lib/packlets/collections/collections.js.map +1 -0
  14. package/lib/packlets/collections/data/puzzles.json +61 -0
  15. package/lib/packlets/collections/index.d.ts +2 -0
  16. package/lib/packlets/collections/index.d.ts.map +1 -0
  17. package/lib/packlets/collections/index.js +41 -0
  18. package/lib/packlets/collections/index.js.map +1 -0
  19. package/lib/packlets/common/cage.d.ts +23 -0
  20. package/lib/packlets/common/cage.d.ts.map +1 -0
  21. package/lib/packlets/common/cage.js +87 -0
  22. package/lib/packlets/common/cage.js.map +1 -0
  23. package/lib/packlets/common/cell.d.ts +34 -0
  24. package/lib/packlets/common/cell.d.ts.map +1 -0
  25. package/lib/packlets/common/cell.js +92 -0
  26. package/lib/packlets/common/cell.js.map +1 -0
  27. package/lib/packlets/common/common.d.ts +77 -0
  28. package/lib/packlets/common/common.d.ts.map +1 -0
  29. package/lib/packlets/common/common.js +49 -0
  30. package/lib/packlets/common/common.js.map +1 -0
  31. package/lib/packlets/common/converters.d.ts +24 -0
  32. package/lib/packlets/common/converters.d.ts.map +1 -0
  33. package/lib/packlets/common/converters.js +73 -0
  34. package/lib/packlets/common/converters.js.map +1 -0
  35. package/lib/packlets/common/ids.d.ts +15 -0
  36. package/lib/packlets/common/ids.d.ts.map +1 -0
  37. package/lib/packlets/common/ids.js +107 -0
  38. package/lib/packlets/common/ids.js.map +1 -0
  39. package/lib/packlets/common/index.d.ts +12 -0
  40. package/lib/packlets/common/index.d.ts.map +1 -0
  41. package/lib/packlets/common/index.js +65 -0
  42. package/lib/packlets/common/index.js.map +1 -0
  43. package/lib/packlets/common/model.d.ts +15 -0
  44. package/lib/packlets/common/model.d.ts.map +1 -0
  45. package/lib/packlets/common/model.js +26 -0
  46. package/lib/packlets/common/model.js.map +1 -0
  47. package/lib/packlets/common/public.d.ts +65 -0
  48. package/lib/packlets/common/public.d.ts.map +1 -0
  49. package/lib/packlets/common/public.js +26 -0
  50. package/lib/packlets/common/public.js.map +1 -0
  51. package/lib/packlets/common/puzzle.d.ts +99 -0
  52. package/lib/packlets/common/puzzle.d.ts.map +1 -0
  53. package/lib/packlets/common/puzzle.js +389 -0
  54. package/lib/packlets/common/puzzle.js.map +1 -0
  55. package/lib/packlets/common/puzzleSession.d.ts +214 -0
  56. package/lib/packlets/common/puzzleSession.d.ts.map +1 -0
  57. package/lib/packlets/common/puzzleSession.js +361 -0
  58. package/lib/packlets/common/puzzleSession.js.map +1 -0
  59. package/lib/packlets/common/puzzleState.d.ts +52 -0
  60. package/lib/packlets/common/puzzleState.d.ts.map +1 -0
  61. package/lib/packlets/common/puzzleState.js +100 -0
  62. package/lib/packlets/common/puzzleState.js.map +1 -0
  63. package/lib/packlets/file/converters.d.ts +17 -0
  64. package/lib/packlets/file/converters.d.ts.map +1 -0
  65. package/lib/packlets/file/converters.js +49 -0
  66. package/lib/packlets/file/converters.js.map +1 -0
  67. package/lib/packlets/file/index.d.ts +4 -0
  68. package/lib/packlets/file/index.d.ts.map +1 -0
  69. package/lib/packlets/file/index.js +54 -0
  70. package/lib/packlets/file/index.js.map +1 -0
  71. package/lib/packlets/file/model.d.ts +9 -0
  72. package/lib/packlets/file/model.d.ts.map +1 -0
  73. package/lib/packlets/file/model.js +26 -0
  74. package/lib/packlets/file/model.js.map +1 -0
  75. package/lib/packlets/puzzles/anyPuzzle.d.ts +10 -0
  76. package/lib/packlets/puzzles/anyPuzzle.d.ts.map +1 -0
  77. package/lib/packlets/puzzles/anyPuzzle.js +51 -0
  78. package/lib/packlets/puzzles/anyPuzzle.js.map +1 -0
  79. package/lib/packlets/puzzles/index.d.ts +6 -0
  80. package/lib/packlets/puzzles/index.d.ts.map +1 -0
  81. package/lib/packlets/puzzles/index.js +35 -0
  82. package/lib/packlets/puzzles/index.js.map +1 -0
  83. package/lib/packlets/puzzles/killerSudokuPuzzle.d.ts +14 -0
  84. package/lib/packlets/puzzles/killerSudokuPuzzle.d.ts.map +1 -0
  85. package/lib/packlets/puzzles/killerSudokuPuzzle.js +136 -0
  86. package/lib/packlets/puzzles/killerSudokuPuzzle.js.map +1 -0
  87. package/lib/packlets/puzzles/sudokuPuzzle.d.ts +10 -0
  88. package/lib/packlets/puzzles/sudokuPuzzle.d.ts.map +1 -0
  89. package/lib/packlets/puzzles/sudokuPuzzle.js +47 -0
  90. package/lib/packlets/puzzles/sudokuPuzzle.js.map +1 -0
  91. package/lib/packlets/puzzles/sudokuXPuzzle.d.ts +11 -0
  92. package/lib/packlets/puzzles/sudokuXPuzzle.d.ts.map +1 -0
  93. package/lib/packlets/puzzles/sudokuXPuzzle.js +65 -0
  94. package/lib/packlets/puzzles/sudokuXPuzzle.js.map +1 -0
  95. package/package.json +70 -0
@@ -0,0 +1,763 @@
1
+ import { Brand } from '@fgv/ts-utils';
2
+ import { Converter } from '@fgv/ts-utils';
3
+ import { Result } from '@fgv/ts-utils';
4
+
5
+ /**
6
+ * All supported public types.
7
+ * @public
8
+ */
9
+ export declare const allPuzzleTypes: PuzzleType[];
10
+
11
+ /**
12
+ * Static class to instantiate any puzzle from a {@link Data.Model.PuzzleDescription | puzzle description}.
13
+ * @internal
14
+ */
15
+ declare class AnyPuzzle {
16
+ static create(puzzle: IPuzzleDescription): Result<Puzzle>;
17
+ }
18
+
19
+ /**
20
+ * @internal
21
+ */
22
+ export declare class Cage implements ICage {
23
+ readonly id: CageId;
24
+ readonly cageType: CageType;
25
+ readonly total: number;
26
+ protected readonly _cellIds: CellId[];
27
+ private _values;
28
+ private constructor();
29
+ get cellIds(): CellId[];
30
+ get numCells(): number;
31
+ static create(id: CageId, type: CageType, total: number, cells: CellId[]): Result<Cage>;
32
+ containsCell(id: CellId): boolean;
33
+ containsValue(value: number, state: PuzzleState, ignore?: CellId[]): boolean;
34
+ containedValues(state: PuzzleState): Set<number>;
35
+ toString(state?: PuzzleState): string;
36
+ }
37
+
38
+ /**
39
+ * Nominal identifier for a single {@Link ICage | cage} in a {@link PuzzleSession | puzzle}.
40
+ * @public
41
+ */
42
+ export declare type CageId = Brand<string, 'CageId'>;
43
+
44
+ /**
45
+ * Converts an arbitrary value to a {@link CageId | CageId}.
46
+ * @public
47
+ */
48
+ declare const cageId: Converter<CageId>;
49
+
50
+ /**
51
+ * Identifies the type of a {@Link ICage | cage}.
52
+ * @public
53
+ */
54
+ export declare type CageType = 'row' | 'column' | 'section' | 'x' | 'killer';
55
+
56
+ /**
57
+ * @internal
58
+ */
59
+ export declare class Cell implements ICellInit, ICell {
60
+ readonly id: CellId;
61
+ readonly row: number;
62
+ readonly col: number;
63
+ readonly cages: readonly Cage[];
64
+ readonly immutable: boolean;
65
+ readonly immutableValue?: number;
66
+ constructor(init: ICellInit, cages: readonly Cage[]);
67
+ isValid(state: PuzzleState): boolean;
68
+ hasValue(state: PuzzleState): boolean;
69
+ isValidValue(value: number | undefined, state: PuzzleState): boolean;
70
+ update(value: number | undefined, notes: number[]): Result<ICellState>;
71
+ updateValue(value: number | undefined, state: PuzzleState): Result<ICellState>;
72
+ updateNotes(notes: number[], state: PuzzleState): Result<ICellState>;
73
+ toString(state?: PuzzleState): string;
74
+ }
75
+
76
+ /**
77
+ * Nominal identifier for a single {@Link ICell | cell} in a {@link PuzzleSession | puzzle}.
78
+ * @public
79
+ */
80
+ export declare type CellId = Brand<string, 'CellId'>;
81
+
82
+ /**
83
+ * Converts an arbitrary value to a {@link CellId | CellId}.
84
+ * @public
85
+ */
86
+ declare const cellId: Converter<CellId>;
87
+
88
+ declare namespace Converters {
89
+ export {
90
+ cageId,
91
+ cellId,
92
+ puzzleType,
93
+ puzzleDescription
94
+ }
95
+ }
96
+ export { Converters }
97
+
98
+ declare namespace Converters_2 {
99
+ export {
100
+ loadJsonPuzzlesFileSync,
101
+ puzzlesFile
102
+ }
103
+ }
104
+
105
+ declare namespace File_2 {
106
+ export {
107
+ Converters_2 as Converters,
108
+ Model
109
+ }
110
+ }
111
+ export { File_2 as File }
112
+
113
+ /**
114
+ * Describes the structure of a single cage in a {@link PuzzleSession | puzzle}.
115
+ * Does not describe state.
116
+ * @public
117
+ */
118
+ export declare interface ICage {
119
+ /**
120
+ * Unique identifier for the cage.
121
+ */
122
+ readonly id: CageId;
123
+ /**
124
+ * The {@link CageType | type} of the cage.
125
+ */
126
+ readonly cageType: CageType;
127
+ /**
128
+ * The expected sum of all cells in the cage.
129
+ */
130
+ readonly total: number;
131
+ /**
132
+ * The number of cells in the cage.
133
+ */
134
+ readonly numCells: number;
135
+ /**
136
+ * The identity of each cell in the cage.
137
+ */
138
+ readonly cellIds: CellId[];
139
+ /**
140
+ * Determines if a supplied cell is present in the cage.
141
+ * @param id - the identifier to be searched.
142
+ */
143
+ containsCell(id: CellId): boolean;
144
+ }
145
+
146
+ /**
147
+ * Describes the structure of a single cell in a {@link PuzzleSession | puzzle}.
148
+ * Does not describe state.
149
+ * @public
150
+ */
151
+ export declare interface ICell {
152
+ /**
153
+ * Unique identifier for the cell.
154
+ */
155
+ readonly id: CellId;
156
+ /**
157
+ * Row number of the cell.
158
+ */
159
+ readonly row: number;
160
+ /**
161
+ * Column number of the cell.
162
+ */
163
+ readonly col: number;
164
+ /**
165
+ * All of the {@Link ICage | cages} to which this cell belongs.
166
+ */
167
+ readonly cages: readonly ICage[];
168
+ /**
169
+ * Indicates whether this cell is a given value (immutable).
170
+ */
171
+ readonly immutable: boolean;
172
+ /**
173
+ * Given value of this cell, or `undefined` if the cell is not immutable.
174
+ */
175
+ readonly immutableValue?: number;
176
+ }
177
+
178
+ /**
179
+ * The contents of a single {@Link ICell | cell} in a {@link PuzzleSession | puzzle}.
180
+ * @public
181
+ */
182
+ export declare interface ICellContents {
183
+ /**
184
+ * The value of the {@link ICell | cell}, or `undefined` if no value has been assigned.
185
+ */
186
+ readonly value?: number;
187
+ /**
188
+ * Any notes associated with the {@link ICell | cell}.
189
+ */
190
+ readonly notes: number[];
191
+ }
192
+
193
+ /**
194
+ * @internal
195
+ */
196
+ export declare interface ICellInit {
197
+ readonly id: CellId;
198
+ readonly row: number;
199
+ readonly col: number;
200
+ readonly immutableValue?: number;
201
+ }
202
+
203
+ /**
204
+ * Describes the state of or a state update for a single {@link ICell |cell} in a
205
+ * {@link PuzzleSession | puzzle}.
206
+ * @public
207
+ */
208
+ export declare interface ICellState extends ICellContents {
209
+ readonly id: CellId;
210
+ }
211
+
212
+ /**
213
+ * @internal
214
+ */
215
+ export declare interface ICellUpdate {
216
+ from: ICellState;
217
+ to: ICellState;
218
+ }
219
+
220
+ /**
221
+ * @public
222
+ */
223
+ export declare class Ids {
224
+ static cageId(from: string | ICage): Result<CageId>;
225
+ static cellId(spec: string | IRowColumn | ICell): Result<CellId>;
226
+ static rowCageId(row: number): CageId;
227
+ static columnCageId(col: number): CageId;
228
+ static sectionCageId(row: number, col: number): CageId;
229
+ static cellIds(firstRow: number, numRows: number, firstCol: number, numCols: number): Result<CellId[]>;
230
+ }
231
+
232
+ /**
233
+ * Description of a single puzzle.
234
+ * @public
235
+ */
236
+ export declare interface IPuzzleDescription {
237
+ id?: string;
238
+ description: string;
239
+ type: PuzzleType;
240
+ level: number;
241
+ rows: number;
242
+ cols: number;
243
+ cells: string;
244
+ }
245
+
246
+ /**
247
+ * Parsed file containing a collection of puzzles.
248
+ * @public
249
+ */
250
+ declare interface IPuzzlesFile {
251
+ puzzles: IPuzzleDescription[];
252
+ }
253
+
254
+ declare interface IPuzzleStep {
255
+ updates: ICellUpdate[];
256
+ }
257
+
258
+ /**
259
+ * @internal
260
+ */
261
+ export declare interface IPuzzleUpdate {
262
+ from: PuzzleState;
263
+ to: PuzzleState;
264
+ cells: ICellUpdate[];
265
+ }
266
+
267
+ /**
268
+ * The row/column coordinate of a single {@Link ICell | cell} in a {@link PuzzleSession | puzzle}.
269
+ * @public
270
+ */
271
+ export declare interface IRowColumn {
272
+ row: number;
273
+ col: number;
274
+ }
275
+
276
+ /**
277
+ * @public
278
+ */
279
+ declare class KillerSudokuPuzzle extends Puzzle {
280
+ private constructor();
281
+ static create(desc: IPuzzleDescription): Result<Puzzle>;
282
+ private static _getKillerCages;
283
+ private static _getCageCells;
284
+ private static _getCages;
285
+ private static _getKillerCells;
286
+ }
287
+
288
+ /**
289
+ * Loads an arbitrary JSON file and parses it to return a validated
290
+ * {@link Data.Model.PuzzlesFile | PuzzlesFile}.
291
+ * @param path - String path to the file
292
+ * @returns `Success` with the resulting file, or `Failure` with details if an
293
+ * error occurs.
294
+ * @public
295
+ */
296
+ declare function loadJsonPuzzlesFileSync(path: string): Result<IPuzzlesFile>;
297
+
298
+ declare namespace Model {
299
+ export {
300
+ IPuzzlesFile
301
+ }
302
+ }
303
+
304
+ /**
305
+ * Navigation direction within a puzzle.
306
+ * @public
307
+ *
308
+ */
309
+ export declare type NavigationDirection = 'down' | 'left' | 'right' | 'up';
310
+
311
+ /**
312
+ * Wrapping rules when navigating within a puzzle.
313
+ * @public
314
+ */
315
+ export declare type NavigationWrap = 'none' | 'wrap-around' | 'wrap-next';
316
+
317
+ /**
318
+ * @internal
319
+ */
320
+ export declare class Puzzle {
321
+ readonly id?: string;
322
+ readonly description: string;
323
+ readonly initialState: PuzzleState;
324
+ /**
325
+ * @internal
326
+ */
327
+ protected readonly _rows: Map<CageId, Cage>;
328
+ /**
329
+ * @internal
330
+ */
331
+ protected readonly _columns: Map<CageId, Cage>;
332
+ /**
333
+ * @internal
334
+ */
335
+ protected readonly _sections: Map<CageId, Cage>;
336
+ /**
337
+ * @internal
338
+ */
339
+ protected readonly _cages: Map<CageId, Cage>;
340
+ /**
341
+ * @internal
342
+ */
343
+ protected readonly _cells: Map<CellId, Cell>;
344
+ /**
345
+ * Constructs a new puzzle state.
346
+ * @param puzzle - {@Link Data.Model.PuzzleDescription | Puzzle description} from which this puzzle state
347
+ * is to be initialized.
348
+ */
349
+ protected constructor(puzzle: IPuzzleDescription, extraCages?: [CageId, Cage][]);
350
+ get numRows(): number;
351
+ get numColumns(): number;
352
+ get rows(): Cage[];
353
+ get cols(): Cage[];
354
+ get sections(): Cage[];
355
+ get cages(): Cage[];
356
+ get cells(): Cell[];
357
+ /**
358
+ * @internal
359
+ */
360
+ protected static _createRowCages(numRows: number, numCols: number): Result<[CageId, Cage][]>;
361
+ /**
362
+ * @internal
363
+ */
364
+ protected static _createColumnCages(numRows: number, numCols: number): Result<[CageId, Cage][]>;
365
+ /**
366
+ * @internal
367
+ */
368
+ private static _createSectionCages;
369
+ checkIsSolved(state: PuzzleState): boolean;
370
+ checkIsValid(state: PuzzleState): boolean;
371
+ getEmptyCells(state: PuzzleState): Cell[];
372
+ getInvalidCells(state: PuzzleState): Cell[];
373
+ getCellContents(spec: string | IRowColumn, state: PuzzleState): Result<{
374
+ cell: Cell;
375
+ contents: ICellContents;
376
+ }>;
377
+ getCell(spec: string | IRowColumn | ICell): Result<Cell>;
378
+ getCellNeighbor(spec: string | IRowColumn | ICell, direction: NavigationDirection, wrap: NavigationWrap): Result<ICell>;
379
+ updateContents(wantUpdates: ICellState[] | ICellState, state: PuzzleState): Result<IPuzzleUpdate>;
380
+ updateValues(wantUpdates: ICellState[] | ICellState, state: PuzzleState): Result<IPuzzleUpdate>;
381
+ updateNotes(wantUpdates: ICellState[] | ICellState, state: PuzzleState): Result<IPuzzleUpdate>;
382
+ updateCellValue(want: string | IRowColumn, value: number | undefined, state: PuzzleState): Result<IPuzzleUpdate>;
383
+ updateCellNotes(want: string | IRowColumn, notes: number[], state: PuzzleState): Result<IPuzzleUpdate>;
384
+ getRow(row: CageId | number): Result<Cage>;
385
+ getColumn(col: CageId | number): Result<Cage>;
386
+ getSection(spec: CageId | IRowColumn): Result<Cage>;
387
+ getCage(id: CageId): Result<Cage>;
388
+ toStrings(state: PuzzleState): string[];
389
+ toString(state: PuzzleState): string;
390
+ private _moveColumn;
391
+ private _moveRow;
392
+ }
393
+
394
+ /**
395
+ * A collection of puzzles of various types.
396
+ * @public
397
+ */
398
+ export declare class PuzzleCollection {
399
+ /**
400
+ * All puzzles in the collection.
401
+ */
402
+ readonly puzzles: readonly IPuzzleDescription[];
403
+ private readonly _byId;
404
+ private constructor();
405
+ /**
406
+ * Creates a new puzzle from a loaded {@link FileData.Model.IPuzzlesFile | PuzzlesFile}
407
+ * @param from - The {@link FileData.Model.IPuzzlesFile | puzzles file} to be loaded.
408
+ * @returns `Success` with the resulting {@link PuzzleCollection | PuzzleCollection}
409
+ * or `Failure` with details if an error occurs.
410
+ */
411
+ static create(from: File_2.Model.IPuzzlesFile): Result<PuzzleCollection>;
412
+ /**
413
+ * Creates a new puzzle from a JSON file.
414
+ * @param path - path to the JSON file to be loaded.
415
+ * @returns `Success` with the resulting {@link PuzzleCollection | PuzzleCollection}
416
+ * or `Failure` with details if an error occurs.
417
+ */
418
+ static load(path: string): Result<PuzzleCollection>;
419
+ /**
420
+ * Gets a puzzle by id from this collection.
421
+ * @param id - The string ID of the puzzle to be returned.
422
+ * @returns `Success` with the requested {@link PuzzleSession | puzzle}, or
423
+ * `Failure` with details if an error occurs.
424
+ */
425
+ getPuzzle(id: string): Result<PuzzleSession>;
426
+ /**
427
+ * Gets a puzzle by id from this collection.
428
+ * @param id - The string ID of the puzzle to be returned.
429
+ * @returns `Success` with the requested {@link PuzzleSession | puzzle}, or
430
+ * `Failure` with details if an error occurs.
431
+ */
432
+ getDescription(id: string): Result<IPuzzleDescription>;
433
+ }
434
+
435
+ /**
436
+ * Get well-known {@link PuzzleCollection | puzzle collections}.
437
+ * @public
438
+ */
439
+ export declare class PuzzleCollections {
440
+ private static _default;
441
+ /**
442
+ * The default {@link PuzzleCollection | puzzle collection}.
443
+ */
444
+ static get default(): PuzzleCollection;
445
+ }
446
+
447
+ /**
448
+ * Converts an arbitrary object to a {@link Data.Model.PuzzleDescription | PuzzleDescription}.
449
+ * @public
450
+ */
451
+ declare const puzzleDescription: Converter<IPuzzleDescription>;
452
+
453
+ declare namespace Puzzles {
454
+ export {
455
+ AnyPuzzle as Any,
456
+ KillerSudokuPuzzle as Killer,
457
+ SudokuPuzzle as Sudoku,
458
+ SudokuXPuzzle as SudokuX
459
+ }
460
+ }
461
+ export { Puzzles }
462
+
463
+ /**
464
+ * Represents a single puzzle session, including puzzle, current state and redo/undo.
465
+ * @public
466
+ */
467
+ export declare class PuzzleSession {
468
+ /**
469
+ * The current {@link PuzzleState | state} of this puzzle session.
470
+ */
471
+ state: PuzzleState;
472
+ protected readonly _puzzle: Puzzle;
473
+ protected _nextStep: number;
474
+ protected _numSteps: number;
475
+ protected _steps: IPuzzleStep[];
476
+ /**
477
+ * @internal
478
+ */
479
+ protected constructor(puzzle: Puzzle);
480
+ /**
481
+ * ID of the puzzle being solved.
482
+ */
483
+ get id(): string | undefined;
484
+ /**
485
+ * Description of the puzzle being solved.
486
+ */
487
+ get description(): string;
488
+ /**
489
+ * Number of rows in the puzzle being solved.
490
+ */
491
+ get numRows(): number;
492
+ /**
493
+ * Number of columns in the puzzle being solved.
494
+ */
495
+ get numColumns(): number;
496
+ /**
497
+ * The row {@link ICage | cages} in the puzzle being solved.
498
+ */
499
+ get rows(): ICage[];
500
+ /**
501
+ * The column {@link ICage | cages} in the puzzle being solved.
502
+ */
503
+ get cols(): ICage[];
504
+ /**
505
+ * The section {@link ICage | cages} in the puzzle being solved.
506
+ */
507
+ get sections(): ICage[];
508
+ /**
509
+ * All {@link ICage | cages} in the puzzle being solved.
510
+ */
511
+ get cages(): ICage[];
512
+ /**
513
+ * The cells {@link ICell | cells} in the puzzle being solved.
514
+ */
515
+ get cells(): ICell[];
516
+ /**
517
+ * Index of the next step in this puzzle session.
518
+ */
519
+ get nextStep(): number;
520
+ /**
521
+ * Number of steps currently elapsed in this puzzle session. Note
522
+ * that after undo, `nextStep` will be less than `numSteps`.
523
+ */
524
+ get numSteps(): number;
525
+ /***
526
+ * Indicates whether undo is currently possible.
527
+ */
528
+ get canUndo(): boolean;
529
+ /**
530
+ * Indicates whether redo is currently possible.
531
+ */
532
+ get canRedo(): boolean;
533
+ /**
534
+ * Creates a new {@link PuzzleSession | puzzle session} from a supplied
535
+ * {@link Puzzle | puzzle}.
536
+ * @param puzzle - The {@link Puzzle | puzzle} from which the session is to be
537
+ * initialized.
538
+ * @returns `Success` with the requested {@link PuzzleSession | puzzle session},
539
+ * or `Failure` with details if an error occurs.
540
+ */
541
+ static create(puzzle: Puzzle): Result<PuzzleSession>;
542
+ /**
543
+ * Determines if the puzzle is correctly solved.
544
+ * @returns `true` if the puzzle is solved, `false` if the puzzle has
545
+ * empty or invalid cells.
546
+ */
547
+ checkIsSolved(): boolean;
548
+ /**
549
+ * Determines if the puzzle is valid in its current state.
550
+ * @returns `true` if all non-empty cells in the puzzle are valid,
551
+ * or `false` if any cells are invalid.
552
+ */
553
+ checkIsValid(): boolean;
554
+ /**
555
+ * Gets all of the currently empty {@link ICell | cells} in the puzzle.
556
+ * @returns An array of {@link ICell | ICell} with all empty cells.
557
+ */
558
+ getEmptyCells(): ICell[];
559
+ /**
560
+ * Gets all of the currently invalid {@link ICell | cells} in the puzzle.
561
+ * @returns An array of {@link ICell | ICell} with all invalid cells.
562
+ */
563
+ getInvalidCells(): ICell[];
564
+ /**
565
+ * Determines if a cell is valid.
566
+ * @param spec - A `string` ({@link CellId | CellId}), {@link IRowColumn | RowColumn} or {@link ICell | ICell}
567
+ * describing the cell to be tested.
568
+ * @returns `true` if the cell value is valid, `false` if the cell value or the cell itself is invalid.
569
+ */
570
+ cellIsValid(spec: string | IRowColumn | ICell): boolean;
571
+ /**
572
+ * Determines if a cell has a value.
573
+ * @param spec - A `string` ({@link CellId | CellId}), {@link IRowColumn | RowColumn} or {@link ICell | ICell}
574
+ * describing the cell to be tested.
575
+ * @returns `true` if the cell has a value, `false` if the cell is empty or the cell itself is invalid.
576
+ */
577
+ cellHasValue(spec: string | IRowColumn | ICell): boolean;
578
+ /**
579
+ * Determines if supplied value is valid for a specific cell.
580
+ * @param spec - A `string` ({@link CellId | CellId}), {@link IRowColumn | RowColumn} or {@link ICell | ICell}
581
+ * describing the cell to be tested.
582
+ * @param value - The value to be tested.
583
+ * @returns `true` if `value` is valid for the requested cell, `false` if the value or the cell itself is invalid.
584
+ */
585
+ isValidForCell(spec: string | IRowColumn | ICell, value: number): boolean;
586
+ /**
587
+ * Gets the neighbor for a cell in a given direction using specified wrapping rules.
588
+ * @param spec - A `string` ({@link CellId | CellId}), {@link IRowColumn | RowColumn} or {@link ICell | ICell}
589
+ * describing the cell to be tested.
590
+ * @param direction - The direction of the desired neighbor.
591
+ * @param wrap - Wrapping rules to be applied.
592
+ * @returns `Success` with the requested {@link ICell | cell}, or `Failure` with details if an error occurs.
593
+ */
594
+ getCellNeighbor(spec: string | IRowColumn | ICell, direction: NavigationDirection, wrap: NavigationWrap): Result<ICell>;
595
+ /**
596
+ * Gets the {@link ICellContents | contents} for a specified cell.
597
+ * @param spec - A `string` ({@link CellId | CellId}), {@link IRowColumn | RowColumn} or {@link ICell | ICell}
598
+ * describing the cell to be queried.
599
+ * @returns `Success` with the {@link ICell | cell description} and {@link ICellContents | cell contents}, or
600
+ * `Failure` with details if an error occurs.
601
+ */
602
+ getCellContents(spec: string | IRowColumn): Result<{
603
+ cell: ICell;
604
+ contents: ICellContents;
605
+ }>;
606
+ /**
607
+ * Updates the value of a cell.
608
+ * @param spec - A `string`, {@link IRowColumn | row and column}, or {@link ICell | cell} identifying
609
+ * the cell to be updated.
610
+ * @param value - A new value for the cell.
611
+ * @returns `Success` with `this` if the update is applied, `Failure` with details if an error occurs.
612
+ */
613
+ updateCellValue(spec: string | IRowColumn | ICell, value: number | undefined): Result<this>;
614
+ /**
615
+ * Updates the notes on a cell.
616
+ * @param spec - A `string`, {@link IRowColumn | row and column}, or {@link ICell | cell} identifying
617
+ * the cell to be updated.
618
+ * @param notes - New notes for the cell.
619
+ * @returns `Success` with `this` if the update is applied, `Failure` with details if an error occurs.
620
+ */
621
+ updateCellNotes(spec: string | IRowColumn | ICell, notes: number[]): Result<this>;
622
+ /**
623
+ * Updates value & notes for multiple cells.
624
+ * @param updates - An array of {@link ICellState | cell state} objects, each describing
625
+ * one cell to be updated.
626
+ * @returns `Success` with `this` if the updates are applied, `Failure` with details if
627
+ * an error occurs.
628
+ */
629
+ updateCells(updates: ICellState[]): Result<this>;
630
+ /**
631
+ * Determines if some {@link ICage | cage} contains a specific value.
632
+ * @param spec - A `string` ({@link CageId | CageId}) or {@link ICage | ICage}
633
+ * indicating the cage to be tested.
634
+ * @param value - The value to be tested.
635
+ * @returns `true` if the cage exists and contains the specified value,
636
+ * `false` otherwise.
637
+ */
638
+ cageContainsValue(spec: string | ICage, value: number): boolean;
639
+ /**
640
+ * Determines the numbers currently present in some cage.
641
+ * @param spec - A `string` ({@link CageId | CageId}) or {@link ICage | ICage}
642
+ * indicating the cage to be tested.
643
+ * @returns A `Set<number>` containing all numbers present in the cage.
644
+ */
645
+ cageContainedValues(spec: string | ICage): Set<number>;
646
+ /**
647
+ * Undo a single move in this puzzle session.
648
+ * @returns `Success` with `this` if the undo is applied, or `Failure`
649
+ * with details if an error occurs.
650
+ */
651
+ undo(): Result<this>;
652
+ /**
653
+ * Redo a single move in this puzzle session.
654
+ * @returns `Success` with `this` if the redo is applied, or `Failure`
655
+ * with details if an error occurs.
656
+ */
657
+ redo(): Result<this>;
658
+ /**
659
+ * Gets a string representation of this puzzle, one string
660
+ * per row.
661
+ */
662
+ toStrings(): string[];
663
+ private _addMove;
664
+ private _cage;
665
+ private _cell;
666
+ }
667
+
668
+ /**
669
+ * Converts an arbitrary object to a {@link Data.Model.PuzzlesFile | PuzzlesFile}.
670
+ * @public
671
+ */
672
+ declare const puzzlesFile: Converter<IPuzzlesFile>;
673
+
674
+ /**
675
+ * @public
676
+ */
677
+ export declare class PuzzleState {
678
+ /**
679
+ * @internal
680
+ */
681
+ protected readonly _cells: Map<CellId, ICellContents>;
682
+ /**
683
+ * @internal
684
+ */
685
+ protected constructor(from: Map<CellId, ICellContents>, updates?: ICellState[]);
686
+ /**
687
+ * Constructs a new {@link PuzzleState | PuzzleState}.
688
+ * @param cells - An array of {@link ICellState | CellState} used to initialize the state.
689
+ * @returns The new {@link PuzzleState | PuzzleState}.
690
+ */
691
+ static create(cells: ICellState[]): Result<PuzzleState>;
692
+ /**
693
+ * Convert {@link ICellContents | CellContents} to `[`{@link CellId | CellId}`,` {@link ICellContents | CellContents}`]`
694
+ * tuple for `Map` construction.
695
+ * @param states - An array of {@link ICellContents | CellContents} to be converted.
696
+ * @returns The corresponding array of `[`{@link CellId | CellId}`,` {@link ICellContents | CellContents}`]`
697
+ * @internal
698
+ */
699
+ protected static _toEntries(states?: ICellState[]): [CellId, ICellContents][];
700
+ /**
701
+ * Gets the contents of a cell specified by {@link CellId | id}.
702
+ * @param id - The {@link CellId | id} of the cell to be retrieved.
703
+ * @returns A {@link ICellContents | CellContents} with the contents of
704
+ * the requested cell.
705
+ */
706
+ getCellContents(id: CellId): Result<ICellContents>;
707
+ /**
708
+ * Determines if some cell has an assigned value.
709
+ * @param id - The {@link CellId | id} of the cell to be tested.
710
+ * @returns `true` if the cell has a value, `false` if the cell
711
+ * is empty or invalid.
712
+ */
713
+ hasValue(id: CellId): boolean;
714
+ /**
715
+ * Creates a new {@link PuzzleState | PuzzleState} which corresponds
716
+ * to this state with updates applied.
717
+ * @param updates - An array of {@link ICellState | CellState} to be
718
+ * applied.
719
+ * @returns A new {@link PuzzleState} with updates applied.
720
+ */
721
+ update(updates: ICellState[]): Result<PuzzleState>;
722
+ }
723
+
724
+ /**
725
+ * Describes the rules that apply to the puzzle.
726
+ * @public
727
+ */
728
+ export declare type PuzzleType = 'killer-sudoku' | 'sudoku' | 'sudoku-x';
729
+
730
+ /**
731
+ * Converts an arbitrary value to a {@link PuzzleType | PuzzleType}.
732
+ * @public
733
+ */
734
+ declare const puzzleType: Converter<PuzzleType, PuzzleType[]>;
735
+
736
+ /**
737
+ * @public
738
+ */
739
+ declare class SudokuPuzzle extends Puzzle {
740
+ private constructor();
741
+ static create(puzzle: IPuzzleDescription): Result<Puzzle>;
742
+ }
743
+
744
+ /**
745
+ * @public
746
+ */
747
+ declare class SudokuXPuzzle extends Puzzle {
748
+ private constructor();
749
+ static create(puzzle: IPuzzleDescription): Result<Puzzle>;
750
+ private static _getXCages;
751
+ }
752
+
753
+ /**
754
+ * The minimum and maximum possible values for a {@link ICage | cage}, by cage size in
755
+ * {@link ICell | cells}.
756
+ * @public
757
+ */
758
+ export declare const totalsByCageSize: readonly {
759
+ min: number;
760
+ max: number;
761
+ }[];
762
+
763
+ export { }