@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,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.35.2"
9
+ }
10
+ ]
11
+ }
package/lib/index.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ import * as File from './packlets/file';
2
+ import * as Puzzles from './packlets/puzzles';
3
+ export * from './packlets/collections';
4
+ export * from './packlets/common';
5
+ export { File, Puzzles };
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAwBA,OAAO,KAAK,IAAI,MAAM,iBAAiB,CAAC;AACxC,OAAO,KAAK,OAAO,MAAM,oBAAoB,CAAC;AAE9C,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC"}
package/lib/index.js ADDED
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ /*
3
+ * MIT License
4
+ *
5
+ * Copyright (c) 2023 Erik Fortune
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
26
+ if (k2 === undefined) k2 = k;
27
+ var desc = Object.getOwnPropertyDescriptor(m, k);
28
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
29
+ desc = { enumerable: true, get: function() { return m[k]; } };
30
+ }
31
+ Object.defineProperty(o, k2, desc);
32
+ }) : (function(o, m, k, k2) {
33
+ if (k2 === undefined) k2 = k;
34
+ o[k2] = m[k];
35
+ }));
36
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
37
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
38
+ }) : function(o, v) {
39
+ o["default"] = v;
40
+ });
41
+ var __importStar = (this && this.__importStar) || function (mod) {
42
+ if (mod && mod.__esModule) return mod;
43
+ var result = {};
44
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
45
+ __setModuleDefault(result, mod);
46
+ return result;
47
+ };
48
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
49
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
50
+ };
51
+ Object.defineProperty(exports, "__esModule", { value: true });
52
+ exports.Puzzles = exports.File = void 0;
53
+ const File = __importStar(require("./packlets/file"));
54
+ exports.File = File;
55
+ const Puzzles = __importStar(require("./packlets/puzzles"));
56
+ exports.Puzzles = Puzzles;
57
+ __exportStar(require("./packlets/collections"), exports);
58
+ __exportStar(require("./packlets/common"), exports);
59
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,sDAAwC;AAK/B,oBAAI;AAJb,4DAA8C;AAI/B,0BAAO;AAFtB,yDAAuC;AACvC,oDAAkC","sourcesContent":["/*\n * MIT License\n *\n * Copyright (c) 2023 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport * as File from './packlets/file';\nimport * as Puzzles from './packlets/puzzles';\n\nexport * from './packlets/collections';\nexport * from './packlets/common';\nexport { File, Puzzles };\n"]}
@@ -0,0 +1,55 @@
1
+ import * as FileData from '../file';
2
+ import { Result } from '@fgv/ts-utils';
3
+ import { IPuzzleDescription, PuzzleSession } from '../common';
4
+ /**
5
+ * A collection of puzzles of various types.
6
+ * @public
7
+ */
8
+ export declare class PuzzleCollection {
9
+ /**
10
+ * All puzzles in the collection.
11
+ */
12
+ readonly puzzles: readonly IPuzzleDescription[];
13
+ private readonly _byId;
14
+ private constructor();
15
+ /**
16
+ * Creates a new puzzle from a loaded {@link FileData.Model.IPuzzlesFile | PuzzlesFile}
17
+ * @param from - The {@link FileData.Model.IPuzzlesFile | puzzles file} to be loaded.
18
+ * @returns `Success` with the resulting {@link PuzzleCollection | PuzzleCollection}
19
+ * or `Failure` with details if an error occurs.
20
+ */
21
+ static create(from: FileData.Model.IPuzzlesFile): Result<PuzzleCollection>;
22
+ /**
23
+ * Creates a new puzzle from a JSON file.
24
+ * @param path - path to the JSON file to be loaded.
25
+ * @returns `Success` with the resulting {@link PuzzleCollection | PuzzleCollection}
26
+ * or `Failure` with details if an error occurs.
27
+ */
28
+ static load(path: string): Result<PuzzleCollection>;
29
+ /**
30
+ * Gets a puzzle by id from this collection.
31
+ * @param id - The string ID of the puzzle to be returned.
32
+ * @returns `Success` with the requested {@link PuzzleSession | puzzle}, or
33
+ * `Failure` with details if an error occurs.
34
+ */
35
+ getPuzzle(id: string): Result<PuzzleSession>;
36
+ /**
37
+ * Gets a puzzle by id from this collection.
38
+ * @param id - The string ID of the puzzle to be returned.
39
+ * @returns `Success` with the requested {@link PuzzleSession | puzzle}, or
40
+ * `Failure` with details if an error occurs.
41
+ */
42
+ getDescription(id: string): Result<IPuzzleDescription>;
43
+ }
44
+ /**
45
+ * Get well-known {@link PuzzleCollection | puzzle collections}.
46
+ * @public
47
+ */
48
+ export declare class PuzzleCollections {
49
+ private static _default;
50
+ /**
51
+ * The default {@link PuzzleCollection | puzzle collection}.
52
+ */
53
+ static get default(): PuzzleCollection;
54
+ }
55
+ //# sourceMappingURL=collections.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collections.d.ts","sourceRoot":"","sources":["../../../src/packlets/collections/collections.ts"],"names":[],"mappings":"AAwBA,OAAO,KAAK,QAAQ,MAAM,SAAS,CAAC;AAGpC,OAAO,EAAE,MAAM,EAAgC,MAAM,eAAe,CAAC;AAErE,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAG9D;;;GAGG;AACH,qBAAa,gBAAgB;IAC3B;;OAEG;IACH,SAAgB,OAAO,EAAE,SAAS,kBAAkB,EAAE,CAAC;IAEvD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAkC;IAExD,OAAO;IASP;;;;;OAKG;WACW,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,KAAK,CAAC,YAAY,GAAG,MAAM,CAAC,gBAAgB,CAAC;IAIjF;;;;;OAKG;WACW,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,gBAAgB,CAAC;IAI1D;;;;;OAKG;IACI,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC,aAAa,CAAC;IAUnD;;;;;OAKG;IACI,cAAc,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC,kBAAkB,CAAC;CAO9D;AAED;;;GAGG;AACH,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAA2C;IAElE;;OAEG;IACH,WAAkB,OAAO,IAAI,gBAAgB,CAQ5C;CACF"}
@@ -0,0 +1,137 @@
1
+ "use strict";
2
+ /*
3
+ * MIT License
4
+ *
5
+ * Copyright (c) 2023 Erik Fortune
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
26
+ if (k2 === undefined) k2 = k;
27
+ var desc = Object.getOwnPropertyDescriptor(m, k);
28
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
29
+ desc = { enumerable: true, get: function() { return m[k]; } };
30
+ }
31
+ Object.defineProperty(o, k2, desc);
32
+ }) : (function(o, m, k, k2) {
33
+ if (k2 === undefined) k2 = k;
34
+ o[k2] = m[k];
35
+ }));
36
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
37
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
38
+ }) : function(o, v) {
39
+ o["default"] = v;
40
+ });
41
+ var __importStar = (this && this.__importStar) || function (mod) {
42
+ if (mod && mod.__esModule) return mod;
43
+ var result = {};
44
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
45
+ __setModuleDefault(result, mod);
46
+ return result;
47
+ };
48
+ var __importDefault = (this && this.__importDefault) || function (mod) {
49
+ return (mod && mod.__esModule) ? mod : { "default": mod };
50
+ };
51
+ Object.defineProperty(exports, "__esModule", { value: true });
52
+ exports.PuzzleCollections = exports.PuzzleCollection = void 0;
53
+ const FileData = __importStar(require("../file"));
54
+ const Puzzles = __importStar(require("../puzzles"));
55
+ const ts_utils_1 = require("@fgv/ts-utils");
56
+ const common_1 = require("../common");
57
+ const puzzles_json_1 = __importDefault(require("./data/puzzles.json"));
58
+ /**
59
+ * A collection of puzzles of various types.
60
+ * @public
61
+ */
62
+ class PuzzleCollection {
63
+ constructor(puzzles) {
64
+ this.puzzles = puzzles.puzzles;
65
+ this._byId = new Map(this.puzzles
66
+ .map((p) => [p.id, p])
67
+ .filter((p) => p !== undefined));
68
+ }
69
+ /**
70
+ * Creates a new puzzle from a loaded {@link FileData.Model.IPuzzlesFile | PuzzlesFile}
71
+ * @param from - The {@link FileData.Model.IPuzzlesFile | puzzles file} to be loaded.
72
+ * @returns `Success` with the resulting {@link PuzzleCollection | PuzzleCollection}
73
+ * or `Failure` with details if an error occurs.
74
+ */
75
+ static create(from) {
76
+ return (0, ts_utils_1.captureResult)(() => new PuzzleCollection(from));
77
+ }
78
+ /**
79
+ * Creates a new puzzle from a JSON file.
80
+ * @param path - path to the JSON file to be loaded.
81
+ * @returns `Success` with the resulting {@link PuzzleCollection | PuzzleCollection}
82
+ * or `Failure` with details if an error occurs.
83
+ */
84
+ static load(path) {
85
+ return FileData.Converters.loadJsonPuzzlesFileSync(path).onSuccess(PuzzleCollection.create);
86
+ }
87
+ /**
88
+ * Gets a puzzle by id from this collection.
89
+ * @param id - The string ID of the puzzle to be returned.
90
+ * @returns `Success` with the requested {@link PuzzleSession | puzzle}, or
91
+ * `Failure` with details if an error occurs.
92
+ */
93
+ getPuzzle(id) {
94
+ return this.getDescription(id)
95
+ .onSuccess((desc) => {
96
+ return Puzzles.Any.create(desc);
97
+ })
98
+ .onSuccess((puzzle) => {
99
+ return common_1.PuzzleSession.create(puzzle);
100
+ });
101
+ }
102
+ /**
103
+ * Gets a puzzle by id from this collection.
104
+ * @param id - The string ID of the puzzle to be returned.
105
+ * @returns `Success` with the requested {@link PuzzleSession | puzzle}, or
106
+ * `Failure` with details if an error occurs.
107
+ */
108
+ getDescription(id) {
109
+ const desc = this._byId.get(id);
110
+ if (!desc) {
111
+ return (0, ts_utils_1.fail)(`Puzzle "${id}" not found`);
112
+ }
113
+ return (0, ts_utils_1.succeed)(desc);
114
+ }
115
+ }
116
+ exports.PuzzleCollection = PuzzleCollection;
117
+ /**
118
+ * Get well-known {@link PuzzleCollection | puzzle collections}.
119
+ * @public
120
+ */
121
+ class PuzzleCollections {
122
+ /**
123
+ * The default {@link PuzzleCollection | puzzle collection}.
124
+ */
125
+ static get default() {
126
+ if (!PuzzleCollections._default) {
127
+ PuzzleCollections._default = FileData.Converters.puzzlesFile
128
+ .convert(puzzles_json_1.default)
129
+ .onSuccess(PuzzleCollection.create)
130
+ .orThrow();
131
+ }
132
+ return PuzzleCollections._default;
133
+ }
134
+ }
135
+ exports.PuzzleCollections = PuzzleCollections;
136
+ PuzzleCollections._default = undefined;
137
+ //# sourceMappingURL=collections.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collections.js","sourceRoot":"","sources":["../../../src/packlets/collections/collections.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,kDAAoC;AACpC,oDAAsC;AAEtC,4CAAqE;AAErE,sCAA8D;AAC9D,uEAAiD;AAEjD;;;GAGG;AACH,MAAa,gBAAgB;IAQ3B,YAAoB,OAAoC;QACtD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;QAC/B,IAAI,CAAC,KAAK,GAAG,IAAI,GAAG,CAClB,IAAI,CAAC,OAAO;aACT,GAAG,CAAC,CAAC,CAAC,EAA4C,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;aAC/D,MAAM,CAAC,CAAC,CAAC,EAAqC,EAAE,CAAC,CAAC,KAAK,SAAS,CAAC,CACrE,CAAC;IACJ,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,MAAM,CAAC,IAAiC;QACpD,OAAO,IAAA,wBAAa,EAAC,GAAG,EAAE,CAAC,IAAI,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC;IACzD,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,IAAI,CAAC,IAAY;QAC7B,OAAO,QAAQ,CAAC,UAAU,CAAC,uBAAuB,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAC9F,CAAC;IAED;;;;;OAKG;IACI,SAAS,CAAC,EAAU;QACzB,OAAO,IAAI,CAAC,cAAc,CAAC,EAAE,CAAC;aAC3B,SAAS,CAAC,CAAC,IAAI,EAAE,EAAE;YAClB,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAClC,CAAC,CAAC;aACD,SAAS,CAAC,CAAC,MAAM,EAAE,EAAE;YACpB,OAAO,sBAAa,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACtC,CAAC,CAAC,CAAC;IACP,CAAC;IAED;;;;;OAKG;IACI,cAAc,CAAC,EAAU;QAC9B,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAChC,IAAI,CAAC,IAAI,EAAE;YACT,OAAO,IAAA,eAAI,EAAC,WAAW,EAAE,aAAa,CAAC,CAAC;SACzC;QACD,OAAO,IAAA,kBAAO,EAAC,IAAI,CAAC,CAAC;IACvB,CAAC;CACF;AAlED,4CAkEC;AAED;;;GAGG;AACH,MAAa,iBAAiB;IAG5B;;OAEG;IACI,MAAM,KAAK,OAAO;QACvB,IAAI,CAAC,iBAAiB,CAAC,QAAQ,EAAE;YAC/B,iBAAiB,CAAC,QAAQ,GAAG,QAAQ,CAAC,UAAU,CAAC,WAAW;iBACzD,OAAO,CAAC,sBAAc,CAAC;iBACvB,SAAS,CAAC,gBAAgB,CAAC,MAAM,CAAC;iBAClC,OAAO,EAAE,CAAC;SACd;QACD,OAAO,iBAAiB,CAAC,QAAQ,CAAC;IACpC,CAAC;;AAdH,8CAeC;AAdgB,0BAAQ,GAAiC,SAAS,CAAC","sourcesContent":["/*\n * MIT License\n *\n * Copyright (c) 2023 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport * as FileData from '../file';\nimport * as Puzzles from '../puzzles';\n\nimport { Result, captureResult, fail, succeed } from '@fgv/ts-utils';\n\nimport { IPuzzleDescription, PuzzleSession } from '../common';\nimport DefaultPuzzles from './data/puzzles.json';\n\n/**\n * A collection of puzzles of various types.\n * @public\n */\nexport class PuzzleCollection {\n /**\n * All puzzles in the collection.\n */\n public readonly puzzles: readonly IPuzzleDescription[];\n\n private readonly _byId: Map<string, IPuzzleDescription>;\n\n private constructor(puzzles: FileData.Model.IPuzzlesFile) {\n this.puzzles = puzzles.puzzles;\n this._byId = new Map(\n this.puzzles\n .map((p): [string | undefined, IPuzzleDescription] => [p.id, p])\n .filter((p): p is [string, IPuzzleDescription] => p !== undefined)\n );\n }\n\n /**\n * Creates a new puzzle from a loaded {@link FileData.Model.IPuzzlesFile | PuzzlesFile}\n * @param from - The {@link FileData.Model.IPuzzlesFile | puzzles file} to be loaded.\n * @returns `Success` with the resulting {@link PuzzleCollection | PuzzleCollection}\n * or `Failure` with details if an error occurs.\n */\n public static create(from: FileData.Model.IPuzzlesFile): Result<PuzzleCollection> {\n return captureResult(() => new PuzzleCollection(from));\n }\n\n /**\n * Creates a new puzzle from a JSON file.\n * @param path - path to the JSON file to be loaded.\n * @returns `Success` with the resulting {@link PuzzleCollection | PuzzleCollection}\n * or `Failure` with details if an error occurs.\n */\n public static load(path: string): Result<PuzzleCollection> {\n return FileData.Converters.loadJsonPuzzlesFileSync(path).onSuccess(PuzzleCollection.create);\n }\n\n /**\n * Gets a puzzle by id from this collection.\n * @param id - The string ID of the puzzle to be returned.\n * @returns `Success` with the requested {@link PuzzleSession | puzzle}, or\n * `Failure` with details if an error occurs.\n */\n public getPuzzle(id: string): Result<PuzzleSession> {\n return this.getDescription(id)\n .onSuccess((desc) => {\n return Puzzles.Any.create(desc);\n })\n .onSuccess((puzzle) => {\n return PuzzleSession.create(puzzle);\n });\n }\n\n /**\n * Gets a puzzle by id from this collection.\n * @param id - The string ID of the puzzle to be returned.\n * @returns `Success` with the requested {@link PuzzleSession | puzzle}, or\n * `Failure` with details if an error occurs.\n */\n public getDescription(id: string): Result<IPuzzleDescription> {\n const desc = this._byId.get(id);\n if (!desc) {\n return fail(`Puzzle \"${id}\" not found`);\n }\n return succeed(desc);\n }\n}\n\n/**\n * Get well-known {@link PuzzleCollection | puzzle collections}.\n * @public\n */\nexport class PuzzleCollections {\n private static _default: PuzzleCollection | undefined = undefined;\n\n /**\n * The default {@link PuzzleCollection | puzzle collection}.\n */\n public static get default(): PuzzleCollection {\n if (!PuzzleCollections._default) {\n PuzzleCollections._default = FileData.Converters.puzzlesFile\n .convert(DefaultPuzzles)\n .onSuccess(PuzzleCollection.create)\n .orThrow();\n }\n return PuzzleCollections._default;\n }\n}\n"]}
@@ -0,0 +1,61 @@
1
+ {
2
+ "puzzles": [
3
+ {
4
+ "id": "hidden-pair",
5
+ "description": "hidden pair sample",
6
+ "type": "sudoku",
7
+ "level": 1,
8
+ "rows": 9,
9
+ "cols": 9,
10
+ "cells": [
11
+ ".........",
12
+ "9.46.7...",
13
+ ".768.41..",
14
+ "3.97.1.8.",
15
+ "7.8...3.1",
16
+ ".513.87.2",
17
+ "..75.261.",
18
+ "..54.32.8",
19
+ "........."
20
+ ]
21
+ },
22
+ {
23
+ "id": "almost-done",
24
+ "description": "nearly complete puzzle missing only 1 in cell A1",
25
+ "type": "sudoku",
26
+ "level": 1,
27
+ "rows": 9,
28
+ "cols": 9,
29
+ "cells": ".46728539837549126259316748685297413312684957794153862428965371571832694963471285"
30
+ },
31
+ {
32
+ "id": "sudoku-x-example",
33
+ "description": "sample x-sudoku puzzle",
34
+ "type": "sudoku-x",
35
+ "level": 1,
36
+ "rows": 9,
37
+ "cols": 9,
38
+ "cells": "4.....13....6.1.....7..29...76.....2....3..9.9.1....577...1.6..3...5.7...4......1"
39
+ },
40
+ {
41
+ "id": "killer-insane",
42
+ "description": "Insane (3208329) example from djape.net",
43
+ "type": "killer-sudoku",
44
+ "level": 100,
45
+ "rows": 9,
46
+ "cols": 9,
47
+ "cells": [
48
+ "ABCCCDDDE",
49
+ "ABFFGGGDE",
50
+ "HIJKGGLLL",
51
+ "HIJKMGLNN",
52
+ "HOPPMQQNR",
53
+ "OOSTMUVWR",
54
+ "SSSTTUVWR",
55
+ "XYTTTZZab",
56
+ "XYYYcccab",
57
+ "|A11,B09,C09,D20,E16,F17,G30,H17,I13,J09,K11,L16,M16,N11,O16,P07,Q11,R10,S14,T39,U08,V17,W16,X06,Y26,Z06,a09,b09,c11"
58
+ ]
59
+ }
60
+ ]
61
+ }
@@ -0,0 +1,2 @@
1
+ export * from './collections';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/packlets/collections/index.ts"],"names":[],"mappings":"AAwBA,cAAc,eAAe,CAAC"}
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ /*
3
+ * MIT License
4
+ *
5
+ * Copyright (c) 2023 Erik Fortune
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
26
+ if (k2 === undefined) k2 = k;
27
+ var desc = Object.getOwnPropertyDescriptor(m, k);
28
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
29
+ desc = { enumerable: true, get: function() { return m[k]; } };
30
+ }
31
+ Object.defineProperty(o, k2, desc);
32
+ }) : (function(o, m, k, k2) {
33
+ if (k2 === undefined) k2 = k;
34
+ o[k2] = m[k];
35
+ }));
36
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
37
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
38
+ };
39
+ Object.defineProperty(exports, "__esModule", { value: true });
40
+ __exportStar(require("./collections"), exports);
41
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/packlets/collections/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;;;;;;;;;;;;;;;;AAEH,gDAA8B","sourcesContent":["/*\n * MIT License\n *\n * Copyright (c) 2023 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nexport * from './collections';\n"]}
@@ -0,0 +1,23 @@
1
+ import { Result } from '@fgv/ts-utils';
2
+ import { CageId, CageType, CellId } from './common';
3
+ import { ICage } from './public';
4
+ import { PuzzleState } from './puzzleState';
5
+ /**
6
+ * @internal
7
+ */
8
+ export declare class Cage implements ICage {
9
+ readonly id: CageId;
10
+ readonly cageType: CageType;
11
+ readonly total: number;
12
+ protected readonly _cellIds: CellId[];
13
+ private _values;
14
+ private constructor();
15
+ get cellIds(): CellId[];
16
+ get numCells(): number;
17
+ static create(id: CageId, type: CageType, total: number, cells: CellId[]): Result<Cage>;
18
+ containsCell(id: CellId): boolean;
19
+ containsValue(value: number, state: PuzzleState, ignore?: CellId[]): boolean;
20
+ containedValues(state: PuzzleState): Set<number>;
21
+ toString(state?: PuzzleState): string;
22
+ }
23
+ //# sourceMappingURL=cage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cage.d.ts","sourceRoot":"","sources":["../../../src/packlets/common/cage.ts"],"names":[],"mappings":"AAwBA,OAAO,EAAE,MAAM,EAAiB,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACpD,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACjC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C;;GAEG;AACH,qBAAa,IAAK,YAAW,KAAK;IAChC,SAAgB,EAAE,EAAE,MAAM,CAAC;IAC3B,SAAgB,QAAQ,EAAE,QAAQ,CAAC;IACnC,SAAgB,KAAK,EAAE,MAAM,CAAC;IAE9B,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,CAAC;IACtC,OAAO,CAAC,OAAO,CAAc;IAE7B,OAAO;IAQP,IAAW,OAAO,IAAI,MAAM,EAAE,CAE7B;IAED,IAAW,QAAQ,IAAI,MAAM,CAE5B;WAEa,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC;IAIvF,YAAY,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;IAIjC,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,GAAG,OAAO;IAY5E,eAAe,CAAC,KAAK,EAAE,WAAW,GAAG,GAAG,CAAC,MAAM,CAAC;IAYhD,QAAQ,CAAC,KAAK,CAAC,EAAE,WAAW,GAAG,MAAM;CAS7C"}
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ /*
3
+ * MIT License
4
+ *
5
+ * Copyright (c) 2023 Erik Fortune
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.Cage = void 0;
27
+ const ts_utils_1 = require("@fgv/ts-utils");
28
+ /**
29
+ * @internal
30
+ */
31
+ class Cage {
32
+ constructor(id, type, total, cells) {
33
+ this.id = id;
34
+ this.cageType = type;
35
+ this.total = total;
36
+ this._cellIds = Array.from(cells);
37
+ this._values = new Set();
38
+ }
39
+ get cellIds() {
40
+ return Array.from(this._cellIds);
41
+ }
42
+ get numCells() {
43
+ return this._cellIds.length;
44
+ }
45
+ static create(id, type, total, cells) {
46
+ return (0, ts_utils_1.captureResult)(() => new Cage(id, type, total, cells));
47
+ }
48
+ containsCell(id) {
49
+ return this._cellIds.includes(id);
50
+ }
51
+ containsValue(value, state, ignore) {
52
+ var _a;
53
+ for (const cellId of this._cellIds) {
54
+ if (!(ignore === null || ignore === void 0 ? void 0 : ignore.includes(cellId))) {
55
+ /* c8 ignore next - defense in depth, ? should never happen */
56
+ if (((_a = state.getCellContents(cellId).orDefault()) === null || _a === void 0 ? void 0 : _a.value) === value) {
57
+ return true;
58
+ }
59
+ }
60
+ }
61
+ return false;
62
+ }
63
+ containedValues(state) {
64
+ var _a;
65
+ const values = new Set();
66
+ for (const cellId of this._cellIds) {
67
+ /* c8 ignore next - defense in depth, ? should never happen */
68
+ const value = (_a = state.getCellContents(cellId).orDefault()) === null || _a === void 0 ? void 0 : _a.value;
69
+ if (value !== undefined) {
70
+ values.add(value);
71
+ }
72
+ }
73
+ return values;
74
+ }
75
+ toString(state) {
76
+ return this._cellIds
77
+ .map((id) => {
78
+ var _a;
79
+ /* c8 ignore next - defense in depth, ? should never happen */
80
+ const value = (_a = state === null || state === void 0 ? void 0 : state.getCellContents(id).orDefault()) === null || _a === void 0 ? void 0 : _a.value;
81
+ return value ? String(value) : '.';
82
+ })
83
+ .join('');
84
+ }
85
+ }
86
+ exports.Cage = Cage;
87
+ //# sourceMappingURL=cage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cage.js","sourceRoot":"","sources":["../../../src/packlets/common/cage.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;;;AAEH,4CAAsD;AAKtD;;GAEG;AACH,MAAa,IAAI;IAQf,YAAoB,EAAU,EAAE,IAAc,EAAE,KAAa,EAAE,KAAe;QAC5E,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACrB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAClC,IAAI,CAAC,OAAO,GAAG,IAAI,GAAG,EAAE,CAAC;IAC3B,CAAC;IAED,IAAW,OAAO;QAChB,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACnC,CAAC;IAED,IAAW,QAAQ;QACjB,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;IAC9B,CAAC;IAEM,MAAM,CAAC,MAAM,CAAC,EAAU,EAAE,IAAc,EAAE,KAAa,EAAE,KAAe;QAC7E,OAAO,IAAA,wBAAa,EAAC,GAAG,EAAE,CAAC,IAAI,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;IAC/D,CAAC;IAEM,YAAY,CAAC,EAAU;QAC5B,OAAO,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IACpC,CAAC;IAEM,aAAa,CAAC,KAAa,EAAE,KAAkB,EAAE,MAAiB;;QACvE,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,QAAQ,EAAE;YAClC,IAAI,CAAC,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,QAAQ,CAAC,MAAM,CAAC,CAAA,EAAE;gBAC7B,8DAA8D;gBAC9D,IAAI,CAAA,MAAA,KAAK,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,0CAAE,KAAK,MAAK,KAAK,EAAE;oBAC9D,OAAO,IAAI,CAAC;iBACb;aACF;SACF;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAEM,eAAe,CAAC,KAAkB;;QACvC,MAAM,MAAM,GAAG,IAAI,GAAG,EAAU,CAAC;QACjC,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,QAAQ,EAAE;YAClC,8DAA8D;YAC9D,MAAM,KAAK,GAAG,MAAA,KAAK,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,0CAAE,KAAK,CAAC;YAC/D,IAAI,KAAK,KAAK,SAAS,EAAE;gBACvB,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;aACnB;SACF;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IAEM,QAAQ,CAAC,KAAmB;QACjC,OAAO,IAAI,CAAC,QAAQ;aACjB,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE;;YACV,8DAA8D;YAC9D,MAAM,KAAK,GAAG,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,eAAe,CAAC,EAAE,EAAE,SAAS,EAAE,0CAAE,KAAK,CAAC;YAC5D,OAAO,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;QACrC,CAAC,CAAC;aACD,IAAI,CAAC,EAAE,CAAC,CAAC;IACd,CAAC;CACF;AAjED,oBAiEC","sourcesContent":["/*\n * MIT License\n *\n * Copyright (c) 2023 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { Result, captureResult } from '@fgv/ts-utils';\nimport { CageId, CageType, CellId } from './common';\nimport { ICage } from './public';\nimport { PuzzleState } from './puzzleState';\n\n/**\n * @internal\n */\nexport class Cage implements ICage {\n public readonly id: CageId;\n public readonly cageType: CageType;\n public readonly total: number;\n\n protected readonly _cellIds: CellId[];\n private _values: Set<number>;\n\n private constructor(id: CageId, type: CageType, total: number, cells: CellId[]) {\n this.id = id;\n this.cageType = type;\n this.total = total;\n this._cellIds = Array.from(cells);\n this._values = new Set();\n }\n\n public get cellIds(): CellId[] {\n return Array.from(this._cellIds);\n }\n\n public get numCells(): number {\n return this._cellIds.length;\n }\n\n public static create(id: CageId, type: CageType, total: number, cells: CellId[]): Result<Cage> {\n return captureResult(() => new Cage(id, type, total, cells));\n }\n\n public containsCell(id: CellId): boolean {\n return this._cellIds.includes(id);\n }\n\n public containsValue(value: number, state: PuzzleState, ignore?: CellId[]): boolean {\n for (const cellId of this._cellIds) {\n if (!ignore?.includes(cellId)) {\n /* c8 ignore next - defense in depth, ? should never happen */\n if (state.getCellContents(cellId).orDefault()?.value === value) {\n return true;\n }\n }\n }\n return false;\n }\n\n public containedValues(state: PuzzleState): Set<number> {\n const values = new Set<number>();\n for (const cellId of this._cellIds) {\n /* c8 ignore next - defense in depth, ? should never happen */\n const value = state.getCellContents(cellId).orDefault()?.value;\n if (value !== undefined) {\n values.add(value);\n }\n }\n return values;\n }\n\n public toString(state?: PuzzleState): string {\n return this._cellIds\n .map((id) => {\n /* c8 ignore next - defense in depth, ? should never happen */\n const value = state?.getCellContents(id).orDefault()?.value;\n return value ? String(value) : '.';\n })\n .join('');\n }\n}\n"]}
@@ -0,0 +1,34 @@
1
+ import { Result } from '@fgv/ts-utils';
2
+ import { Cage } from './cage';
3
+ import { CellId, ICellState } from './common';
4
+ import { ICell } from './public';
5
+ import { PuzzleState } from './puzzleState';
6
+ /**
7
+ * @internal
8
+ */
9
+ export interface ICellInit {
10
+ readonly id: CellId;
11
+ readonly row: number;
12
+ readonly col: number;
13
+ readonly immutableValue?: number;
14
+ }
15
+ /**
16
+ * @internal
17
+ */
18
+ export declare class Cell implements ICellInit, ICell {
19
+ readonly id: CellId;
20
+ readonly row: number;
21
+ readonly col: number;
22
+ readonly cages: readonly Cage[];
23
+ readonly immutable: boolean;
24
+ readonly immutableValue?: number;
25
+ constructor(init: ICellInit, cages: readonly Cage[]);
26
+ isValid(state: PuzzleState): boolean;
27
+ hasValue(state: PuzzleState): boolean;
28
+ isValidValue(value: number | undefined, state: PuzzleState): boolean;
29
+ update(value: number | undefined, notes: number[]): Result<ICellState>;
30
+ updateValue(value: number | undefined, state: PuzzleState): Result<ICellState>;
31
+ updateNotes(notes: number[], state: PuzzleState): Result<ICellState>;
32
+ toString(state?: PuzzleState): string;
33
+ }
34
+ //# sourceMappingURL=cell.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cell.d.ts","sourceRoot":"","sources":["../../../src/packlets/common/cell.ts"],"names":[],"mappings":"AAwBA,OAAO,EAAE,MAAM,EAAiB,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,MAAM,EAAiB,UAAU,EAAE,MAAM,UAAU,CAAC;AAC7D,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACjC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;CAClC;AAED;;GAEG;AACH,qBAAa,IAAK,YAAW,SAAS,EAAE,KAAK;IAC3C,SAAgB,EAAE,EAAE,MAAM,CAAC;IAC3B,SAAgB,GAAG,EAAE,MAAM,CAAC;IAC5B,SAAgB,GAAG,EAAE,MAAM,CAAC;IAC5B,SAAgB,KAAK,EAAE,SAAS,IAAI,EAAE,CAAC;IAEvC,SAAgB,SAAS,EAAE,OAAO,CAAC;IACnC,SAAgB,cAAc,CAAC,EAAE,MAAM,CAAC;gBAErB,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,IAAI,EAAE;IASnD,OAAO,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO;IAQpC,QAAQ,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO;IASrC,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,EAAE,KAAK,EAAE,WAAW,GAAG,OAAO;IASpE,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC,UAAU,CAAC;IAWtE,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,EAAE,KAAK,EAAE,WAAW,GAAG,MAAM,CAAC,UAAU,CAAC;IAM9E,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,WAAW,GAAG,MAAM,CAAC,UAAU,CAAC;IAMpE,QAAQ,CAAC,KAAK,CAAC,EAAE,WAAW,GAAG,MAAM;CAK7C"}