@fgv/ts-sudoku-lib 5.0.0-24 → 5.0.0-25

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.
@@ -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 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 File.Model.IPuzzlesFile | IPuzzlesFile}.
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 IPuzzleDescription | 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 File.Model.IPuzzlesFile | PuzzlesFile}
407
+ * @param from - The {@link File.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 IPuzzleDescription | IPuzzleDescription}.
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 File.Model.IPuzzlesFile | IPuzzlesFile}.
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, ReadonlyArray<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 { }
@@ -0,0 +1,11 @@
1
+ // This file is read by tools that parse documentation comments conforming to the TSDoc standard.
2
+ // It should be published with your NPM package. It should not be tracked by Git.
3
+ {
4
+ "tsdocVersion": "0.12",
5
+ "toolPackages": [
6
+ {
7
+ "packageName": "@microsoft/api-extractor",
8
+ "packageVersion": "7.52.10"
9
+ }
10
+ ]
11
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fgv/ts-sudoku-lib",
3
- "version": "5.0.0-24",
3
+ "version": "5.0.0-25",
4
4
  "description": "Sudoku rules library",
5
5
  "main": "lib/index.js",
6
6
  "types": "dist/ts-sudoku-lib.d.ts",
@@ -43,12 +43,12 @@
43
43
  "@rushstack/eslint-config": "4.4.0",
44
44
  "@rushstack/heft-jest-plugin": "0.16.12",
45
45
  "eslint-plugin-tsdoc": "~0.4.0",
46
- "@fgv/ts-utils": "5.0.0-24",
47
- "@fgv/ts-json-base": "5.0.0-24",
48
- "@fgv/ts-utils-jest": "5.0.0-24"
46
+ "@fgv/ts-utils-jest": "5.0.0-25",
47
+ "@fgv/ts-utils": "5.0.0-25",
48
+ "@fgv/ts-json-base": "5.0.0-25"
49
49
  },
50
50
  "peerDependencies": {
51
- "@fgv/ts-utils": "5.0.0-24"
51
+ "@fgv/ts-utils": "5.0.0-25"
52
52
  },
53
53
  "scripts": {
54
54
  "build": "heft build --clean",
@@ -1,343 +0,0 @@
1
- /**
2
- * Config file for API Extractor. For more info, please visit: https://api-extractor.com
3
- */
4
- {
5
- "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
6
- /**
7
- * Optionally specifies another JSON config file that this file extends from. This provides a way for
8
- * standard settings to be shared across multiple projects.
9
- *
10
- * If the path starts with "./" or "../", the path is resolved relative to the folder of the file that contains
11
- * the "extends" field. Otherwise, the first path segment is interpreted as an NPM package name, and will be
12
- * resolved using NodeJS require().
13
- *
14
- * SUPPORTED TOKENS: none
15
- * DEFAULT VALUE: ""
16
- */
17
- // "extends": "./shared/api-extractor-base.json"
18
- // "extends": "my-package/include/api-extractor-base.json"
19
- /**
20
- * Determines the "<projectFolder>" token that can be used with other config file settings. The project folder
21
- * typically contains the tsconfig.json and package.json config files, but the path is user-defined.
22
- *
23
- * The path is resolved relative to the folder of the config file that contains the setting.
24
- *
25
- * The default value for "projectFolder" is the token "<lookup>", which means the folder is determined by traversing
26
- * parent folders, starting from the folder containing api-extractor.json, and stopping at the first folder
27
- * that contains a tsconfig.json file. If a tsconfig.json file cannot be found in this way, then an error
28
- * will be reported.
29
- *
30
- * SUPPORTED TOKENS: <lookup>
31
- * DEFAULT VALUE: "<lookup>"
32
- */
33
- "projectFolder": "..",
34
- /**
35
- * (REQUIRED) Specifies the .d.ts file to be used as the starting point for analysis. API Extractor
36
- * analyzes the symbols exported by this module.
37
- *
38
- * The file extension must be ".d.ts" and not ".ts".
39
- *
40
- * The path is resolved relative to the folder of the config file that contains the setting; to change this,
41
- * prepend a folder token such as "<projectFolder>".
42
- *
43
- * SUPPORTED TOKENS: <projectFolder>, <packageName>, <unscopedPackageName>
44
- */
45
- "mainEntryPointFilePath": "<projectFolder>/lib/index.d.ts",
46
- /**
47
- * A list of NPM package names whose exports should be treated as part of this package.
48
- *
49
- * For example, suppose that Webpack is used to generate a distributed bundle for the project "library1",
50
- * and another NPM package "library2" is embedded in this bundle. Some types from library2 may become part
51
- * of the exported API for library1, but by default API Extractor would generate a .d.ts rollup that explicitly
52
- * imports library2. To avoid this, we can specify:
53
- *
54
- * "bundledPackages": [ "library2" ],
55
- *
56
- * This would direct API Extractor to embed those types directly in the .d.ts rollup, as if they had been
57
- * local files for library1.
58
- */
59
- "bundledPackages": [],
60
- /**
61
- * Determines how the TypeScript compiler engine will be invoked by API Extractor.
62
- */
63
- "compiler": {
64
- /**
65
- * Specifies the path to the tsconfig.json file to be used by API Extractor when analyzing the project.
66
- *
67
- * The path is resolved relative to the folder of the config file that contains the setting; to change this,
68
- * prepend a folder token such as "<projectFolder>".
69
- *
70
- * Note: This setting will be ignored if "overrideTsconfig" is used.
71
- *
72
- * SUPPORTED TOKENS: <projectFolder>, <packageName>, <unscopedPackageName>
73
- * DEFAULT VALUE: "<projectFolder>/tsconfig.json"
74
- */
75
- // "tsconfigFilePath": "<projectFolder>/tsconfig.json",
76
- /**
77
- * Provides a compiler configuration that will be used instead of reading the tsconfig.json file from disk.
78
- * The object must conform to the TypeScript tsconfig schema:
79
- *
80
- * http://json.schemastore.org/tsconfig
81
- *
82
- * If omitted, then the tsconfig.json file will be read from the "projectFolder".
83
- *
84
- * DEFAULT VALUE: no overrideTsconfig section
85
- */
86
- // "overrideTsconfig": {
87
- // . . .
88
- // }
89
- /**
90
- * This option causes the compiler to be invoked with the --skipLibCheck option. This option is not recommended
91
- * and may cause API Extractor to produce incomplete or incorrect declarations, but it may be required when
92
- * dependencies contain declarations that are incompatible with the TypeScript engine that API Extractor uses
93
- * for its analysis. Where possible, the underlying issue should be fixed rather than relying on skipLibCheck.
94
- *
95
- * DEFAULT VALUE: false
96
- */
97
- // "skipLibCheck": true,
98
- },
99
- /**
100
- * Configures how the API report file (*.api.md) will be generated.
101
- */
102
- "apiReport": {
103
- /**
104
- * (REQUIRED) Whether to generate an API report.
105
- */
106
- "enabled": true
107
- /**
108
- * The filename for the API report files. It will be combined with "reportFolder" or "reportTempFolder" to produce
109
- * a full file path.
110
- *
111
- * The file extension should be ".api.md", and the string should not contain a path separator such as "\" or "/".
112
- *
113
- * SUPPORTED TOKENS: <packageName>, <unscopedPackageName>
114
- * DEFAULT VALUE: "<unscopedPackageName>.api.md"
115
- */
116
- // "reportFileName": "<unscopedPackageName>.api.md",
117
- /**
118
- * Specifies the folder where the API report file is written. The file name portion is determined by
119
- * the "reportFileName" setting.
120
- *
121
- * The API report file is normally tracked by Git. Changes to it can be used to trigger a branch policy,
122
- * e.g. for an API review.
123
- *
124
- * The path is resolved relative to the folder of the config file that contains the setting; to change this,
125
- * prepend a folder token such as "<projectFolder>".
126
- *
127
- * SUPPORTED TOKENS: <projectFolder>, <packageName>, <unscopedPackageName>
128
- * DEFAULT VALUE: "<projectFolder>/etc/"
129
- */
130
- // "reportFolder": "<projectFolder>/etc/",
131
- /**
132
- * Specifies the folder where the temporary report file is written. The file name portion is determined by
133
- * the "reportFileName" setting.
134
- *
135
- * After the temporary file is written to disk, it is compared with the file in the "reportFolder".
136
- * If they are different, a production build will fail.
137
- *
138
- * The path is resolved relative to the folder of the config file that contains the setting; to change this,
139
- * prepend a folder token such as "<projectFolder>".
140
- *
141
- * SUPPORTED TOKENS: <projectFolder>, <packageName>, <unscopedPackageName>
142
- * DEFAULT VALUE: "<projectFolder>/temp/"
143
- */
144
- // "reportTempFolder": "<projectFolder>/temp/"
145
- },
146
- /**
147
- * Configures how the doc model file (*.api.json) will be generated.
148
- */
149
- "docModel": {
150
- /**
151
- * (REQUIRED) Whether to generate a doc model file.
152
- */
153
- "enabled": true
154
- /**
155
- * The output path for the doc model file. The file extension should be ".api.json".
156
- *
157
- * The path is resolved relative to the folder of the config file that contains the setting; to change this,
158
- * prepend a folder token such as "<projectFolder>".
159
- *
160
- * SUPPORTED TOKENS: <projectFolder>, <packageName>, <unscopedPackageName>
161
- * DEFAULT VALUE: "<projectFolder>/temp/<unscopedPackageName>.api.json"
162
- */
163
- // "apiJsonFilePath": "<projectFolder>/temp/<unscopedPackageName>.api.json"
164
- },
165
- /**
166
- * Configures how the .d.ts rollup file will be generated.
167
- */
168
- "dtsRollup": {
169
- /**
170
- * (REQUIRED) Whether to generate the .d.ts rollup file.
171
- */
172
- "enabled": true
173
- /**
174
- * Specifies the output path for a .d.ts rollup file to be generated without any trimming.
175
- * This file will include all declarations that are exported by the main entry point.
176
- *
177
- * If the path is an empty string, then this file will not be written.
178
- *
179
- * The path is resolved relative to the folder of the config file that contains the setting; to change this,
180
- * prepend a folder token such as "<projectFolder>".
181
- *
182
- * SUPPORTED TOKENS: <projectFolder>, <packageName>, <unscopedPackageName>
183
- * DEFAULT VALUE: "<projectFolder>/dist/<unscopedPackageName>.d.ts"
184
- */
185
- // "untrimmedFilePath": "<projectFolder>/dist/<unscopedPackageName>.d.ts",
186
- /**
187
- * Specifies the output path for a .d.ts rollup file to be generated with trimming for a "beta" release.
188
- * This file will include only declarations that are marked as "@public" or "@beta".
189
- *
190
- * The path is resolved relative to the folder of the config file that contains the setting; to change this,
191
- * prepend a folder token such as "<projectFolder>".
192
- *
193
- * SUPPORTED TOKENS: <projectFolder>, <packageName>, <unscopedPackageName>
194
- * DEFAULT VALUE: ""
195
- */
196
- // "betaTrimmedFilePath": "<projectFolder>/dist/<unscopedPackageName>-beta.d.ts",
197
- /**
198
- * Specifies the output path for a .d.ts rollup file to be generated with trimming for a "public" release.
199
- * This file will include only declarations that are marked as "@public".
200
- *
201
- * If the path is an empty string, then this file will not be written.
202
- *
203
- * The path is resolved relative to the folder of the config file that contains the setting; to change this,
204
- * prepend a folder token such as "<projectFolder>".
205
- *
206
- * SUPPORTED TOKENS: <projectFolder>, <packageName>, <unscopedPackageName>
207
- * DEFAULT VALUE: ""
208
- */
209
- // "publicTrimmedFilePath": "<projectFolder>/dist/<unscopedPackageName>-public.d.ts",
210
- /**
211
- * When a declaration is trimmed, by default it will be replaced by a code comment such as
212
- * "Excluded from this release type: exampleMember". Set "omitTrimmingComments" to true to remove the
213
- * declaration completely.
214
- *
215
- * DEFAULT VALUE: false
216
- */
217
- // "omitTrimmingComments": true
218
- },
219
- /**
220
- * Configures how the tsdoc-metadata.json file will be generated.
221
- */
222
- "tsdocMetadata": {
223
- /**
224
- * Whether to generate the tsdoc-metadata.json file.
225
- *
226
- * DEFAULT VALUE: true
227
- */
228
- // "enabled": true,
229
- /**
230
- * Specifies where the TSDoc metadata file should be written.
231
- *
232
- * The path is resolved relative to the folder of the config file that contains the setting; to change this,
233
- * prepend a folder token such as "<projectFolder>".
234
- *
235
- * The default value is "<lookup>", which causes the path to be automatically inferred from the "tsdocMetadata",
236
- * "typings" or "main" fields of the project's package.json. If none of these fields are set, the lookup
237
- * falls back to "tsdoc-metadata.json" in the package folder.
238
- *
239
- * SUPPORTED TOKENS: <projectFolder>, <packageName>, <unscopedPackageName>
240
- * DEFAULT VALUE: "<lookup>"
241
- */
242
- // "tsdocMetadataFilePath": "<projectFolder>/dist/tsdoc-metadata.json"
243
- },
244
- /**
245
- * Specifies what type of newlines API Extractor should use when writing output files. By default, the output files
246
- * will be written with Windows-style newlines. To use POSIX-style newlines, specify "lf" instead.
247
- * To use the OS's default newline kind, specify "os".
248
- *
249
- * DEFAULT VALUE: "crlf"
250
- */
251
- // "newlineKind": "crlf",
252
- /**
253
- * Configures how API Extractor reports error and warning messages produced during analysis.
254
- *
255
- * There are three sources of messages: compiler messages, API Extractor messages, and TSDoc messages.
256
- */
257
- "messages": {
258
- /**
259
- * Configures handling of diagnostic messages reported by the TypeScript compiler engine while analyzing
260
- * the input .d.ts files.
261
- *
262
- * TypeScript message identifiers start with "TS" followed by an integer. For example: "TS2551"
263
- *
264
- * DEFAULT VALUE: A single "default" entry with logLevel=warning.
265
- */
266
- "compilerMessageReporting": {
267
- /**
268
- * Configures the default routing for messages that don't match an explicit rule in this table.
269
- */
270
- "default": {
271
- /**
272
- * Specifies whether the message should be written to the the tool's output log. Note that
273
- * the "addToApiReportFile" property may supersede this option.
274
- *
275
- * Possible values: "error", "warning", "none"
276
- *
277
- * Errors cause the build to fail and return a nonzero exit code. Warnings cause a production build fail
278
- * and return a nonzero exit code. For a non-production build (e.g. when "api-extractor run" includes
279
- * the "--local" option), the warning is displayed but the build will not fail.
280
- *
281
- * DEFAULT VALUE: "warning"
282
- */
283
- "logLevel": "warning"
284
- /**
285
- * When addToApiReportFile is true: If API Extractor is configured to write an API report file (.api.md),
286
- * then the message will be written inside that file; otherwise, the message is instead logged according to
287
- * the "logLevel" option.
288
- *
289
- * DEFAULT VALUE: false
290
- */
291
- // "addToApiReportFile": false
292
- }
293
- // "TS2551": {
294
- // "logLevel": "warning",
295
- // "addToApiReportFile": true
296
- // },
297
- //
298
- // . . .
299
- },
300
- /**
301
- * Configures handling of messages reported by API Extractor during its analysis.
302
- *
303
- * API Extractor message identifiers start with "ae-". For example: "ae-extra-release-tag"
304
- *
305
- * DEFAULT VALUE: See api-extractor-defaults.json for the complete table of extractorMessageReporting mappings
306
- */
307
- "extractorMessageReporting": {
308
- "default": {
309
- "logLevel": "warning"
310
- // "addToApiReportFile": false
311
- },
312
- "ae-unresolved-link": {
313
- "logLevel": "none",
314
- "addToApiReportFile": true
315
- }
316
- // "ae-extra-release-tag": {
317
- // "logLevel": "warning",
318
- // "addToApiReportFile": true
319
- // },
320
- //
321
- // . . .
322
- },
323
- /**
324
- * Configures handling of messages reported by the TSDoc parser when analyzing code comments.
325
- *
326
- * TSDoc message identifiers start with "tsdoc-". For example: "tsdoc-link-tag-unescaped-text"
327
- *
328
- * DEFAULT VALUE: A single "default" entry with logLevel=warning.
329
- */
330
- "tsdocMessageReporting": {
331
- "default": {
332
- "logLevel": "warning"
333
- // "addToApiReportFile": false
334
- }
335
- // "tsdoc-link-tag-unescaped-text": {
336
- // "logLevel": "warning",
337
- // "addToApiReportFile": true
338
- // },
339
- //
340
- // . . .
341
- }
342
- }
343
- }
package/config/rig.json DELETED
@@ -1,16 +0,0 @@
1
- // The "rig.json" file directs tools to look for their config files in an external package.
2
- // Documentation for this system: https://www.npmjs.com/package/@rushstack/rig-package
3
- {
4
- "$schema": "https://developer.microsoft.com/json-schemas/rig-package/rig.schema.json",
5
- /**
6
- * (Required) The name of the rig package to inherit from.
7
- * It should be an NPM package name with the "-rig" suffix.
8
- */
9
- "rigPackageName": "@rushstack/heft-node-rig"
10
- /**
11
- * (Optional) Selects a config profile from the rig package. The name must consist of
12
- * lowercase alphanumeric words separated by hyphens, for example "sample-profile".
13
- * If omitted, then the "default" profile will be used."
14
- */
15
- // "rigProfile": "your-profile-name"
16
- }