@fgv/ts-sudoku-lib 5.0.0-21 → 5.0.0-23

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.
@@ -1,98 +0,0 @@
1
- /*
2
- * MIT License
3
- *
4
- * Copyright (c) 2023 Erik Fortune
5
- *
6
- * Permission is hereby granted, free of charge, to any person obtaining a copy
7
- * of this software and associated documentation files (the "Software"), to deal
8
- * in the Software without restriction, including without limitation the rights
9
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- * copies of the Software, and to permit persons to whom the Software is
11
- * furnished to do so, subject to the following conditions:
12
- *
13
- * The above copyright notice and this permission notice shall be included in all
14
- * copies or substantial portions of the Software.
15
- *
16
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- * SOFTWARE.
23
- */
24
-
25
- import { Result, fail, succeed } from '@fgv/ts-utils';
26
- import { CageId, CellId, IRowColumn } from './common';
27
- import * as Converters from './converters';
28
- import { ICage, ICell } from './public';
29
-
30
- const firstRowIdChar: number = 'A'.charCodeAt(0);
31
- const firstColIdChar: number = '1'.charCodeAt(0);
32
-
33
- function isRowColumn(from: unknown): from is IRowColumn {
34
- return typeof from === 'object' && from !== null && 'row' in from && `col` in from;
35
- }
36
-
37
- /**
38
- * @public
39
- */
40
- export class Ids {
41
- public static cageId(from: string | ICage): Result<CageId> {
42
- if (typeof from === 'string') {
43
- return Converters.cageId.convert(from);
44
- }
45
- return succeed(from.id);
46
- }
47
-
48
- public static cellId(spec: string | IRowColumn | ICell): Result<CellId> {
49
- if (isRowColumn(spec)) {
50
- if ('id' in spec) {
51
- return succeed(spec.id);
52
- }
53
- const row = String.fromCharCode(firstRowIdChar + spec.row);
54
- const col = String.fromCharCode(firstColIdChar + spec.col);
55
- return succeed(`${row}${col}` as CellId);
56
- }
57
- return Converters.cellId.convert(spec);
58
- }
59
-
60
- public static rowCageId(row: number): CageId {
61
- return `R${String.fromCharCode(firstRowIdChar + row)}` as CageId;
62
- }
63
-
64
- public static columnCageId(col: number): CageId {
65
- return `C${String.fromCharCode(firstColIdChar + col)}` as CageId;
66
- }
67
-
68
- public static sectionCageId(row: number, col: number): CageId {
69
- row = Math.floor(row / 3) * 3;
70
- col = Math.floor(col / 3) * 3;
71
- return `S${String.fromCharCode(firstRowIdChar + row)}${String.fromCharCode(
72
- firstColIdChar + col
73
- )}` as CageId;
74
- }
75
-
76
- public static cellIds(
77
- firstRow: number,
78
- numRows: number,
79
- firstCol: number,
80
- numCols: number
81
- ): Result<CellId[]> {
82
- const cellIds: CellId[] = [];
83
- for (let row = firstRow; row < firstRow + numRows; row++) {
84
- for (let col = firstCol; col < firstCol + numCols; col++) {
85
- const result = this.cellId({ row, col }).onSuccess((id) => {
86
- cellIds.push(id);
87
- return succeed(id);
88
- });
89
-
90
- /* c8 ignore next 3 - defense in depth should not happen */
91
- if (result.isFailure()) {
92
- return fail(result.message);
93
- }
94
- }
95
- }
96
- return succeed(cellIds);
97
- }
98
- }
@@ -1,37 +0,0 @@
1
- /*
2
- * MIT License
3
- *
4
- * Copyright (c) 2023 Erik Fortune
5
- *
6
- * Permission is hereby granted, free of charge, to any person obtaining a copy
7
- * of this software and associated documentation files (the "Software"), to deal
8
- * in the Software without restriction, including without limitation the rights
9
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- * copies of the Software, and to permit persons to whom the Software is
11
- * furnished to do so, subject to the following conditions:
12
- *
13
- * The above copyright notice and this permission notice shall be included in all
14
- * copies or substantial portions of the Software.
15
- *
16
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- * SOFTWARE.
23
- */
24
-
25
- import * as Converters from './converters';
26
-
27
- export * from './cage';
28
- export * from './cell';
29
- export * from './common';
30
- export { Ids } from './ids';
31
- export * from './model';
32
- export * from './public';
33
- export * from './puzzle';
34
- export * from './puzzleSession';
35
- export * from './puzzleState';
36
-
37
- export { Converters };
@@ -1,39 +0,0 @@
1
- /*
2
- * MIT License
3
- *
4
- * Copyright (c) 2023 Erik Fortune
5
- *
6
- * Permission is hereby granted, free of charge, to any person obtaining a copy
7
- * of this software and associated documentation files (the "Software"), to deal
8
- * in the Software without restriction, including without limitation the rights
9
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- * copies of the Software, and to permit persons to whom the Software is
11
- * furnished to do so, subject to the following conditions:
12
- *
13
- * The above copyright notice and this permission notice shall be included in all
14
- * copies or substantial portions of the Software.
15
- *
16
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- * SOFTWARE.
23
- */
24
-
25
- import { PuzzleType } from './common';
26
-
27
- /**
28
- * Description of a single puzzle.
29
- * @public
30
- */
31
- export interface IPuzzleDescription {
32
- id?: string;
33
- description: string;
34
- type: PuzzleType;
35
- level: number;
36
- rows: number;
37
- cols: number;
38
- cells: string;
39
- }
@@ -1,100 +0,0 @@
1
- /*
2
- * MIT License
3
- *
4
- * Copyright (c) 2023 Erik Fortune
5
- *
6
- * Permission is hereby granted, free of charge, to any person obtaining a copy
7
- * of this software and associated documentation files (the "Software"), to deal
8
- * in the Software without restriction, including without limitation the rights
9
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- * copies of the Software, and to permit persons to whom the Software is
11
- * furnished to do so, subject to the following conditions:
12
- *
13
- * The above copyright notice and this permission notice shall be included in all
14
- * copies or substantial portions of the Software.
15
- *
16
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- * SOFTWARE.
23
- */
24
-
25
- import { CageId, CageType, CellId } from './common';
26
-
27
- /**
28
- * Describes the structure of a single cage in a {@link PuzzleSession | puzzle}.
29
- * Does not describe state.
30
- * @public
31
- */
32
- export interface ICage {
33
- /**
34
- * Unique identifier for the cage.
35
- */
36
- readonly id: CageId;
37
-
38
- /**
39
- * The {@link CageType | type} of the cage.
40
- */
41
- readonly cageType: CageType;
42
-
43
- /**
44
- * The expected sum of all cells in the cage.
45
- */
46
- readonly total: number;
47
-
48
- /**
49
- * The number of cells in the cage.
50
- */
51
- readonly numCells: number;
52
-
53
- /**
54
- * The identity of each cell in the cage.
55
- */
56
- readonly cellIds: CellId[];
57
-
58
- /**
59
- * Determines if a supplied cell is present in the cage.
60
- * @param id - the identifier to be searched.
61
- */
62
- containsCell(id: CellId): boolean;
63
- }
64
-
65
- /**
66
- * Describes the structure of a single cell in a {@link PuzzleSession | puzzle}.
67
- * Does not describe state.
68
- * @public
69
- */
70
- export interface ICell {
71
- /**
72
- * Unique identifier for the cell.
73
- */
74
- readonly id: CellId;
75
-
76
- /**
77
- * Row number of the cell.
78
- */
79
- readonly row: number;
80
-
81
- /**
82
- * Column number of the cell.
83
- */
84
- readonly col: number;
85
-
86
- /**
87
- * All of the {@Link ICage | cages} to which this cell belongs.
88
- */
89
- readonly cages: readonly ICage[];
90
-
91
- /**
92
- * Indicates whether this cell is a given value (immutable).
93
- */
94
- readonly immutable: boolean;
95
-
96
- /**
97
- * Given value of this cell, or `undefined` if the cell is not immutable.
98
- */
99
- readonly immutableValue?: number;
100
- }