@fgv/ts-sudoku-lib 5.1.0-4 → 5.1.0-40
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/dist/index.browser.js.map +1 -0
- package/dist/index.js.map +1 -0
- package/dist/packlets/collections/collections.js +1 -1
- package/dist/packlets/collections/collections.js.map +1 -0
- package/dist/packlets/collections/index.js.map +1 -0
- package/dist/packlets/common/cage.js.map +1 -0
- package/dist/packlets/common/cell.js.map +1 -0
- package/dist/packlets/common/common.js.map +1 -0
- package/dist/packlets/common/converters.js.map +1 -0
- package/dist/packlets/common/ids.js.map +1 -0
- package/dist/packlets/common/index.js.map +1 -0
- package/dist/packlets/common/logging.js.map +1 -0
- package/dist/packlets/common/public.js.map +1 -0
- package/dist/packlets/common/puzzle.js +1 -1
- package/dist/packlets/common/puzzle.js.map +1 -0
- package/dist/packlets/common/puzzleDefinitions.js.map +1 -0
- package/dist/packlets/common/puzzleSession.js.map +1 -0
- package/dist/packlets/common/puzzleState.js.map +1 -0
- package/dist/packlets/files/converters.js.map +1 -0
- package/dist/packlets/files/fileTreeHelpers.js.map +1 -0
- package/dist/packlets/files/filesystem.js.map +1 -0
- package/dist/packlets/files/index.browser.js.map +1 -0
- package/dist/packlets/files/index.js.map +1 -0
- package/dist/packlets/files/model.js.map +1 -0
- package/dist/packlets/hints/baseHintProvider.js.map +1 -0
- package/dist/packlets/hints/explanations.js.map +1 -0
- package/dist/packlets/hints/hiddenSingles.js.map +1 -0
- package/dist/packlets/hints/hintRegistry.js.map +1 -0
- package/dist/packlets/hints/hints.js.map +1 -0
- package/dist/packlets/hints/index.js.map +1 -0
- package/dist/packlets/hints/interfaces.js.map +1 -0
- package/dist/packlets/hints/nakedSingles.js.map +1 -0
- package/dist/packlets/hints/puzzleSessionHints.js.map +1 -0
- package/dist/packlets/hints/types.js.map +1 -0
- package/dist/packlets/puzzles/anyPuzzle.js.map +1 -0
- package/dist/packlets/puzzles/index.js.map +1 -0
- package/dist/packlets/puzzles/internal/combinationCache.js.map +1 -0
- package/dist/packlets/puzzles/internal/combinationGenerator.js.map +1 -0
- package/dist/packlets/puzzles/internal/possibilityAnalyzer.js.map +1 -0
- package/dist/packlets/puzzles/killerCombinations.js.map +1 -0
- package/dist/packlets/puzzles/killerCombinationsTypes.js.map +1 -0
- package/dist/packlets/puzzles/killerSudokuPuzzle.js.map +1 -0
- package/dist/packlets/puzzles/sudokuPuzzle.js.map +1 -0
- package/dist/packlets/puzzles/sudokuXPuzzle.js.map +1 -0
- package/dist/ts-sudoku-lib.d.ts +8 -8
- package/dist/tsdoc-metadata.json +1 -1
- package/lib/index.browser.d.ts.map +1 -0
- package/lib/index.browser.js.map +1 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js.map +1 -0
- package/lib/packlets/collections/collections.d.ts +1 -1
- package/lib/packlets/collections/collections.d.ts.map +1 -0
- package/lib/packlets/collections/collections.js +1 -1
- package/lib/packlets/collections/collections.js.map +1 -0
- package/lib/packlets/collections/index.d.ts.map +1 -0
- package/lib/packlets/collections/index.js.map +1 -0
- package/lib/packlets/common/cage.d.ts.map +1 -0
- package/lib/packlets/common/cage.js.map +1 -0
- package/lib/packlets/common/cell.d.ts.map +1 -0
- package/lib/packlets/common/cell.js.map +1 -0
- package/lib/packlets/common/common.d.ts +5 -5
- package/lib/packlets/common/common.d.ts.map +1 -0
- package/lib/packlets/common/common.js.map +1 -0
- package/lib/packlets/common/converters.d.ts.map +1 -0
- package/lib/packlets/common/converters.js.map +1 -0
- package/lib/packlets/common/ids.d.ts.map +1 -0
- package/lib/packlets/common/ids.js.map +1 -0
- package/lib/packlets/common/index.d.ts.map +1 -0
- package/lib/packlets/common/index.js.map +1 -0
- package/lib/packlets/common/logging.d.ts.map +1 -0
- package/lib/packlets/common/logging.js.map +1 -0
- package/lib/packlets/common/public.d.ts +1 -1
- package/lib/packlets/common/public.d.ts.map +1 -0
- package/lib/packlets/common/public.js.map +1 -0
- package/lib/packlets/common/puzzle.d.ts +1 -1
- package/lib/packlets/common/puzzle.d.ts.map +1 -0
- package/lib/packlets/common/puzzle.js +1 -1
- package/lib/packlets/common/puzzle.js.map +1 -0
- package/lib/packlets/common/puzzleDefinitions.d.ts.map +1 -0
- package/lib/packlets/common/puzzleDefinitions.js.map +1 -0
- package/lib/packlets/common/puzzleSession.d.ts.map +1 -0
- package/lib/packlets/common/puzzleSession.js.map +1 -0
- package/lib/packlets/common/puzzleState.d.ts.map +1 -0
- package/lib/packlets/common/puzzleState.js.map +1 -0
- package/lib/packlets/files/converters.d.ts.map +1 -0
- package/lib/packlets/files/converters.js.map +1 -0
- package/lib/packlets/files/fileTreeHelpers.d.ts.map +1 -0
- package/lib/packlets/files/fileTreeHelpers.js.map +1 -0
- package/lib/packlets/files/filesystem.d.ts.map +1 -0
- package/lib/packlets/files/filesystem.js.map +1 -0
- package/lib/packlets/files/index.browser.d.ts.map +1 -0
- package/lib/packlets/files/index.browser.js.map +1 -0
- package/lib/packlets/files/index.d.ts.map +1 -0
- package/lib/packlets/files/index.js.map +1 -0
- package/lib/packlets/files/model.d.ts.map +1 -0
- package/lib/packlets/files/model.js.map +1 -0
- package/lib/packlets/hints/baseHintProvider.d.ts.map +1 -0
- package/lib/packlets/hints/baseHintProvider.js.map +1 -0
- package/lib/packlets/hints/explanations.d.ts.map +1 -0
- package/lib/packlets/hints/explanations.js.map +1 -0
- package/lib/packlets/hints/hiddenSingles.d.ts.map +1 -0
- package/lib/packlets/hints/hiddenSingles.js.map +1 -0
- package/lib/packlets/hints/hintRegistry.d.ts.map +1 -0
- package/lib/packlets/hints/hintRegistry.js.map +1 -0
- package/lib/packlets/hints/hints.d.ts.map +1 -0
- package/lib/packlets/hints/hints.js.map +1 -0
- package/lib/packlets/hints/index.d.ts.map +1 -0
- package/lib/packlets/hints/index.js.map +1 -0
- package/lib/packlets/hints/interfaces.d.ts.map +1 -0
- package/lib/packlets/hints/interfaces.js.map +1 -0
- package/lib/packlets/hints/nakedSingles.d.ts.map +1 -0
- package/lib/packlets/hints/nakedSingles.js.map +1 -0
- package/lib/packlets/hints/puzzleSessionHints.d.ts.map +1 -0
- package/lib/packlets/hints/puzzleSessionHints.js.map +1 -0
- package/lib/packlets/hints/types.d.ts.map +1 -0
- package/lib/packlets/hints/types.js.map +1 -0
- package/lib/packlets/puzzles/anyPuzzle.d.ts.map +1 -0
- package/lib/packlets/puzzles/anyPuzzle.js.map +1 -0
- package/lib/packlets/puzzles/index.d.ts.map +1 -0
- package/lib/packlets/puzzles/index.js.map +1 -0
- package/lib/packlets/puzzles/internal/combinationCache.d.ts.map +1 -0
- package/lib/packlets/puzzles/internal/combinationCache.js.map +1 -0
- package/lib/packlets/puzzles/internal/combinationGenerator.d.ts.map +1 -0
- package/lib/packlets/puzzles/internal/combinationGenerator.js.map +1 -0
- package/lib/packlets/puzzles/internal/possibilityAnalyzer.d.ts.map +1 -0
- package/lib/packlets/puzzles/internal/possibilityAnalyzer.js.map +1 -0
- package/lib/packlets/puzzles/killerCombinations.d.ts.map +1 -0
- package/lib/packlets/puzzles/killerCombinations.js.map +1 -0
- package/lib/packlets/puzzles/killerCombinationsTypes.d.ts.map +1 -0
- package/lib/packlets/puzzles/killerCombinationsTypes.js.map +1 -0
- package/lib/packlets/puzzles/killerSudokuPuzzle.d.ts.map +1 -0
- package/lib/packlets/puzzles/killerSudokuPuzzle.js.map +1 -0
- package/lib/packlets/puzzles/sudokuPuzzle.d.ts.map +1 -0
- package/lib/packlets/puzzles/sudokuPuzzle.js.map +1 -0
- package/lib/packlets/puzzles/sudokuXPuzzle.d.ts.map +1 -0
- package/lib/packlets/puzzles/sudokuXPuzzle.js.map +1 -0
- package/package.json +7 -7
- package/debug_test.js +0 -88
- package/dist/test/unit/helpers/puzzleBuilders.js +0 -149
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"killerSudokuPuzzle.js","sourceRoot":"","sources":["../../../src/packlets/puzzles/killerSudokuPuzzle.ts"],"names":[],"mappings":";AAAA;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AyB,EAAE,MAAc;QACtE,MAAM,KAAK,GAAa,EAAE,CAAC;QAC3B,KAAK,IAAI,GAAG,GAAG,CAAC,EAAE,GAAG,GAAG,MAAM,CAAC,SAAS,EAAE,GAAG,EAAE,EAAE,CAAC;YAChD,KAAK,IAAI,GAAG,GAAG,CAAC,EAAE,GAAG,GAAG,MAAM,CAAC,YAAY,EAAE,GAAG,EAAE,EAAE,CAAC;gBACnD,MAAM,MAAM,GAAG,YAAG,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;gBAClD,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,MAAM,CAAC,CAAC;gBACzD,IAAI,IAAI,EAAE,CAAC;oBACT,6DAA6D;oBAC7D,IAAI,IAAI,CAAC,KAAK,GAAG,CAAC,IAAI,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC;wBACnD,MAAM,IAAI,KAAK,CAAC,iBAAiB,IAAI,CAAC,KAAK,aAAa,MAAM,EAAE,CAAC,CAAC;oBACpE,CAAC;oBACD,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;gBACjC,CAAC;qBAAM,CAAC;oBACN,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;gBAClB,CAAC;YACH,CAAC;QACH,CAAC;QACD,OAAO,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACxB,CAAC;CACF;AA1HD,gDA0HC","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, CageId, CellId, IPuzzleDefinition, Ids, Puzzle, getCageTotalBounds } from '../common';\n\nconst cageDefFormat: RegExp = /^[A-Za-z][0-9][0-9]$/;\n\n/**\n * @public\n */\nexport class KillerSudokuPuzzle extends Puzzle {\n private constructor(puzzle: IPuzzleDefinition, cages: [CageId, Cage][]) {\n super(puzzle, cages);\n }\n\n public static create(desc: IPuzzleDefinition): Result<Puzzle> {\n /* c8 ignore next 3 */\n if (desc.type !== 'killer-sudoku') {\n return fail(`Puzzle '${desc.description}' unsupported type ${desc.type}`);\n }\n\n return captureResult(() => {\n const { cages, givens } = KillerSudokuPuzzle._getKillerCages(desc);\n const cells = KillerSudokuPuzzle._getKillerCells(desc, givens);\n return new KillerSudokuPuzzle({ ...desc, cells }, cages);\n })\n .onSuccess((puzzle) => {\n return succeed(puzzle);\n })\n .onFailure((message) => {\n return fail(`Failed to load killer puzzle \"${desc.description}\" - ${message}`);\n });\n }\n\n private static _getKillerCages(puzzle: IPuzzleDefinition): { cages: [CageId, Cage][]; givens: Cage[] } {\n const decl = puzzle.cells.split('|');\n /* c8 ignore next 3 - tested but coverage has intermittent issues */\n if (decl.length !== 2) {\n throw new Error(`malformed cells|cages \"${puzzle.cells}\"`);\n }\n\n const cageCells = KillerSudokuPuzzle._getCageCells(puzzle, decl[0]);\n const allCages = KillerSudokuPuzzle._getCages(puzzle, cageCells, decl[1]);\n const cages = allCages.filter(([__id, cage]) => cage.numCells > 1);\n const givens = allCages.filter(([__id, cage]) => cage.numCells === 1).map(([__id, cage]) => cage);\n return { cages, givens };\n }\n\n private static _getCageCells(puzzle: IPuzzleDefinition, mappingDecl: string): Map<string, CellId[]> {\n const cages: Map<string, CellId[]> = new Map();\n const cageMapping = Array.from(mappingDecl);\n\n /* c8 ignore next 5 - defensive coding: protected by validation in puzzleDefinitions.ts */\n if (cageMapping.length !== puzzle.totalRows * puzzle.totalColumns) {\n const expected = puzzle.totalRows * puzzle.totalColumns;\n const got = cageMapping.length;\n throw new Error(`expected ${expected} cell mappings, found ${got}`);\n }\n\n for (let row = 0; row < puzzle.totalRows; row++) {\n for (let col = 0; col < puzzle.totalColumns; col++) {\n const cage = cageMapping.shift()!;\n const cell = Ids.cellId({ row, col }).orThrow();\n const cells = cages.get(cage) ?? [];\n cells.push(cell);\n cages.set(cage, cells);\n }\n }\n\n return cages;\n }\n\n private static _getCages(\n puzzle: IPuzzleDefinition,\n cageCells: Map<string, CellId[]>,\n cagePart: string\n ): [CageId, Cage][] {\n const cages = new Map<CageId, Cage>();\n\n const cageDefs = cagePart.split(',');\n if (cageDefs.length !== cageCells.size) {\n throw new Error(`expected ${cageCells.size} cage sizes, found ${cageDefs.length}`);\n }\n\n for (const def of cageDefs) {\n if (!cageDefFormat.test(def)) {\n throw new Error(`malformed cage spec ${def}`);\n }\n const cage = def.slice(0, 1);\n const cageId = Ids.cageId(`K${cage}`).orThrow();\n\n const total = Number.parseInt(def.slice(1));\n const cells = cageCells.get(cage);\n /* c8 ignore next 3 - should never happen */\n if (!cells) {\n throw new Error(`cage ${cageId} has no cells`);\n }\n // Use the puzzle's maxValue for dynamic validation\n const maxValue = puzzle.maxValue;\n if (cells.length < 1 || cells.length > maxValue) {\n throw new Error(`invalid cell count ${cells.length} for cage ${cageId} (max ${maxValue})`);\n }\n const { min, max } = getCageTotalBounds(cells.length, maxValue);\n if (total < min || total > max) {\n throw new Error(`invalid total ${total} for cage ${cageId} (expected ${min}..${max})`);\n }\n\n cages.set(cageId, Cage.create(cageId, 'killer', total, cells).orThrow());\n }\n\n return Array.from(cages.entries());\n }\n\n private static _getKillerCells(puzzle: IPuzzleDefinition, givens: Cage[]): string {\n const cells: string[] = [];\n for (let row = 0; row < puzzle.totalRows; row++) {\n for (let col = 0; col < puzzle.totalColumns; col++) {\n const cellId = Ids.cellId({ row, col }).orThrow();\n const cage = givens.find((g) => g.cellIds[0] === cellId);\n if (cage) {\n /* c8 ignore next 3 - defense in depth should never happen */\n if (cage.total < 1 || cage.total > puzzle.maxValue) {\n throw new Error(`invalid total ${cage.total} for cell ${cellId}`);\n }\n cells.push(String(cage.total));\n } else {\n cells.push('.');\n }\n }\n }\n return cells.join('');\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sudokuPuzzle.d.ts","sourceRoot":"","sources":["../../../src/packlets/puzzles/sudokuPuzzle.ts"],"names":[],"mappings":"AAwBA,OAAO,EAAE,MAAM,EAAgC,MAAM,eAAe,CAAC;AACrE,OAAO,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEtD;;GAEG;AACH,qBAAa,YAAa,SAAQ,MAAM;IACtC,OAAO;WAIO,MAAM,CAAC,MAAM,EAAE,iBAAiB,GAAG,MAAM,CAAC,MAAM,CAAC;CAUhE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sudokuPuzzle.js","sourceRoot":"","sources":["../../../src/packlets/puzzles/sudokuPuzzle.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;;;AAEH,4CAAqE;AACrE,sCAAsD;AAEtD;;GAEG;AACH,MAAa,YAAa,SAAQ,eAAM;IACtC,YAAoB,MAAyB;QAC3C,KAAK,CAAC,MAAM,CAAC,CAAC;IAChB,CAAC;IAEM,MAAM,CAAC,MAAM,CAAC,MAAyB;QAC5C,sBAAsB;QACtB,IAAI,MAAM,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC7B,OAAO,IAAA,eAAI,EAAC,WAAW,MAAM,CAAC,WAAW,sBAAsB,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;QAChF,CAAC;QAED,OAAO,IAAA,wBAAa,EAAC,GAAG,EAAE,CAAC,IAAI,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,MAAM,EAAE,EAAE;YACxE,OAAO,IAAA,kBAAO,EAAC,MAAM,CAAC,CAAC;QACzB,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAfD,oCAeC","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 { IPuzzleDefinition, Puzzle } from '../common';\n\n/**\n * @public\n */\nexport class SudokuPuzzle extends Puzzle {\n private constructor(puzzle: IPuzzleDefinition) {\n super(puzzle);\n }\n\n public static create(puzzle: IPuzzleDefinition): Result<Puzzle> {\n /* c8 ignore next 3 */\n if (puzzle.type !== 'sudoku') {\n return fail(`Puzzle '${puzzle.description}' unsupported type ${puzzle.type}`);\n }\n\n return captureResult(() => new SudokuPuzzle(puzzle)).onSuccess((puzzle) => {\n return succeed(puzzle);\n });\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sudokuXPuzzle.d.ts","sourceRoot":"","sources":["../../../src/packlets/puzzles/sudokuXPuzzle.ts"],"names":[],"mappings":"AAwBA,OAAO,EAAE,MAAM,EAAgC,MAAM,eAAe,CAAC;AACrE,OAAO,EAAwB,iBAAiB,EAAO,MAAM,EAAE,MAAM,WAAW,CAAC;AAEjF;;GAEG;AACH,qBAAa,aAAc,SAAQ,MAAM;IACvC,OAAO;WAIO,MAAM,CAAC,MAAM,EAAE,iBAAiB,GAAG,MAAM,CAAC,MAAM,CAAC;IAgB/D,OAAO,CAAC,MAAM,CAAC,UAAU;CAuB1B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sudokuXPuzzle.js","sourceRoot":"","sources":["../../../src/packlets/puzzles/sudokuXPuzzle.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;;;AAEH,4CAAqE;AACrE,sCAAiF;AAEjF;;GAEG;AACH,MAAa,aAAc,SAAQ,eAAM;IACvC,YAAoB,MAAyB,EAAE,UAA4B;QACzE,KAAK,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IAC5B,CAAC;IAEM,MAAM,CAAC,MAAM,CAAC,MAAyB;QAC5C,sBAAsB;QACtB,IAAI,MAAM,CAAC,IAAI,KAAK,UAAU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CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,CAAC;QACxC,MAAM,IAAI,GAAG,YAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,CAAC;QAExC,MAAM,EAAE,GAAG,aAAI,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE,MAAM,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC,OAAO,EAAE,CAAC;QAC5E,MAAM,EAAE,GAAG,aAAI,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE,MAAM,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC,OAAO,EAAE,CAAC;QAC5E,OAAO;YACL,CAAC,IAAI,EAAE,EAAE,CAAC;YACV,CAAC,IAAI,EAAE,EAAE,CAAC;SACX,CAAC;IACJ,CAAC;CACF;AA5CD,sCA4CC","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, succeed, fail } from '@fgv/ts-utils';\nimport { Cage, CageId, CellId, IPuzzleDefinition, Ids, Puzzle } from '../common';\n\n/**\n * @public\n */\nexport class SudokuXPuzzle extends Puzzle {\n private constructor(puzzle: IPuzzleDefinition, extraCages: [CageId, Cage][]) {\n super(puzzle, extraCages);\n }\n\n public static create(puzzle: IPuzzleDefinition): Result<Puzzle> {\n /* c8 ignore next 3 */\n if (puzzle.type !== 'sudoku-x') {\n return fail(`Puzzle '${puzzle.description}' unsupported type ${puzzle.type}`);\n }\n // Sudoku X diagonals work for any square puzzle (totalRows === totalColumns)\n if (puzzle.totalRows !== puzzle.totalColumns) {\n return fail(`Sudoku X puzzle must be square, got ${puzzle.totalRows}x${puzzle.totalColumns}`);\n }\n return captureResult(() => {\n return new SudokuXPuzzle(puzzle, SudokuXPuzzle._getXCages(puzzle));\n }).onSuccess((puzzle) => {\n return succeed(puzzle);\n });\n }\n\n private static _getXCages(puzzle: IPuzzleDefinition): [CageId, Cage][] {\n const x1Cells: CellId[] = [];\n const x2Cells: CellId[] = [];\n\n for (\n let row = 0, col1 = 0, col2 = puzzle.totalColumns - 1;\n row < puzzle.totalRows;\n row++, col1++, col2--\n ) {\n x1Cells.push(Ids.cellId({ row, col: col1 }).orThrow());\n x2Cells.push(Ids.cellId({ row, col: col2 }).orThrow());\n }\n\n const x1Id = Ids.cageId('X1').orThrow();\n const x2Id = Ids.cageId('X2').orThrow();\n\n const x1 = Cage.create(x1Id, 'x', puzzle.basicCageTotal, x1Cells).orThrow();\n const x2 = Cage.create(x2Id, 'x', puzzle.basicCageTotal, x2Cells).orThrow();\n return [\n [x1Id, x1],\n [x2Id, x2]\n ];\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fgv/ts-sudoku-lib",
|
|
3
|
-
"version": "5.1.0-
|
|
3
|
+
"version": "5.1.0-40",
|
|
4
4
|
"description": "Sudoku rules library",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "dist/ts-sudoku-lib.d.ts",
|
|
@@ -44,14 +44,14 @@
|
|
|
44
44
|
"@rushstack/heft-jest-plugin": "1.2.6",
|
|
45
45
|
"eslint-plugin-tsdoc": "~0.5.2",
|
|
46
46
|
"typedoc": "~0.28.16",
|
|
47
|
-
"@fgv/heft-dual-rig": "5.1.0-
|
|
48
|
-
"@fgv/ts-utils": "5.1.0-
|
|
49
|
-
"@fgv/ts-
|
|
50
|
-
"@fgv/ts-
|
|
51
|
-
"@fgv/typedoc-compact-theme": "5.1.0-
|
|
47
|
+
"@fgv/heft-dual-rig": "5.1.0-40",
|
|
48
|
+
"@fgv/ts-utils": "5.1.0-40",
|
|
49
|
+
"@fgv/ts-utils-jest": "5.1.0-40",
|
|
50
|
+
"@fgv/ts-json-base": "5.1.0-40",
|
|
51
|
+
"@fgv/typedoc-compact-theme": "5.1.0-40"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
|
-
"@fgv/ts-utils": "5.1.0-
|
|
54
|
+
"@fgv/ts-utils": "5.1.0-40"
|
|
55
55
|
},
|
|
56
56
|
"exports": {
|
|
57
57
|
".": {
|
package/debug_test.js
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
const path = require('path');
|
|
2
|
-
const libPath = path.join(__dirname, 'lib');
|
|
3
|
-
require.main.paths.unshift(libPath);
|
|
4
|
-
|
|
5
|
-
try {
|
|
6
|
-
const Puzzles = require('./lib/packlets/puzzles');
|
|
7
|
-
const { PuzzleSession } = require('./lib/packlets/common');
|
|
8
|
-
const { KillerCombinations } = require('./lib/packlets/puzzles');
|
|
9
|
-
|
|
10
|
-
function createSimpleKillerCage(cageSize, total, containedValues = []) {
|
|
11
|
-
const existingPuzzleDesc = {
|
|
12
|
-
id: 'test-killer',
|
|
13
|
-
description: 'Test killer sudoku puzzle',
|
|
14
|
-
type: 'killer-sudoku',
|
|
15
|
-
level: 1,
|
|
16
|
-
rows: 9,
|
|
17
|
-
cols: 9,
|
|
18
|
-
cells: [
|
|
19
|
-
'ABCCCDDDE',
|
|
20
|
-
'ABFFGGGDE',
|
|
21
|
-
'HIJKGGLLL',
|
|
22
|
-
'HIJKMGLNN',
|
|
23
|
-
'HOPPMQQNR',
|
|
24
|
-
'OOSTMUVWR',
|
|
25
|
-
'SSSTTUVWR',
|
|
26
|
-
'XYTTTZZab',
|
|
27
|
-
'XYYYcccab',
|
|
28
|
-
'|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'
|
|
29
|
-
].join('')
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
const puzzle = Puzzles.Killer.create(existingPuzzleDesc);
|
|
33
|
-
if (puzzle.isFailure()) throw new Error(puzzle.message);
|
|
34
|
-
|
|
35
|
-
const session = PuzzleSession.create(puzzle.value);
|
|
36
|
-
if (session.isFailure()) throw new Error(session.message);
|
|
37
|
-
|
|
38
|
-
// Apply contained values if provided
|
|
39
|
-
if (containedValues.length > 0) {
|
|
40
|
-
const cageA = puzzle.value.getCage('KA');
|
|
41
|
-
if (cageA.isFailure()) throw new Error(cageA.message);
|
|
42
|
-
const cellIds = Array.from(cageA.value.cellIds);
|
|
43
|
-
containedValues.forEach((value, index) => {
|
|
44
|
-
if (index < cellIds.length) {
|
|
45
|
-
const result = session.value.updateCellValue(cellIds[index], value);
|
|
46
|
-
if (result.isFailure()) throw new Error(result.message);
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// For this simple test, we'll use cage KA
|
|
52
|
-
const cage = puzzle.value.getCage('KA');
|
|
53
|
-
if (cage.isFailure()) throw new Error(cage.message);
|
|
54
|
-
|
|
55
|
-
return { puzzle: puzzle.value, state: session.value.state, cage: cage.value };
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
console.log('Testing cage KA with one cell filled with 5...');
|
|
59
|
-
const { puzzle, state, cage } = createSimpleKillerCage(2, 11, [5]);
|
|
60
|
-
|
|
61
|
-
console.log('Cage info:', {
|
|
62
|
-
id: cage.id,
|
|
63
|
-
total: cage.total,
|
|
64
|
-
numCells: cage.numCells,
|
|
65
|
-
cellIds: Array.from(cage.cellIds)
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
console.log('Cell states:');
|
|
69
|
-
Array.from(cage.cellIds).forEach((cellId) => {
|
|
70
|
-
const contents = state.getCellContents(cellId);
|
|
71
|
-
if (contents.isSuccess()) {
|
|
72
|
-
console.log(` ${cellId}:`, contents.value);
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
const result = KillerCombinations.getCellPossibilities(puzzle, state, cage);
|
|
77
|
-
if (result.isSuccess()) {
|
|
78
|
-
console.log('Possibilities:');
|
|
79
|
-
result.value.forEach((values, cellId) => {
|
|
80
|
-
console.log(` ${cellId}: [${values.join(',')}]`);
|
|
81
|
-
});
|
|
82
|
-
} else {
|
|
83
|
-
console.error('Failed to get possibilities:', result.message);
|
|
84
|
-
}
|
|
85
|
-
} catch (error) {
|
|
86
|
-
console.error('Error:', error.message);
|
|
87
|
-
console.error('Stack:', error.stack);
|
|
88
|
-
}
|
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* MIT License
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2023 Erik Fortune
|
|
5
|
-
*
|
|
6
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
* in the Software without restriction, including without limitation the rights
|
|
9
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
* furnished to do so, subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
* copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
* SOFTWARE.
|
|
23
|
-
*/
|
|
24
|
-
import '@fgv/ts-utils-jest';
|
|
25
|
-
import { PuzzleSession, PuzzleDefinitionFactory, STANDARD_CONFIGS } from '../../../index';
|
|
26
|
-
import { Puzzles } from '../../../index';
|
|
27
|
-
/**
|
|
28
|
-
* Creates a standard test puzzle and state from row strings
|
|
29
|
-
* @param rows - 9 strings representing puzzle rows (use '.' for empty cells)
|
|
30
|
-
* @param puzzleId - Optional puzzle ID (defaults to 'test-puzzle')
|
|
31
|
-
* @returns Puzzle instance and initial state
|
|
32
|
-
*/
|
|
33
|
-
export function createPuzzleAndState(rows, puzzleId = 'test-puzzle') {
|
|
34
|
-
const puzzleDefinition = PuzzleDefinitionFactory.create(STANDARD_CONFIGS.puzzle9x9, {
|
|
35
|
-
id: puzzleId,
|
|
36
|
-
description: 'Test puzzle',
|
|
37
|
-
type: 'sudoku',
|
|
38
|
-
level: 1,
|
|
39
|
-
cells: rows.join('')
|
|
40
|
-
}).orThrow();
|
|
41
|
-
const puzzle = Puzzles.Any.create(puzzleDefinition).orThrow();
|
|
42
|
-
const session = PuzzleSession.create(puzzle).orThrow();
|
|
43
|
-
return { puzzle, state: session.state };
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Creates a test puzzle with specific dimensions
|
|
47
|
-
* @param dimensions - Puzzle dimensions configuration
|
|
48
|
-
* @param cells - Cell values string
|
|
49
|
-
* @param type - Puzzle type (defaults to 'sudoku')
|
|
50
|
-
* @returns Puzzle instance and initial state
|
|
51
|
-
*/
|
|
52
|
-
export function createPuzzleWithDimensions(dimensions, cells, type = 'sudoku') {
|
|
53
|
-
const puzzleDefinition = PuzzleDefinitionFactory.create(dimensions, {
|
|
54
|
-
id: 'test-puzzle',
|
|
55
|
-
description: 'Test puzzle',
|
|
56
|
-
type,
|
|
57
|
-
level: 1,
|
|
58
|
-
cells
|
|
59
|
-
}).orThrow();
|
|
60
|
-
const puzzle = Puzzles.Any.create(puzzleDefinition).orThrow();
|
|
61
|
-
const session = PuzzleSession.create(puzzle).orThrow();
|
|
62
|
-
return { puzzle, state: session.state };
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Creates a killer sudoku puzzle for testing cage-based logic
|
|
66
|
-
* @param config - Configuration for the killer puzzle
|
|
67
|
-
* @returns Puzzle instance, session, and first cage
|
|
68
|
-
*/
|
|
69
|
-
export function createTestKillerPuzzle(config) {
|
|
70
|
-
var _a;
|
|
71
|
-
const cells = (_a = config.cells) !== null && _a !== void 0 ? _a : '.'.repeat(81);
|
|
72
|
-
// Build cage specifications
|
|
73
|
-
let cageSpecs = '';
|
|
74
|
-
if (config.cages) {
|
|
75
|
-
cageSpecs = config.cages
|
|
76
|
-
.map((cage) => {
|
|
77
|
-
var _a;
|
|
78
|
-
const id = (_a = cage.id) !== null && _a !== void 0 ? _a : `cage${cage.sum}`;
|
|
79
|
-
const cellList = cage.cells.join(',');
|
|
80
|
-
return `${id}:${cellList}:${cage.sum}`;
|
|
81
|
-
})
|
|
82
|
-
.join('|');
|
|
83
|
-
}
|
|
84
|
-
const puzzleDefinition = PuzzleDefinitionFactory.create(STANDARD_CONFIGS.puzzle9x9, {
|
|
85
|
-
id: 'test-killer',
|
|
86
|
-
description: 'Test Killer Sudoku',
|
|
87
|
-
type: 'killer',
|
|
88
|
-
level: 1,
|
|
89
|
-
cells: cells + (cageSpecs ? `:${cageSpecs}` : '')
|
|
90
|
-
}).orThrow();
|
|
91
|
-
const puzzle = Puzzles.Killer.create(puzzleDefinition).orThrow();
|
|
92
|
-
const session = PuzzleSession.create(puzzle).orThrow();
|
|
93
|
-
// Return first cage if any were defined
|
|
94
|
-
const cage = config.cages && config.cages.length > 0
|
|
95
|
-
? puzzle.cages.find((c) => { var _a; return c.id === ((_a = config.cages[0].id) !== null && _a !== void 0 ? _a : `cage${config.cages[0].sum}`); })
|
|
96
|
-
: undefined;
|
|
97
|
-
return { puzzle, session, cage };
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Creates a simple killer sudoku cage for testing
|
|
101
|
-
* @param cageSize - Number of cells in the cage
|
|
102
|
-
* @param total - Sum total for the cage
|
|
103
|
-
* @param startCell - Starting cell ID (defaults to 'A1')
|
|
104
|
-
* @returns Cage specification object
|
|
105
|
-
*/
|
|
106
|
-
export function createSimpleKillerCage(cageSize, total, startCell = 'A1') {
|
|
107
|
-
const cells = [startCell];
|
|
108
|
-
// Add adjacent cells horizontally
|
|
109
|
-
const startRow = startCell.charCodeAt(0);
|
|
110
|
-
const startCol = parseInt(startCell.substring(1), 10);
|
|
111
|
-
for (let i = 1; i < cageSize && cells.length < cageSize; i++) {
|
|
112
|
-
const row = String.fromCharCode(startRow);
|
|
113
|
-
const col = startCol + i;
|
|
114
|
-
if (col <= 9) {
|
|
115
|
-
cells.push(`${row}${col}`);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
// If we need more cells, add them vertically
|
|
119
|
-
for (let i = 1; cells.length < cageSize && i < 9; i++) {
|
|
120
|
-
const row = String.fromCharCode(startRow + i);
|
|
121
|
-
const col = startCol;
|
|
122
|
-
if (row <= 'I') {
|
|
123
|
-
cells.push(`${row}${col}`);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
return {
|
|
127
|
-
id: `cage${total}`,
|
|
128
|
-
cells,
|
|
129
|
-
sum: total
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Creates a sudoku X puzzle for testing diagonal constraints
|
|
134
|
-
* @param rows - 9 strings representing puzzle rows
|
|
135
|
-
* @returns Puzzle instance and initial state
|
|
136
|
-
*/
|
|
137
|
-
export function createSudokuXPuzzle(rows) {
|
|
138
|
-
const puzzleDefinition = PuzzleDefinitionFactory.create(STANDARD_CONFIGS.puzzle9x9, {
|
|
139
|
-
id: 'test-sudoku-x',
|
|
140
|
-
description: 'Test Sudoku X',
|
|
141
|
-
type: 'sudoku-x',
|
|
142
|
-
level: 1,
|
|
143
|
-
cells: rows.join('')
|
|
144
|
-
}).orThrow();
|
|
145
|
-
const puzzle = Puzzles.SudokuX.create(puzzleDefinition).orThrow();
|
|
146
|
-
const session = PuzzleSession.create(puzzle).orThrow();
|
|
147
|
-
return { puzzle, state: session.state };
|
|
148
|
-
}
|
|
149
|
-
//# sourceMappingURL=puzzleBuilders.js.map
|