@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.
- package/LICENSE +21 -0
- package/README.md +5 -0
- package/cspell.json +13 -0
- package/dist/ts-sudoku-lib.d.ts +763 -0
- package/dist/tsdoc-metadata.json +11 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +59 -0
- package/lib/index.js.map +1 -0
- package/lib/packlets/collections/collections.d.ts +55 -0
- package/lib/packlets/collections/collections.d.ts.map +1 -0
- package/lib/packlets/collections/collections.js +137 -0
- package/lib/packlets/collections/collections.js.map +1 -0
- package/lib/packlets/collections/data/puzzles.json +61 -0
- package/lib/packlets/collections/index.d.ts +2 -0
- package/lib/packlets/collections/index.d.ts.map +1 -0
- package/lib/packlets/collections/index.js +41 -0
- package/lib/packlets/collections/index.js.map +1 -0
- package/lib/packlets/common/cage.d.ts +23 -0
- package/lib/packlets/common/cage.d.ts.map +1 -0
- package/lib/packlets/common/cage.js +87 -0
- package/lib/packlets/common/cage.js.map +1 -0
- package/lib/packlets/common/cell.d.ts +34 -0
- package/lib/packlets/common/cell.d.ts.map +1 -0
- package/lib/packlets/common/cell.js +92 -0
- package/lib/packlets/common/cell.js.map +1 -0
- package/lib/packlets/common/common.d.ts +77 -0
- package/lib/packlets/common/common.d.ts.map +1 -0
- package/lib/packlets/common/common.js +49 -0
- package/lib/packlets/common/common.js.map +1 -0
- package/lib/packlets/common/converters.d.ts +24 -0
- package/lib/packlets/common/converters.d.ts.map +1 -0
- package/lib/packlets/common/converters.js +73 -0
- package/lib/packlets/common/converters.js.map +1 -0
- package/lib/packlets/common/ids.d.ts +15 -0
- package/lib/packlets/common/ids.d.ts.map +1 -0
- package/lib/packlets/common/ids.js +107 -0
- package/lib/packlets/common/ids.js.map +1 -0
- package/lib/packlets/common/index.d.ts +12 -0
- package/lib/packlets/common/index.d.ts.map +1 -0
- package/lib/packlets/common/index.js +65 -0
- package/lib/packlets/common/index.js.map +1 -0
- package/lib/packlets/common/model.d.ts +15 -0
- package/lib/packlets/common/model.d.ts.map +1 -0
- package/lib/packlets/common/model.js +26 -0
- package/lib/packlets/common/model.js.map +1 -0
- package/lib/packlets/common/public.d.ts +65 -0
- package/lib/packlets/common/public.d.ts.map +1 -0
- package/lib/packlets/common/public.js +26 -0
- package/lib/packlets/common/public.js.map +1 -0
- package/lib/packlets/common/puzzle.d.ts +99 -0
- package/lib/packlets/common/puzzle.d.ts.map +1 -0
- package/lib/packlets/common/puzzle.js +389 -0
- package/lib/packlets/common/puzzle.js.map +1 -0
- package/lib/packlets/common/puzzleSession.d.ts +214 -0
- package/lib/packlets/common/puzzleSession.d.ts.map +1 -0
- package/lib/packlets/common/puzzleSession.js +361 -0
- package/lib/packlets/common/puzzleSession.js.map +1 -0
- package/lib/packlets/common/puzzleState.d.ts +52 -0
- package/lib/packlets/common/puzzleState.d.ts.map +1 -0
- package/lib/packlets/common/puzzleState.js +100 -0
- package/lib/packlets/common/puzzleState.js.map +1 -0
- package/lib/packlets/file/converters.d.ts +17 -0
- package/lib/packlets/file/converters.d.ts.map +1 -0
- package/lib/packlets/file/converters.js +49 -0
- package/lib/packlets/file/converters.js.map +1 -0
- package/lib/packlets/file/index.d.ts +4 -0
- package/lib/packlets/file/index.d.ts.map +1 -0
- package/lib/packlets/file/index.js +54 -0
- package/lib/packlets/file/index.js.map +1 -0
- package/lib/packlets/file/model.d.ts +9 -0
- package/lib/packlets/file/model.d.ts.map +1 -0
- package/lib/packlets/file/model.js +26 -0
- package/lib/packlets/file/model.js.map +1 -0
- package/lib/packlets/puzzles/anyPuzzle.d.ts +10 -0
- package/lib/packlets/puzzles/anyPuzzle.d.ts.map +1 -0
- package/lib/packlets/puzzles/anyPuzzle.js +51 -0
- package/lib/packlets/puzzles/anyPuzzle.js.map +1 -0
- package/lib/packlets/puzzles/index.d.ts +6 -0
- package/lib/packlets/puzzles/index.d.ts.map +1 -0
- package/lib/packlets/puzzles/index.js +35 -0
- package/lib/packlets/puzzles/index.js.map +1 -0
- package/lib/packlets/puzzles/killerSudokuPuzzle.d.ts +14 -0
- package/lib/packlets/puzzles/killerSudokuPuzzle.d.ts.map +1 -0
- package/lib/packlets/puzzles/killerSudokuPuzzle.js +136 -0
- package/lib/packlets/puzzles/killerSudokuPuzzle.js.map +1 -0
- package/lib/packlets/puzzles/sudokuPuzzle.d.ts +10 -0
- package/lib/packlets/puzzles/sudokuPuzzle.d.ts.map +1 -0
- package/lib/packlets/puzzles/sudokuPuzzle.js +47 -0
- package/lib/packlets/puzzles/sudokuPuzzle.js.map +1 -0
- package/lib/packlets/puzzles/sudokuXPuzzle.d.ts +11 -0
- package/lib/packlets/puzzles/sudokuXPuzzle.d.ts.map +1 -0
- package/lib/packlets/puzzles/sudokuXPuzzle.js +65 -0
- package/lib/packlets/puzzles/sudokuXPuzzle.js.map +1 -0
- package/package.json +70 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"puzzleSession.js","sourceRoot":"","sources":["../../../src/packlets/common/puzzleSession.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;;;AAEH,4CAAqE;AACrE,iCAA8B;AAC9B,iCAA8B;AAE9B,+BAA4B;AAS5B;;;GAGG;AACH,MAAa,aAAa;IAWxB;;OAEG;IACH,YAAsB,MAAc;QAClC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,YAAY,CAAC;QACjC,IAAI,CAAC,SAAS,GAAG,CAAC,CAAC;QACnB,IAAI,CAAC,SAAS,GAAG,CAAC,CAAC;QACnB,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;IACnB,CAAC;IAED;;OAEG;IACH,IAAW,EAAE;QACX,OAAO,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,IAAW,WAAW;QACpB,OA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GAAG,IAAI,CAAC,SAAS,CAAC;IAClC,CAAC;IAEO,KAAK,CAAC,IAAoB;QAChC,IAAI,IAAI,YAAY,WAAI,EAAE;YACxB,OAAO,IAAI,CAAC;SACb;QACD,OAAO,SAAG,CAAC,MAAM,CAAC,IAAI,CAAC;aACpB,SAAS,CAAC,CAAC,EAAE,EAAE,EAAE;YAChB,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QAClC,CAAC,CAAC;aACD,SAAS,EAAE,CAAC;IACjB,CAAC;IAEO,KAAK,CAAC,IAAiC;QAC7C,IAAI,IAAI,YAAY,WAAI,EAAE;YACxB,OAAO,IAAI,CAAC;SACb;QACD,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,IAA2B,CAAC,CAAC,SAAS,EAAE,CAAC;IACvE,CAAC;CACF;AArXD,sCAqXC","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, fail, succeed } from '@fgv/ts-utils';\nimport { Cage } from './cage';\nimport { Cell } from './cell';\nimport { ICellContents, ICellState, IRowColumn, NavigationDirection, NavigationWrap } from './common';\nimport { Ids } from './ids';\nimport { ICage, ICell } from './public';\nimport { ICellUpdate, Puzzle } from './puzzle';\nimport { PuzzleState } from './puzzleState';\n\ninterface IPuzzleStep {\n updates: ICellUpdate[];\n}\n\n/**\n * Represents a single puzzle session, including puzzle, current state and redo/undo.\n * @public\n */\nexport class PuzzleSession {\n /**\n * The current {@link PuzzleState | state} of this puzzle session.\n */\n public state: PuzzleState;\n\n protected readonly _puzzle: Puzzle;\n protected _nextStep: number;\n protected _numSteps: number;\n protected _steps: IPuzzleStep[];\n\n /**\n * @internal\n */\n protected constructor(puzzle: Puzzle) {\n this._puzzle = puzzle;\n this.state = puzzle.initialState;\n this._nextStep = 0;\n this._numSteps = 0;\n this._steps = [];\n }\n\n /**\n * ID of the puzzle being solved.\n */\n public get id(): string | undefined {\n return this._puzzle.id;\n }\n\n /**\n * Description of the puzzle being solved.\n */\n public get description(): string {\n return this._puzzle.description;\n }\n\n /**\n * Number of rows in the puzzle being solved.\n */\n public get numRows(): number {\n return this._puzzle.numRows;\n }\n\n /**\n * Number of columns in the puzzle being solved.\n */\n public get numColumns(): number {\n return this._puzzle.numColumns;\n }\n\n /**\n * The row {@link ICage | cages} in the puzzle being solved.\n */\n public get rows(): ICage[] {\n return this._puzzle.rows;\n }\n\n /**\n * The column {@link ICage | cages} in the puzzle being solved.\n */\n public get cols(): ICage[] {\n return this._puzzle.cols;\n }\n\n /**\n * The section {@link ICage | cages} in the puzzle being solved.\n */\n public get sections(): ICage[] {\n return this._puzzle.sections;\n }\n\n /**\n * All {@link ICage | cages} in the puzzle being solved.\n */\n public get cages(): ICage[] {\n return this._puzzle.cages;\n }\n\n /**\n * The cells {@link ICell | cells} in the puzzle being solved.\n */\n public get cells(): ICell[] {\n return this._puzzle.cells;\n }\n\n /**\n * Index of the next step in this puzzle session.\n */\n public get nextStep(): number {\n return this._nextStep;\n }\n\n /**\n * Number of steps currently elapsed in this puzzle session. Note\n * that after undo, `nextStep` will be less than `numSteps`.\n */\n public get numSteps(): number {\n return this._numSteps;\n }\n\n /***\n * Indicates whether undo is currently possible.\n */\n public get canUndo(): boolean {\n return this._nextStep > 0;\n }\n\n /**\n * Indicates whether redo is currently possible.\n */\n public get canRedo(): boolean {\n return this._nextStep < this._numSteps;\n }\n\n /**\n * Creates a new {@link PuzzleSession | puzzle session} from a supplied\n * {@link Puzzle | puzzle}.\n * @param puzzle - The {@link Puzzle | puzzle} from which the session is to be\n * initialized.\n * @returns `Success` with the requested {@link PuzzleSession | puzzle session},\n * or `Failure` with details if an error occurs.\n */\n public static create(puzzle: Puzzle): Result<PuzzleSession> {\n return captureResult(() => new PuzzleSession(puzzle));\n }\n\n /**\n * Determines if the puzzle is correctly solved.\n * @returns `true` if the puzzle is solved, `false` if the puzzle has\n * empty or invalid cells.\n */\n public checkIsSolved(): boolean {\n return this._puzzle.checkIsSolved(this.state);\n }\n\n /**\n * Determines if the puzzle is valid in its current state.\n * @returns `true` if all non-empty cells in the puzzle are valid,\n * or `false` if any cells are invalid.\n */\n public checkIsValid(): boolean {\n return this._puzzle.checkIsValid(this.state);\n }\n\n /**\n * Gets all of the currently empty {@link ICell | cells} in the puzzle.\n * @returns An array of {@link ICell | ICell} with all empty cells.\n */\n public getEmptyCells(): ICell[] {\n return this._puzzle.getEmptyCells(this.state);\n }\n\n /**\n * Gets all of the currently invalid {@link ICell | cells} in the puzzle.\n * @returns An array of {@link ICell | ICell} with all invalid cells.\n */\n public getInvalidCells(): ICell[] {\n return this._puzzle.getInvalidCells(this.state);\n }\n\n /**\n * Determines if a cell is valid.\n * @param spec - A `string` ({@link CellId | CellId}), {@link IRowColumn | RowColumn} or {@link ICell | ICell}\n * describing the cell to be tested.\n * @returns `true` if the cell value is valid, `false` if the cell value or the cell itself is invalid.\n */\n public cellIsValid(spec: string | IRowColumn | ICell): boolean {\n return this._cell(spec)?.isValid(this.state) === true;\n }\n\n /**\n * Determines if a cell has a value.\n * @param spec - A `string` ({@link CellId | CellId}), {@link IRowColumn | RowColumn} or {@link ICell | ICell}\n * describing the cell to be tested.\n * @returns `true` if the cell has a value, `false` if the cell is empty or the cell itself is invalid.\n */\n public cellHasValue(spec: string | IRowColumn | ICell): boolean {\n return this._cell(spec)?.hasValue(this.state) === true;\n }\n\n /**\n * Determines if supplied value is valid for a specific cell.\n * @param spec - A `string` ({@link CellId | CellId}), {@link IRowColumn | RowColumn} or {@link ICell | ICell}\n * describing the cell to be tested.\n * @param value - The value to be tested.\n * @returns `true` if `value` is valid for the requested cell, `false` if the value or the cell itself is invalid.\n */\n public isValidForCell(spec: string | IRowColumn | ICell, value: number): boolean {\n return this._cell(spec)?.isValidValue(value, this.state) === true;\n }\n\n /**\n * Gets the neighbor for a cell in a given direction using specified wrapping rules.\n * @param spec - A `string` ({@link CellId | CellId}), {@link IRowColumn | RowColumn} or {@link ICell | ICell}\n * describing the cell to be tested.\n * @param direction - The direction of the desired neighbor.\n * @param wrap - Wrapping rules to be applied.\n * @returns `Success` with the requested {@link ICell | cell}, or `Failure` with details if an error occurs.\n */\n public getCellNeighbor(\n spec: string | IRowColumn | ICell,\n direction: NavigationDirection,\n wrap: NavigationWrap\n ): Result<ICell> {\n return this._puzzle.getCellNeighbor(spec, direction, wrap);\n }\n\n /**\n * Gets the {@link ICellContents | contents} for a specified cell.\n * @param spec - A `string` ({@link CellId | CellId}), {@link IRowColumn | RowColumn} or {@link ICell | ICell}\n * describing the cell to be queried.\n * @returns `Success` with the {@link ICell | cell description} and {@link ICellContents | cell contents}, or\n * `Failure` with details if an error occurs.\n */\n public getCellContents(spec: string | IRowColumn): Result<{ cell: ICell; contents: ICellContents }> {\n return this._puzzle.getCellContents(spec, this.state);\n }\n\n /**\n * Updates the value of a cell.\n * @param spec - A `string`, {@link IRowColumn | row and column}, or {@link ICell | cell} identifying\n * the cell to be updated.\n * @param value - A new value for the cell.\n * @returns `Success` with `this` if the update is applied, `Failure` with details if an error occurs.\n */\n public updateCellValue(spec: string | IRowColumn | ICell, value: number | undefined): Result<this> {\n const idResult = Ids.cellId(spec);\n return idResult.onSuccess((id) => {\n const notes: number[] = [];\n const update: ICellState = { id, value, notes };\n return this._puzzle.updateValues(update, this.state).onSuccess((update) => {\n this._addMove(update.cells);\n this.state = update.to;\n return succeed(this);\n });\n });\n }\n\n /**\n * Updates the notes on a cell.\n * @param spec - A `string`, {@link IRowColumn | row and column}, or {@link ICell | cell} identifying\n * the cell to be updated.\n * @param notes - New notes for the cell.\n * @returns `Success` with `this` if the update is applied, `Failure` with details if an error occurs.\n */\n public updateCellNotes(spec: string | IRowColumn | ICell, notes: number[]): Result<this> {\n const idResult = Ids.cellId(spec);\n return idResult.onSuccess((id) => {\n const value = undefined;\n const update: ICellState = { id, value, notes };\n return this._puzzle.updateNotes(update, this.state).onSuccess((update) => {\n this._addMove(update.cells);\n this.state = update.to;\n return succeed(this);\n });\n });\n }\n\n /**\n * Updates value & notes for multiple cells.\n * @param updates - An array of {@link ICellState | cell state} objects, each describing\n * one cell to be updated.\n * @returns `Success` with `this` if the updates are applied, `Failure` with details if\n * an error occurs.\n */\n public updateCells(updates: ICellState[]): Result<this> {\n return this._puzzle.updateContents(updates, this.state).onSuccess((update) => {\n this._addMove(update.cells);\n this.state = update.to;\n return succeed(this);\n });\n }\n\n /**\n * Determines if some {@link ICage | cage} contains a specific value.\n * @param spec - A `string` ({@link CageId | CageId}) or {@link ICage | ICage}\n * indicating the cage to be tested.\n * @param value - The value to be tested.\n * @returns `true` if the cage exists and contains the specified value,\n * `false` otherwise.\n */\n public cageContainsValue(spec: string | ICage, value: number): boolean {\n return this._cage(spec)?.containsValue(value, this.state) === true;\n }\n\n /**\n * Determines the numbers currently present in some cage.\n * @param spec - A `string` ({@link CageId | CageId}) or {@link ICage | ICage}\n * indicating the cage to be tested.\n * @returns A `Set<number>` containing all numbers present in the cage.\n */\n public cageContainedValues(spec: string | ICage): Set<number> {\n return this._cage(spec)?.containedValues(this.state) ?? new Set<number>();\n }\n\n /**\n * Undo a single move in this puzzle session.\n * @returns `Success` with `this` if the undo is applied, or `Failure`\n * with details if an error occurs.\n */\n public undo(): Result<this> {\n if (!this.canUndo) {\n return fail(`nothing to undo`);\n }\n\n return this._puzzle\n .updateContents(\n this._steps[this._nextStep - 1].updates.map((u) => u.from),\n this.state\n )\n .onSuccess((update) => {\n this._nextStep--;\n this.state = update.to;\n return succeed(this);\n });\n }\n\n /**\n * Redo a single move in this puzzle session.\n * @returns `Success` with `this` if the redo is applied, or `Failure`\n * with details if an error occurs.\n */\n public redo(): Result<this> {\n if (!this.canRedo) {\n return fail('nothing to redo');\n }\n return this._puzzle\n .updateContents(\n this._steps[this._nextStep].updates.map((u) => u.to),\n this.state\n )\n .onSuccess((update) => {\n this._nextStep++;\n this.state = update.to;\n return succeed(this);\n });\n }\n\n /**\n * Gets a string representation of this puzzle, one string\n * per row.\n */\n public toStrings(): string[] {\n return this._puzzle.toStrings(this.state);\n }\n\n private _addMove(updates: ICellUpdate[]): void {\n if (this._nextStep < this._steps.length) {\n this._steps[this._nextStep++] = { updates };\n } else {\n this._steps.push({ updates });\n this._nextStep = this._steps.length;\n }\n this._numSteps = this._nextStep;\n }\n\n private _cage(spec: string | ICage): Cage | undefined {\n if (spec instanceof Cage) {\n return spec;\n }\n return Ids.cageId(spec)\n .onSuccess((id) => {\n return this._puzzle.getCage(id);\n })\n .orDefault();\n }\n\n private _cell(spec: string | IRowColumn | ICell): Cell | undefined {\n if (spec instanceof Cell) {\n return spec;\n }\n return this._puzzle.getCell(spec as string | IRowColumn).orDefault();\n }\n}\n"]}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Result } from '@fgv/ts-utils';
|
|
2
|
+
import { CellId, ICellContents, ICellState } from './common';
|
|
3
|
+
/**
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export declare class PuzzleState {
|
|
7
|
+
/**
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
protected readonly _cells: Map<CellId, ICellContents>;
|
|
11
|
+
/**
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
protected constructor(from: Map<CellId, ICellContents>, updates?: ICellState[]);
|
|
15
|
+
/**
|
|
16
|
+
* Constructs a new {@link PuzzleState | PuzzleState}.
|
|
17
|
+
* @param cells - An array of {@link ICellState | CellState} used to initialize the state.
|
|
18
|
+
* @returns The new {@link PuzzleState | PuzzleState}.
|
|
19
|
+
*/
|
|
20
|
+
static create(cells: ICellState[]): Result<PuzzleState>;
|
|
21
|
+
/**
|
|
22
|
+
* Convert {@link ICellContents | CellContents} to `[`{@link CellId | CellId}`,` {@link ICellContents | CellContents}`]`
|
|
23
|
+
* tuple for `Map` construction.
|
|
24
|
+
* @param states - An array of {@link ICellContents | CellContents} to be converted.
|
|
25
|
+
* @returns The corresponding array of `[`{@link CellId | CellId}`,` {@link ICellContents | CellContents}`]`
|
|
26
|
+
* @internal
|
|
27
|
+
*/
|
|
28
|
+
protected static _toEntries(states?: ICellState[]): [CellId, ICellContents][];
|
|
29
|
+
/**
|
|
30
|
+
* Gets the contents of a cell specified by {@link CellId | id}.
|
|
31
|
+
* @param id - The {@link CellId | id} of the cell to be retrieved.
|
|
32
|
+
* @returns A {@link ICellContents | CellContents} with the contents of
|
|
33
|
+
* the requested cell.
|
|
34
|
+
*/
|
|
35
|
+
getCellContents(id: CellId): Result<ICellContents>;
|
|
36
|
+
/**
|
|
37
|
+
* Determines if some cell has an assigned value.
|
|
38
|
+
* @param id - The {@link CellId | id} of the cell to be tested.
|
|
39
|
+
* @returns `true` if the cell has a value, `false` if the cell
|
|
40
|
+
* is empty or invalid.
|
|
41
|
+
*/
|
|
42
|
+
hasValue(id: CellId): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Creates a new {@link PuzzleState | PuzzleState} which corresponds
|
|
45
|
+
* to this state with updates applied.
|
|
46
|
+
* @param updates - An array of {@link ICellState | CellState} to be
|
|
47
|
+
* applied.
|
|
48
|
+
* @returns A new {@link PuzzleState} with updates applied.
|
|
49
|
+
*/
|
|
50
|
+
update(updates: ICellState[]): Result<PuzzleState>;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=puzzleState.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"puzzleState.d.ts","sourceRoot":"","sources":["../../../src/packlets/common/puzzleState.ts"],"names":[],"mappings":"AAwBA,OAAO,EAAE,MAAM,EAAiB,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAE7D;;GAEG;AACH,qBAAa,WAAW;IACtB;;OAEG;IACH,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IAEtD;;OAEG;IACH,SAAS,aAAa,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,EAAE,OAAO,CAAC,EAAE,UAAU,EAAE;IAK9E;;;;OAIG;WACW,MAAM,CAAC,KAAK,EAAE,UAAU,EAAE,GAAG,MAAM,CAAC,WAAW,CAAC;IAI9D;;;;;;OAMG;IACH,SAAS,CAAC,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,EAAE;IAW7E;;;;;OAKG;IACI,eAAe,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC,aAAa,CAAC;IAKzD;;;;;OAKG;IACI,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;IAKpC;;;;;;OAMG;IACI,MAAM,CAAC,OAAO,EAAE,UAAU,EAAE,GAAG,MAAM,CAAC,WAAW,CAAC;CAO1D"}
|
|
@@ -0,0 +1,100 @@
|
|
|
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.PuzzleState = void 0;
|
|
27
|
+
const ts_utils_1 = require("@fgv/ts-utils");
|
|
28
|
+
/**
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
31
|
+
class PuzzleState {
|
|
32
|
+
/**
|
|
33
|
+
* @internal
|
|
34
|
+
*/
|
|
35
|
+
constructor(from, updates) {
|
|
36
|
+
const entries = [...Array.from(from.entries()), ...PuzzleState._toEntries(updates)];
|
|
37
|
+
this._cells = new Map(entries);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Constructs a new {@link PuzzleState | PuzzleState}.
|
|
41
|
+
* @param cells - An array of {@link ICellState | CellState} used to initialize the state.
|
|
42
|
+
* @returns The new {@link PuzzleState | PuzzleState}.
|
|
43
|
+
*/
|
|
44
|
+
static create(cells) {
|
|
45
|
+
return (0, ts_utils_1.succeed)(new PuzzleState(new Map(), cells));
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Convert {@link ICellContents | CellContents} to `[`{@link CellId | CellId}`,` {@link ICellContents | CellContents}`]`
|
|
49
|
+
* tuple for `Map` construction.
|
|
50
|
+
* @param states - An array of {@link ICellContents | CellContents} to be converted.
|
|
51
|
+
* @returns The corresponding array of `[`{@link CellId | CellId}`,` {@link ICellContents | CellContents}`]`
|
|
52
|
+
* @internal
|
|
53
|
+
*/
|
|
54
|
+
static _toEntries(states) {
|
|
55
|
+
/* c8 ignore next 3 - defense in depth */
|
|
56
|
+
if (!states) {
|
|
57
|
+
return [];
|
|
58
|
+
}
|
|
59
|
+
return states.map((state) => {
|
|
60
|
+
const { id, value, notes } = state;
|
|
61
|
+
return [id, { value, notes }];
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Gets the contents of a cell specified by {@link CellId | id}.
|
|
66
|
+
* @param id - The {@link CellId | id} of the cell to be retrieved.
|
|
67
|
+
* @returns A {@link ICellContents | CellContents} with the contents of
|
|
68
|
+
* the requested cell.
|
|
69
|
+
*/
|
|
70
|
+
getCellContents(id) {
|
|
71
|
+
const cell = this._cells.get(id);
|
|
72
|
+
return cell ? (0, ts_utils_1.succeed)(cell) : (0, ts_utils_1.fail)(`cell ${id} not found`);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Determines if some cell has an assigned value.
|
|
76
|
+
* @param id - The {@link CellId | id} of the cell to be tested.
|
|
77
|
+
* @returns `true` if the cell has a value, `false` if the cell
|
|
78
|
+
* is empty or invalid.
|
|
79
|
+
*/
|
|
80
|
+
hasValue(id) {
|
|
81
|
+
const cell = this._cells.get(id);
|
|
82
|
+
return (cell === null || cell === void 0 ? void 0 : cell.value) !== undefined;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Creates a new {@link PuzzleState | PuzzleState} which corresponds
|
|
86
|
+
* to this state with updates applied.
|
|
87
|
+
* @param updates - An array of {@link ICellState | CellState} to be
|
|
88
|
+
* applied.
|
|
89
|
+
* @returns A new {@link PuzzleState} with updates applied.
|
|
90
|
+
*/
|
|
91
|
+
update(updates) {
|
|
92
|
+
const updated = new PuzzleState(this._cells, updates);
|
|
93
|
+
if (updated._cells.size > this._cells.size) {
|
|
94
|
+
return (0, ts_utils_1.fail)(`update added cells`);
|
|
95
|
+
}
|
|
96
|
+
return (0, ts_utils_1.succeed)(updated);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
exports.PuzzleState = PuzzleState;
|
|
100
|
+
//# sourceMappingURL=puzzleState.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"puzzleState.js","sourceRoot":"","sources":["../../../src/packlets/common/puzzleState.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;;;AAEH,4CAAsD;AAGtD;;GAEG;AACH,MAAa,WAAW;IAMtB;;OAEG;IACH,YAAsB,IAAgC,EAAE,OAAsB;QAC5E,MAAM,OAAO,GAAG,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,EAAE,GAAG,WAAW,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC;QACpF,IAAI,CAAC,MAAM,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC;IACjC,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,MAAM,CAAC,KAAmB;QACtC,OAAO,IAAA,kBAAO,EAAC,IAAI,WAAW,CAAC,IAAI,GAAG,EAAE,EAAE,KAA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":["/*\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, fail, succeed } from '@fgv/ts-utils';\nimport { CellId, ICellContents, ICellState } from './common';\n\n/**\n * @public\n */\nexport class PuzzleState {\n /**\n * @internal\n */\n protected readonly _cells: Map<CellId, ICellContents>;\n\n /**\n * @internal\n */\n protected constructor(from: Map<CellId, ICellContents>, updates?: ICellState[]) {\n const entries = [...Array.from(from.entries()), ...PuzzleState._toEntries(updates)];\n this._cells = new Map(entries);\n }\n\n /**\n * Constructs a new {@link PuzzleState | PuzzleState}.\n * @param cells - An array of {@link ICellState | CellState} used to initialize the state.\n * @returns The new {@link PuzzleState | PuzzleState}.\n */\n public static create(cells: ICellState[]): Result<PuzzleState> {\n return succeed(new PuzzleState(new Map(), cells));\n }\n\n /**\n * Convert {@link ICellContents | CellContents} to `[`{@link CellId | CellId}`,` {@link ICellContents | CellContents}`]`\n * tuple for `Map` construction.\n * @param states - An array of {@link ICellContents | CellContents} to be converted.\n * @returns The corresponding array of `[`{@link CellId | CellId}`,` {@link ICellContents | CellContents}`]`\n * @internal\n */\n protected static _toEntries(states?: ICellState[]): [CellId, ICellContents][] {\n /* c8 ignore next 3 - defense in depth */\n if (!states) {\n return [];\n }\n return states.map((state) => {\n const { id, value, notes } = state;\n return [id, { value, notes }];\n });\n }\n\n /**\n * Gets the contents of a cell specified by {@link CellId | id}.\n * @param id - The {@link CellId | id} of the cell to be retrieved.\n * @returns A {@link ICellContents | CellContents} with the contents of\n * the requested cell.\n */\n public getCellContents(id: CellId): Result<ICellContents> {\n const cell = this._cells.get(id);\n return cell ? succeed(cell) : fail(`cell ${id} not found`);\n }\n\n /**\n * Determines if some cell has an assigned value.\n * @param id - The {@link CellId | id} of the cell to be tested.\n * @returns `true` if the cell has a value, `false` if the cell\n * is empty or invalid.\n */\n public hasValue(id: CellId): boolean {\n const cell = this._cells.get(id);\n return cell?.value !== undefined;\n }\n\n /**\n * Creates a new {@link PuzzleState | PuzzleState} which corresponds\n * to this state with updates applied.\n * @param updates - An array of {@link ICellState | CellState} to be\n * applied.\n * @returns A new {@link PuzzleState} with updates applied.\n */\n public update(updates: ICellState[]): Result<PuzzleState> {\n const updated = new PuzzleState(this._cells, updates);\n if (updated._cells.size > this._cells.size) {\n return fail(`update added cells`);\n }\n return succeed(updated);\n }\n}\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Converter, Result } from '@fgv/ts-utils';
|
|
2
|
+
import { IPuzzlesFile } from './model';
|
|
3
|
+
/**
|
|
4
|
+
* Converts an arbitrary object to a {@link Data.Model.PuzzlesFile | PuzzlesFile}.
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export declare const puzzlesFile: Converter<IPuzzlesFile>;
|
|
8
|
+
/**
|
|
9
|
+
* Loads an arbitrary JSON file and parses it to return a validated
|
|
10
|
+
* {@link Data.Model.PuzzlesFile | PuzzlesFile}.
|
|
11
|
+
* @param path - String path to the file
|
|
12
|
+
* @returns `Success` with the resulting file, or `Failure` with details if an
|
|
13
|
+
* error occurs.
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
export declare function loadJsonPuzzlesFileSync(path: string): Result<IPuzzlesFile>;
|
|
17
|
+
//# sourceMappingURL=converters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"converters.d.ts","sourceRoot":"","sources":["../../../src/packlets/file/converters.ts"],"names":[],"mappings":"AAwBA,OAAO,EAAE,SAAS,EAAc,MAAM,EAAE,MAAM,eAAe,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAKvC;;;GAGG;AACH,eAAO,MAAM,WAAW,EAAE,SAAS,CAAC,YAAY,CAE9C,CAAC;AAEH;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,YAAY,CAAC,CAE1E"}
|
|
@@ -0,0 +1,49 @@
|
|
|
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.loadJsonPuzzlesFileSync = exports.puzzlesFile = void 0;
|
|
27
|
+
const ts_utils_1 = require("@fgv/ts-utils");
|
|
28
|
+
const ts_json_1 = require("@fgv/ts-json");
|
|
29
|
+
const common_1 = require("../common");
|
|
30
|
+
/**
|
|
31
|
+
* Converts an arbitrary object to a {@link Data.Model.PuzzlesFile | PuzzlesFile}.
|
|
32
|
+
* @public
|
|
33
|
+
*/
|
|
34
|
+
exports.puzzlesFile = ts_utils_1.Converters.strictObject({
|
|
35
|
+
puzzles: ts_utils_1.Converters.arrayOf(common_1.Converters.puzzleDescription)
|
|
36
|
+
});
|
|
37
|
+
/**
|
|
38
|
+
* Loads an arbitrary JSON file and parses it to return a validated
|
|
39
|
+
* {@link Data.Model.PuzzlesFile | PuzzlesFile}.
|
|
40
|
+
* @param path - String path to the file
|
|
41
|
+
* @returns `Success` with the resulting file, or `Failure` with details if an
|
|
42
|
+
* error occurs.
|
|
43
|
+
* @public
|
|
44
|
+
*/
|
|
45
|
+
function loadJsonPuzzlesFileSync(path) {
|
|
46
|
+
return ts_json_1.File.convertJsonFileSync(path, exports.puzzlesFile);
|
|
47
|
+
}
|
|
48
|
+
exports.loadJsonPuzzlesFileSync = loadJsonPuzzlesFileSync;
|
|
49
|
+
//# sourceMappingURL=converters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"converters.js","sourceRoot":"","sources":["../../../src/packlets/file/converters.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;;;AAEH,4CAA8D;AAG9D,0CAAoC;AACpC,sCAA2D;AAE3D;;;GAGG;AACU,QAAA,WAAW,GAA4B,qBAAU,CAAC,YAAY,CAAe;IACxF,OAAO,EAAE,qBAAU,CAAC,OAAO,CAAC,mBAAgB,CAAC,iBAAiB,CAAC;CAChE,CAAC,CAAC;AAEH;;;;;;;GAOG;AACH,SAAgB,uBAAuB,CAAC,IAAY;IAClD,OAAO,cAAI,CAAC,mBAAmB,CAAC,IAAI,EAAE,mBAAW,CAAC,CAAC;AACrD,CAAC;AAFD,0DAEC","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 { Converter, Converters, Result } from '@fgv/ts-utils';\nimport { IPuzzlesFile } from './model';\n\nimport { File } from '@fgv/ts-json';\nimport { Converters as CommonConverters } from '../common';\n\n/**\n * Converts an arbitrary object to a {@link Data.Model.PuzzlesFile | PuzzlesFile}.\n * @public\n */\nexport const puzzlesFile: Converter<IPuzzlesFile> = Converters.strictObject<IPuzzlesFile>({\n puzzles: Converters.arrayOf(CommonConverters.puzzleDescription)\n});\n\n/**\n * Loads an arbitrary JSON file and parses it to return a validated\n * {@link Data.Model.PuzzlesFile | PuzzlesFile}.\n * @param path - String path to the file\n * @returns `Success` with the resulting file, or `Failure` with details if an\n * error occurs.\n * @public\n */\nexport function loadJsonPuzzlesFileSync(path: string): Result<IPuzzlesFile> {\n return File.convertJsonFileSync(path, puzzlesFile);\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/packlets/file/index.ts"],"names":[],"mappings":"AAwBA,OAAO,KAAK,UAAU,MAAM,cAAc,CAAC;AAC3C,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AAEjC,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
49
|
+
exports.Model = exports.Converters = void 0;
|
|
50
|
+
const Converters = __importStar(require("./converters"));
|
|
51
|
+
exports.Converters = Converters;
|
|
52
|
+
const Model = __importStar(require("./model"));
|
|
53
|
+
exports.Model = Model;
|
|
54
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/packlets/file/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,yDAA2C;AAGlC,gCAAU;AAFnB,+CAAiC;AAEZ,sBAAK","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 Converters from './converters';\nimport * as Model from './model';\n\nexport { Converters, Model };\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../../src/packlets/file/model.ts"],"names":[],"mappings":"AAwBA,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAE/C;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,kBAAkB,EAAE,CAAC;CAC/B"}
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
//# sourceMappingURL=model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.js","sourceRoot":"","sources":["../../../src/packlets/file/model.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG","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 { IPuzzleDescription } from '../common';\n\n/**\n * Parsed file containing a collection of puzzles.\n * @public\n */\nexport interface IPuzzlesFile {\n puzzles: IPuzzleDescription[];\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Result } from '@fgv/ts-utils';
|
|
2
|
+
import { IPuzzleDescription, Puzzle } from '../common';
|
|
3
|
+
/**
|
|
4
|
+
* Static class to instantiate any puzzle from a {@link Data.Model.PuzzleDescription | puzzle description}.
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
export declare class AnyPuzzle {
|
|
8
|
+
static create(puzzle: IPuzzleDescription): Result<Puzzle>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=anyPuzzle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anyPuzzle.d.ts","sourceRoot":"","sources":["../../../src/packlets/puzzles/anyPuzzle.ts"],"names":[],"mappings":"AAwBA,OAAO,EAAE,MAAM,EAAQ,MAAM,eAAe,CAAC;AAE7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAKvD;;;GAGG;AACH,qBAAa,SAAS;WACN,MAAM,CAAC,MAAM,EAAE,kBAAkB,GAAG,MAAM,CAAC,MAAM,CAAC;CAajE"}
|
|
@@ -0,0 +1,51 @@
|
|
|
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.AnyPuzzle = void 0;
|
|
27
|
+
const ts_utils_1 = require("@fgv/ts-utils");
|
|
28
|
+
const killerSudokuPuzzle_1 = require("./killerSudokuPuzzle");
|
|
29
|
+
const sudokuPuzzle_1 = require("./sudokuPuzzle");
|
|
30
|
+
const sudokuXPuzzle_1 = require("./sudokuXPuzzle");
|
|
31
|
+
/**
|
|
32
|
+
* Static class to instantiate any puzzle from a {@link Data.Model.PuzzleDescription | puzzle description}.
|
|
33
|
+
* @internal
|
|
34
|
+
*/
|
|
35
|
+
class AnyPuzzle {
|
|
36
|
+
static create(puzzle) {
|
|
37
|
+
switch (puzzle.type) {
|
|
38
|
+
case 'sudoku':
|
|
39
|
+
return sudokuPuzzle_1.SudokuPuzzle.create(puzzle);
|
|
40
|
+
case 'sudoku-x':
|
|
41
|
+
return sudokuXPuzzle_1.SudokuXPuzzle.create(puzzle);
|
|
42
|
+
case 'killer-sudoku':
|
|
43
|
+
return killerSudokuPuzzle_1.KillerSudokuPuzzle.create(puzzle);
|
|
44
|
+
/* c8 ignore next 2 */
|
|
45
|
+
default:
|
|
46
|
+
return (0, ts_utils_1.fail)(`Puzzle '${puzzle.description}' unsupported type ${puzzle.type}`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.AnyPuzzle = AnyPuzzle;
|
|
51
|
+
//# sourceMappingURL=anyPuzzle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anyPuzzle.js","sourceRoot":"","sources":["../../../src/packlets/puzzles/anyPuzzle.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;;;AAEH,4CAA6C;AAG7C,6DAA0D;AAC1D,iDAA8C;AAC9C,mDAAgD;AAEhD;;;GAGG;AACH,MAAa,SAAS;IACb,MAAM,CAAC,MAAM,CAAC,MAA0B;QAC7C,QAAQ,MAAM,CAAC,IAAI,EAAE;YACnB,KAAK,QAAQ;gBACX,OAAO,2BAAY,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YACrC,KAAK,UAAU;gBACb,OAAO,6BAAa,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YACtC,KAAK,eAAe;gBAClB,OAAO,uCAAkB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YAC3C,sBAAsB;YACtB;gBACE,OAAO,IAAA,eAAI,EAAC,WAAW,MAAM,CAAC,WAAW,sBAAsB,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;SACjF;IACH,CAAC;CACF;AAdD,8BAcC","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, fail } from '@fgv/ts-utils';\n\nimport { IPuzzleDescription, Puzzle } from '../common';\nimport { KillerSudokuPuzzle } from './killerSudokuPuzzle';\nimport { SudokuPuzzle } from './sudokuPuzzle';\nimport { SudokuXPuzzle } from './sudokuXPuzzle';\n\n/**\n * Static class to instantiate any puzzle from a {@link Data.Model.PuzzleDescription | puzzle description}.\n * @internal\n */\nexport class AnyPuzzle {\n public static create(puzzle: IPuzzleDescription): Result<Puzzle> {\n switch (puzzle.type) {\n case 'sudoku':\n return SudokuPuzzle.create(puzzle);\n case 'sudoku-x':\n return SudokuXPuzzle.create(puzzle);\n case 'killer-sudoku':\n return KillerSudokuPuzzle.create(puzzle);\n /* c8 ignore next 2 */\n default:\n return fail(`Puzzle '${puzzle.description}' unsupported type ${puzzle.type}`);\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { AnyPuzzle as Any } from './anyPuzzle';
|
|
2
|
+
import { KillerSudokuPuzzle as Killer } from './killerSudokuPuzzle';
|
|
3
|
+
import { SudokuPuzzle as Sudoku } from './sudokuPuzzle';
|
|
4
|
+
import { SudokuXPuzzle as SudokuX } from './sudokuXPuzzle';
|
|
5
|
+
export { Any, Killer, Sudoku, SudokuX };
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/packlets/puzzles/index.ts"],"names":[],"mappings":"AAwBA,OAAO,EAAE,SAAS,IAAI,GAAG,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,kBAAkB,IAAI,MAAM,EAAE,MAAM,sBAAsB,CAAC;AACpE,OAAO,EAAE,YAAY,IAAI,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,aAAa,IAAI,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE3D,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
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.SudokuX = exports.Sudoku = exports.Killer = exports.Any = void 0;
|
|
27
|
+
const anyPuzzle_1 = require("./anyPuzzle");
|
|
28
|
+
Object.defineProperty(exports, "Any", { enumerable: true, get: function () { return anyPuzzle_1.AnyPuzzle; } });
|
|
29
|
+
const killerSudokuPuzzle_1 = require("./killerSudokuPuzzle");
|
|
30
|
+
Object.defineProperty(exports, "Killer", { enumerable: true, get: function () { return killerSudokuPuzzle_1.KillerSudokuPuzzle; } });
|
|
31
|
+
const sudokuPuzzle_1 = require("./sudokuPuzzle");
|
|
32
|
+
Object.defineProperty(exports, "Sudoku", { enumerable: true, get: function () { return sudokuPuzzle_1.SudokuPuzzle; } });
|
|
33
|
+
const sudokuXPuzzle_1 = require("./sudokuXPuzzle");
|
|
34
|
+
Object.defineProperty(exports, "SudokuX", { enumerable: true, get: function () { return sudokuXPuzzle_1.SudokuXPuzzle; } });
|
|
35
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/packlets/puzzles/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;;;AAEH,2CAA+C;AAKtC,oFALa,qBAAG,OAKb;AAJZ,6DAAoE;AAItD,uFAJiB,uCAAM,OAIjB;AAHpB,iDAAwD;AAGlC,uFAHG,2BAAM,OAGH;AAF5B,mDAA2D;AAE7B,wFAFJ,6BAAO,OAEI","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 { AnyPuzzle as Any } from './anyPuzzle';\nimport { KillerSudokuPuzzle as Killer } from './killerSudokuPuzzle';\nimport { SudokuPuzzle as Sudoku } from './sudokuPuzzle';\nimport { SudokuXPuzzle as SudokuX } from './sudokuXPuzzle';\n\nexport { Any, Killer, Sudoku, SudokuX };\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Result } from '@fgv/ts-utils';
|
|
2
|
+
import { IPuzzleDescription, Puzzle } from '../common';
|
|
3
|
+
/**
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export declare class KillerSudokuPuzzle extends Puzzle {
|
|
7
|
+
private constructor();
|
|
8
|
+
static create(desc: IPuzzleDescription): Result<Puzzle>;
|
|
9
|
+
private static _getKillerCages;
|
|
10
|
+
private static _getCageCells;
|
|
11
|
+
private static _getCages;
|
|
12
|
+
private static _getKillerCells;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=killerSudokuPuzzle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"killerSudokuPuzzle.d.ts","sourceRoot":"","sources":["../../../src/packlets/puzzles/killerSudokuPuzzle.ts"],"names":[],"mappings":"AAwBA,OAAO,EAAE,MAAM,EAAgC,MAAM,eAAe,CAAC;AACrE,OAAO,EAAwB,kBAAkB,EAAO,MAAM,EAAoB,MAAM,WAAW,CAAC;AAIpG;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,MAAM;IAC5C,OAAO;WAIO,MAAM,CAAC,IAAI,EAAE,kBAAkB,GAAG,MAAM,CAAC,MAAM,CAAC;IAmB9D,OAAO,CAAC,MAAM,CAAC,eAAe;IAa9B,OAAO,CAAC,MAAM,CAAC,aAAa;IAuB5B,OAAO,CAAC,MAAM,CAAC,SAAS;IAuCxB,OAAO,CAAC,MAAM,CAAC,eAAe;CAmB/B"}
|