@cubingcenter/scrambler 0.1.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/README.md +169 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +10 -0
- package/dist/cli/run.d.ts +9 -0
- package/dist/cli/run.d.ts.map +1 -0
- package/dist/cli/run.js +139 -0
- package/dist/core/api.d.ts +19 -0
- package/dist/core/api.d.ts.map +1 -0
- package/dist/core/api.js +94 -0
- package/dist/core/errors.d.ts +21 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/errors.js +34 -0
- package/dist/core/index.d.ts +5 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +3 -0
- package/dist/core/registry.d.ts +10 -0
- package/dist/core/registry.d.ts.map +1 -0
- package/dist/core/registry.js +35 -0
- package/dist/core/types.d.ts +34 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/puzzles/clock/index.d.ts +2 -0
- package/dist/puzzles/clock/index.d.ts.map +1 -0
- package/dist/puzzles/clock/index.js +1 -0
- package/dist/puzzles/clock/scrambler.d.ts +4 -0
- package/dist/puzzles/clock/scrambler.d.ts.map +1 -0
- package/dist/puzzles/clock/scrambler.js +50 -0
- package/dist/puzzles/cube2/facelets.d.ts +5 -0
- package/dist/puzzles/cube2/facelets.d.ts.map +1 -0
- package/dist/puzzles/cube2/facelets.js +53 -0
- package/dist/puzzles/cube2/index.d.ts +10 -0
- package/dist/puzzles/cube2/index.d.ts.map +1 -0
- package/dist/puzzles/cube2/index.js +8 -0
- package/dist/puzzles/cube2/moves.d.ts +9 -0
- package/dist/puzzles/cube2/moves.d.ts.map +1 -0
- package/dist/puzzles/cube2/moves.js +79 -0
- package/dist/puzzles/cube2/random-state.d.ts +3 -0
- package/dist/puzzles/cube2/random-state.d.ts.map +1 -0
- package/dist/puzzles/cube2/random-state.js +51 -0
- package/dist/puzzles/cube2/scrambler.d.ts +6 -0
- package/dist/puzzles/cube2/scrambler.d.ts.map +1 -0
- package/dist/puzzles/cube2/scrambler.js +54 -0
- package/dist/puzzles/cube2/solver/browser-loader.d.ts +12 -0
- package/dist/puzzles/cube2/solver/browser-loader.d.ts.map +1 -0
- package/dist/puzzles/cube2/solver/browser-loader.js +80 -0
- package/dist/puzzles/cube2/solver/generated/distances.bin +1 -0
- package/dist/puzzles/cube2/solver/generated/manifest.json +21 -0
- package/dist/puzzles/cube2/solver/generated/orientation-distances.bin +0 -0
- package/dist/puzzles/cube2/solver/generated/orientation-table.bin +0 -0
- package/dist/puzzles/cube2/solver/generated/permutation-distances.bin +0 -0
- package/dist/puzzles/cube2/solver/generated/permutation-table.bin +0 -0
- package/dist/puzzles/cube2/solver/generated-assets.d.ts +6 -0
- package/dist/puzzles/cube2/solver/generated-assets.d.ts.map +1 -0
- package/dist/puzzles/cube2/solver/generated-assets.js +25 -0
- package/dist/puzzles/cube2/solver/index.d.ts +3 -0
- package/dist/puzzles/cube2/solver/index.d.ts.map +1 -0
- package/dist/puzzles/cube2/solver/index.js +1 -0
- package/dist/puzzles/cube2/solver/node-loader.d.ts +6 -0
- package/dist/puzzles/cube2/solver/node-loader.d.ts.map +1 -0
- package/dist/puzzles/cube2/solver/node-loader.js +83 -0
- package/dist/puzzles/cube2/solver/search.d.ts +8 -0
- package/dist/puzzles/cube2/solver/search.d.ts.map +1 -0
- package/dist/puzzles/cube2/solver/search.js +50 -0
- package/dist/puzzles/cube2/solver/table-metadata.d.ts +16 -0
- package/dist/puzzles/cube2/solver/table-metadata.d.ts.map +1 -0
- package/dist/puzzles/cube2/solver/table-metadata.js +15 -0
- package/dist/puzzles/cube2/solver/tables.d.ts +14 -0
- package/dist/puzzles/cube2/solver/tables.d.ts.map +1 -0
- package/dist/puzzles/cube2/solver/tables.js +82 -0
- package/dist/puzzles/cube2/state.d.ts +6 -0
- package/dist/puzzles/cube2/state.d.ts.map +1 -0
- package/dist/puzzles/cube2/state.js +30 -0
- package/dist/puzzles/cube2/types.d.ts +23 -0
- package/dist/puzzles/cube2/types.d.ts.map +1 -0
- package/dist/puzzles/cube2/types.js +21 -0
- package/dist/puzzles/cube2/validation.d.ts +6 -0
- package/dist/puzzles/cube2/validation.d.ts.map +1 -0
- package/dist/puzzles/cube2/validation.js +72 -0
- package/dist/puzzles/cube3/facelets.d.ts +5 -0
- package/dist/puzzles/cube3/facelets.d.ts.map +1 -0
- package/dist/puzzles/cube3/facelets.js +89 -0
- package/dist/puzzles/cube3/index.d.ts +10 -0
- package/dist/puzzles/cube3/index.d.ts.map +1 -0
- package/dist/puzzles/cube3/index.js +8 -0
- package/dist/puzzles/cube3/moves.d.ts +9 -0
- package/dist/puzzles/cube3/moves.d.ts.map +1 -0
- package/dist/puzzles/cube3/moves.js +210 -0
- package/dist/puzzles/cube3/random-state.d.ts +3 -0
- package/dist/puzzles/cube3/random-state.d.ts.map +1 -0
- package/dist/puzzles/cube3/random-state.js +59 -0
- package/dist/puzzles/cube3/scrambler.d.ts +6 -0
- package/dist/puzzles/cube3/scrambler.d.ts.map +1 -0
- package/dist/puzzles/cube3/scrambler.js +59 -0
- package/dist/puzzles/cube3/solver/browser-loader.d.ts +5 -0
- package/dist/puzzles/cube3/solver/browser-loader.d.ts.map +1 -0
- package/dist/puzzles/cube3/solver/browser-loader.js +134 -0
- package/dist/puzzles/cube3/solver/browser-worker-pool.d.ts +31 -0
- package/dist/puzzles/cube3/solver/browser-worker-pool.d.ts.map +1 -0
- package/dist/puzzles/cube3/solver/browser-worker-pool.js +118 -0
- package/dist/puzzles/cube3/solver/browser-worker.d.ts +2 -0
- package/dist/puzzles/cube3/solver/browser-worker.d.ts.map +1 -0
- package/dist/puzzles/cube3/solver/browser-worker.js +71 -0
- package/dist/puzzles/cube3/solver/coordinates.d.ts +34 -0
- package/dist/puzzles/cube3/solver/coordinates.d.ts.map +1 -0
- package/dist/puzzles/cube3/solver/coordinates.js +266 -0
- package/dist/puzzles/cube3/solver/generated/manifest.json +404 -0
- package/dist/puzzles/cube3/solver/generated/move-cornerOrientation.bin +0 -0
- package/dist/puzzles/cube3/solver/generated/move-cornerPermutation.bin +0 -0
- package/dist/puzzles/cube3/solver/generated/move-edgeOrientation.bin +0 -0
- package/dist/puzzles/cube3/solver/generated/move-slicePermutation.bin +0 -0
- package/dist/puzzles/cube3/solver/generated/move-udEdgePermutation.bin +0 -0
- package/dist/puzzles/cube3/solver/generated/move-udSlice.bin +0 -0
- package/dist/puzzles/cube3/solver/generated/pruning-cornerOrientation.bin +1 -0
- package/dist/puzzles/cube3/solver/generated/pruning-cornerOrientationEdgeOrientation.bin +1 -0
- package/dist/puzzles/cube3/solver/generated/pruning-cornerPermutation.bin +1 -0
- package/dist/puzzles/cube3/solver/generated/pruning-cornerPermutationSlicePermutation.bin +1 -0
- package/dist/puzzles/cube3/solver/generated/pruning-edgeOrientation.bin +1 -0
- package/dist/puzzles/cube3/solver/generated/pruning-slicePermutation.bin +1 -0
- package/dist/puzzles/cube3/solver/generated/pruning-udEdgePermutation.bin +1 -0
- package/dist/puzzles/cube3/solver/generated/pruning-udEdgePermutationSlicePermutation.bin +1 -0
- package/dist/puzzles/cube3/solver/generated/pruning-udSlice.bin +0 -0
- package/dist/puzzles/cube3/solver/generated-assets.d.ts +5 -0
- package/dist/puzzles/cube3/solver/generated-assets.d.ts.map +1 -0
- package/dist/puzzles/cube3/solver/generated-assets.js +60 -0
- package/dist/puzzles/cube3/solver/index.d.ts +10 -0
- package/dist/puzzles/cube3/solver/index.d.ts.map +1 -0
- package/dist/puzzles/cube3/solver/index.js +5 -0
- package/dist/puzzles/cube3/solver/node-loader.d.ts +3 -0
- package/dist/puzzles/cube3/solver/node-loader.d.ts.map +1 -0
- package/dist/puzzles/cube3/solver/node-loader.js +120 -0
- package/dist/puzzles/cube3/solver/phase1.d.ts +28 -0
- package/dist/puzzles/cube3/solver/phase1.d.ts.map +1 -0
- package/dist/puzzles/cube3/solver/phase1.js +150 -0
- package/dist/puzzles/cube3/solver/phase2.d.ts +44 -0
- package/dist/puzzles/cube3/solver/phase2.d.ts.map +1 -0
- package/dist/puzzles/cube3/solver/phase2.js +270 -0
- package/dist/puzzles/cube3/solver/search-utils.d.ts +9 -0
- package/dist/puzzles/cube3/solver/search-utils.d.ts.map +1 -0
- package/dist/puzzles/cube3/solver/search-utils.js +41 -0
- package/dist/puzzles/cube3/solver/table-metadata.d.ts +97 -0
- package/dist/puzzles/cube3/solver/table-metadata.d.ts.map +1 -0
- package/dist/puzzles/cube3/solver/table-metadata.js +21 -0
- package/dist/puzzles/cube3/solver/tables.d.ts +72 -0
- package/dist/puzzles/cube3/solver/tables.d.ts.map +1 -0
- package/dist/puzzles/cube3/solver/tables.js +202 -0
- package/dist/puzzles/cube3/solver/worker-pool.d.ts +18 -0
- package/dist/puzzles/cube3/solver/worker-pool.d.ts.map +1 -0
- package/dist/puzzles/cube3/solver/worker-pool.js +116 -0
- package/dist/puzzles/cube3/solver/worker.d.ts +2 -0
- package/dist/puzzles/cube3/solver/worker.d.ts.map +1 -0
- package/dist/puzzles/cube3/solver/worker.js +73 -0
- package/dist/puzzles/cube3/state.d.ts +6 -0
- package/dist/puzzles/cube3/state.d.ts.map +1 -0
- package/dist/puzzles/cube3/state.js +40 -0
- package/dist/puzzles/cube3/subset-state.d.ts +4 -0
- package/dist/puzzles/cube3/subset-state.d.ts.map +1 -0
- package/dist/puzzles/cube3/subset-state.js +163 -0
- package/dist/puzzles/cube3/types.d.ts +29 -0
- package/dist/puzzles/cube3/types.d.ts.map +1 -0
- package/dist/puzzles/cube3/types.js +22 -0
- package/dist/puzzles/cube3/validation.d.ts +6 -0
- package/dist/puzzles/cube3/validation.d.ts.map +1 -0
- package/dist/puzzles/cube3/validation.js +83 -0
- package/dist/puzzles/cube4/facelets.d.ts +5 -0
- package/dist/puzzles/cube4/facelets.d.ts.map +1 -0
- package/dist/puzzles/cube4/facelets.js +135 -0
- package/dist/puzzles/cube4/index.d.ts +7 -0
- package/dist/puzzles/cube4/index.d.ts.map +1 -0
- package/dist/puzzles/cube4/index.js +8 -0
- package/dist/puzzles/cube4/moves.d.ts +37 -0
- package/dist/puzzles/cube4/moves.d.ts.map +1 -0
- package/dist/puzzles/cube4/moves.js +243 -0
- package/dist/puzzles/cube4/scrambler.d.ts +4 -0
- package/dist/puzzles/cube4/scrambler.d.ts.map +1 -0
- package/dist/puzzles/cube4/scrambler.js +98 -0
- package/dist/puzzles/cube4/state.d.ts +16 -0
- package/dist/puzzles/cube4/state.d.ts.map +1 -0
- package/dist/puzzles/cube4/state.js +84 -0
- package/dist/puzzles/cube4/types.d.ts +76 -0
- package/dist/puzzles/cube4/types.d.ts.map +1 -0
- package/dist/puzzles/cube4/types.js +62 -0
- package/dist/puzzles/cube5x5/index.d.ts +4 -0
- package/dist/puzzles/cube5x5/index.d.ts.map +1 -0
- package/dist/puzzles/cube5x5/index.js +2 -0
- package/dist/puzzles/cube5x5/scrambler.d.ts +4 -0
- package/dist/puzzles/cube5x5/scrambler.d.ts.map +1 -0
- package/dist/puzzles/cube5x5/scrambler.js +93 -0
- package/dist/puzzles/cube5x5/types.d.ts +4 -0
- package/dist/puzzles/cube5x5/types.d.ts.map +1 -0
- package/dist/puzzles/cube5x5/types.js +4 -0
- package/dist/puzzles/cube6x6/index.d.ts +4 -0
- package/dist/puzzles/cube6x6/index.d.ts.map +1 -0
- package/dist/puzzles/cube6x6/index.js +2 -0
- package/dist/puzzles/cube6x6/scrambler.d.ts +4 -0
- package/dist/puzzles/cube6x6/scrambler.d.ts.map +1 -0
- package/dist/puzzles/cube6x6/scrambler.js +105 -0
- package/dist/puzzles/cube6x6/types.d.ts +4 -0
- package/dist/puzzles/cube6x6/types.d.ts.map +1 -0
- package/dist/puzzles/cube6x6/types.js +8 -0
- package/dist/puzzles/cube7x7/index.d.ts +4 -0
- package/dist/puzzles/cube7x7/index.d.ts.map +1 -0
- package/dist/puzzles/cube7x7/index.js +2 -0
- package/dist/puzzles/cube7x7/scrambler.d.ts +4 -0
- package/dist/puzzles/cube7x7/scrambler.d.ts.map +1 -0
- package/dist/puzzles/cube7x7/scrambler.js +93 -0
- package/dist/puzzles/cube7x7/types.d.ts +4 -0
- package/dist/puzzles/cube7x7/types.d.ts.map +1 -0
- package/dist/puzzles/cube7x7/types.js +8 -0
- package/dist/puzzles/index.d.ts +10 -0
- package/dist/puzzles/index.d.ts.map +1 -0
- package/dist/puzzles/index.js +28 -0
- package/dist/puzzles/megaminx/index.d.ts +4 -0
- package/dist/puzzles/megaminx/index.d.ts.map +1 -0
- package/dist/puzzles/megaminx/index.js +2 -0
- package/dist/puzzles/megaminx/scrambler.d.ts +4 -0
- package/dist/puzzles/megaminx/scrambler.d.ts.map +1 -0
- package/dist/puzzles/megaminx/scrambler.js +56 -0
- package/dist/puzzles/megaminx/types.d.ts +6 -0
- package/dist/puzzles/megaminx/types.d.ts.map +1 -0
- package/dist/puzzles/megaminx/types.js +4 -0
- package/dist/puzzles/pyraminx/index.d.ts +9 -0
- package/dist/puzzles/pyraminx/index.d.ts.map +1 -0
- package/dist/puzzles/pyraminx/index.js +7 -0
- package/dist/puzzles/pyraminx/moves.d.ts +9 -0
- package/dist/puzzles/pyraminx/moves.d.ts.map +1 -0
- package/dist/puzzles/pyraminx/moves.js +117 -0
- package/dist/puzzles/pyraminx/random-state.d.ts +3 -0
- package/dist/puzzles/pyraminx/random-state.d.ts.map +1 -0
- package/dist/puzzles/pyraminx/random-state.js +53 -0
- package/dist/puzzles/pyraminx/scrambler.d.ts +6 -0
- package/dist/puzzles/pyraminx/scrambler.d.ts.map +1 -0
- package/dist/puzzles/pyraminx/scrambler.js +56 -0
- package/dist/puzzles/pyraminx/solver.d.ts +10 -0
- package/dist/puzzles/pyraminx/solver.d.ts.map +1 -0
- package/dist/puzzles/pyraminx/solver.js +160 -0
- package/dist/puzzles/pyraminx/state.d.ts +6 -0
- package/dist/puzzles/pyraminx/state.d.ts.map +1 -0
- package/dist/puzzles/pyraminx/state.js +32 -0
- package/dist/puzzles/pyraminx/types.d.ts +17 -0
- package/dist/puzzles/pyraminx/types.d.ts.map +1 -0
- package/dist/puzzles/pyraminx/types.js +7 -0
- package/dist/puzzles/pyraminx/validation.d.ts +8 -0
- package/dist/puzzles/pyraminx/validation.d.ts.map +1 -0
- package/dist/puzzles/pyraminx/validation.js +79 -0
- package/dist/random/index.d.ts +3 -0
- package/dist/random/index.d.ts.map +1 -0
- package/dist/random/index.js +1 -0
- package/dist/random/prng.d.ts +7 -0
- package/dist/random/prng.d.ts.map +1 -0
- package/dist/random/prng.js +60 -0
- package/dist-cjs/cli/index.js +12 -0
- package/dist-cjs/cli/run.js +142 -0
- package/dist-cjs/core/api.js +102 -0
- package/dist-cjs/core/errors.js +42 -0
- package/dist-cjs/core/index.js +19 -0
- package/dist-cjs/core/registry.js +39 -0
- package/dist-cjs/core/types.js +2 -0
- package/dist-cjs/index.js +19 -0
- package/dist-cjs/package.json +3 -0
- package/dist-cjs/puzzles/clock/index.js +6 -0
- package/dist-cjs/puzzles/clock/scrambler.js +54 -0
- package/dist-cjs/puzzles/cube2/facelets.js +58 -0
- package/dist-cjs/puzzles/cube2/index.js +67 -0
- package/dist-cjs/puzzles/cube2/moves.js +88 -0
- package/dist-cjs/puzzles/cube2/random-state.js +54 -0
- package/dist-cjs/puzzles/cube2/scrambler.js +58 -0
- package/dist-cjs/puzzles/cube2/solver/browser-loader.js +85 -0
- package/dist-cjs/puzzles/cube2/solver/generated/distances.bin +1 -0
- package/dist-cjs/puzzles/cube2/solver/generated/manifest.json +21 -0
- package/dist-cjs/puzzles/cube2/solver/generated/orientation-distances.bin +0 -0
- package/dist-cjs/puzzles/cube2/solver/generated/orientation-table.bin +0 -0
- package/dist-cjs/puzzles/cube2/solver/generated/permutation-distances.bin +0 -0
- package/dist-cjs/puzzles/cube2/solver/generated/permutation-table.bin +0 -0
- package/dist-cjs/puzzles/cube2/solver/generated-assets.js +61 -0
- package/dist-cjs/puzzles/cube2/solver/index.js +5 -0
- package/dist-cjs/puzzles/cube2/solver/node-loader.js +89 -0
- package/dist-cjs/puzzles/cube2/solver/search.js +53 -0
- package/dist-cjs/puzzles/cube2/solver/table-metadata.js +18 -0
- package/dist-cjs/puzzles/cube2/solver/tables.js +91 -0
- package/dist-cjs/puzzles/cube2/state.js +36 -0
- package/dist-cjs/puzzles/cube2/types.js +24 -0
- package/dist-cjs/puzzles/cube2/validation.js +78 -0
- package/dist-cjs/puzzles/cube3/facelets.js +94 -0
- package/dist-cjs/puzzles/cube3/index.js +68 -0
- package/dist-cjs/puzzles/cube3/moves.js +219 -0
- package/dist-cjs/puzzles/cube3/random-state.js +62 -0
- package/dist-cjs/puzzles/cube3/scrambler.js +63 -0
- package/dist-cjs/puzzles/cube3/solver/browser-loader.js +139 -0
- package/dist-cjs/puzzles/cube3/solver/coordinates.js +285 -0
- package/dist-cjs/puzzles/cube3/solver/generated/manifest.json +404 -0
- package/dist-cjs/puzzles/cube3/solver/generated/move-cornerOrientation.bin +0 -0
- package/dist-cjs/puzzles/cube3/solver/generated/move-cornerPermutation.bin +0 -0
- package/dist-cjs/puzzles/cube3/solver/generated/move-edgeOrientation.bin +0 -0
- package/dist-cjs/puzzles/cube3/solver/generated/move-slicePermutation.bin +0 -0
- package/dist-cjs/puzzles/cube3/solver/generated/move-udEdgePermutation.bin +0 -0
- package/dist-cjs/puzzles/cube3/solver/generated/move-udSlice.bin +0 -0
- package/dist-cjs/puzzles/cube3/solver/generated/pruning-cornerOrientation.bin +1 -0
- package/dist-cjs/puzzles/cube3/solver/generated/pruning-cornerOrientationEdgeOrientation.bin +1 -0
- package/dist-cjs/puzzles/cube3/solver/generated/pruning-cornerPermutation.bin +1 -0
- package/dist-cjs/puzzles/cube3/solver/generated/pruning-cornerPermutationSlicePermutation.bin +1 -0
- package/dist-cjs/puzzles/cube3/solver/generated/pruning-edgeOrientation.bin +1 -0
- package/dist-cjs/puzzles/cube3/solver/generated/pruning-slicePermutation.bin +1 -0
- package/dist-cjs/puzzles/cube3/solver/generated/pruning-udEdgePermutation.bin +1 -0
- package/dist-cjs/puzzles/cube3/solver/generated/pruning-udEdgePermutationSlicePermutation.bin +1 -0
- package/dist-cjs/puzzles/cube3/solver/generated/pruning-udSlice.bin +0 -0
- package/dist-cjs/puzzles/cube3/solver/generated-assets.js +98 -0
- package/dist-cjs/puzzles/cube3/solver/index.js +49 -0
- package/dist-cjs/puzzles/cube3/solver/node-loader.js +126 -0
- package/dist-cjs/puzzles/cube3/solver/phase1.js +158 -0
- package/dist-cjs/puzzles/cube3/solver/phase2.js +279 -0
- package/dist-cjs/puzzles/cube3/solver/search-utils.js +49 -0
- package/dist-cjs/puzzles/cube3/solver/table-metadata.js +24 -0
- package/dist-cjs/puzzles/cube3/solver/tables.js +216 -0
- package/dist-cjs/puzzles/cube3/state.js +46 -0
- package/dist-cjs/puzzles/cube3/subset-state.js +166 -0
- package/dist-cjs/puzzles/cube3/types.js +25 -0
- package/dist-cjs/puzzles/cube3/validation.js +89 -0
- package/dist-cjs/puzzles/cube4/facelets.js +140 -0
- package/dist-cjs/puzzles/cube4/index.js +45 -0
- package/dist-cjs/puzzles/cube4/moves.js +251 -0
- package/dist-cjs/puzzles/cube4/scrambler.js +135 -0
- package/dist-cjs/puzzles/cube4/state.js +92 -0
- package/dist-cjs/puzzles/cube4/types.js +65 -0
- package/dist-cjs/puzzles/cube5x5/index.js +9 -0
- package/dist-cjs/puzzles/cube5x5/scrambler.js +97 -0
- package/dist-cjs/puzzles/cube5x5/types.js +7 -0
- package/dist-cjs/puzzles/cube6x6/index.js +9 -0
- package/dist-cjs/puzzles/cube6x6/scrambler.js +109 -0
- package/dist-cjs/puzzles/cube6x6/types.js +11 -0
- package/dist-cjs/puzzles/cube7x7/index.js +9 -0
- package/dist-cjs/puzzles/cube7x7/scrambler.js +97 -0
- package/dist-cjs/puzzles/cube7x7/types.js +11 -0
- package/dist-cjs/puzzles/index.js +64 -0
- package/dist-cjs/puzzles/megaminx/index.js +11 -0
- package/dist-cjs/puzzles/megaminx/scrambler.js +60 -0
- package/dist-cjs/puzzles/megaminx/types.js +7 -0
- package/dist-cjs/puzzles/pyraminx/index.js +30 -0
- package/dist-cjs/puzzles/pyraminx/moves.js +126 -0
- package/dist-cjs/puzzles/pyraminx/random-state.js +56 -0
- package/dist-cjs/puzzles/pyraminx/scrambler.js +60 -0
- package/dist-cjs/puzzles/pyraminx/solver.js +170 -0
- package/dist-cjs/puzzles/pyraminx/state.js +38 -0
- package/dist-cjs/puzzles/pyraminx/types.js +10 -0
- package/dist-cjs/puzzles/pyraminx/validation.js +84 -0
- package/dist-cjs/random/index.js +5 -0
- package/dist-cjs/random/prng.js +63 -0
- package/docs/cubingcenter-integration.md +69 -0
- package/docs/development.md +44 -0
- package/docs/facelets.md +64 -0
- package/docs/getting-started.md +73 -0
- package/examples/cli-json.md +30 -0
- package/examples/commonjs.cjs +11 -0
- package/examples/esm.mjs +9 -0
- package/examples/timer-preview.mjs +29 -0
- package/package.json +53 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { CUBE3_MOVES } from "../types.js";
|
|
2
|
+
import { CUBE3_COORDINATE_RANGES, encodeCube3Coordinates, moveCoordinate } from "./coordinates.js";
|
|
3
|
+
import { createSolvedCube3State } from "../state.js";
|
|
4
|
+
import { loadGeneratedCube3Phase1Tables, loadGeneratedCube3Phase2Tables, loadGeneratedCube3SolverTables } from "./generated-assets.js";
|
|
5
|
+
export const CUBE3_PHASE1_MOVES = CUBE3_MOVES;
|
|
6
|
+
export const CUBE3_PHASE2_MOVES = [
|
|
7
|
+
"U",
|
|
8
|
+
"U2",
|
|
9
|
+
"U'",
|
|
10
|
+
"D",
|
|
11
|
+
"D2",
|
|
12
|
+
"D'",
|
|
13
|
+
"R2",
|
|
14
|
+
"L2",
|
|
15
|
+
"F2",
|
|
16
|
+
"B2"
|
|
17
|
+
];
|
|
18
|
+
let cachedTables;
|
|
19
|
+
let cachedPhase1Tables;
|
|
20
|
+
let cachedPhase2Tables;
|
|
21
|
+
export async function loadCube3SolverTables() {
|
|
22
|
+
cachedTables ??= await loadGeneratedCube3SolverTables();
|
|
23
|
+
return cachedTables;
|
|
24
|
+
}
|
|
25
|
+
export async function loadCube3Phase1Tables() {
|
|
26
|
+
cachedPhase1Tables ??= await loadGeneratedCube3Phase1Tables();
|
|
27
|
+
return cachedPhase1Tables;
|
|
28
|
+
}
|
|
29
|
+
export async function loadCube3Phase2Tables() {
|
|
30
|
+
cachedPhase2Tables ??= await loadGeneratedCube3Phase2Tables();
|
|
31
|
+
return cachedPhase2Tables;
|
|
32
|
+
}
|
|
33
|
+
export function generateCube3Phase1Tables() {
|
|
34
|
+
const cornerOrientation = generateCube3MoveTable("cornerOrientation", CUBE3_COORDINATE_RANGES.cornerOrientation, CUBE3_PHASE1_MOVES);
|
|
35
|
+
const edgeOrientation = generateCube3MoveTable("edgeOrientation", CUBE3_COORDINATE_RANGES.edgeOrientation, CUBE3_PHASE1_MOVES);
|
|
36
|
+
const udSlice = generateCube3MoveTable("udSlice", CUBE3_COORDINATE_RANGES.udSlice, CUBE3_PHASE1_MOVES);
|
|
37
|
+
return {
|
|
38
|
+
phase1Moves: CUBE3_PHASE1_MOVES,
|
|
39
|
+
moveTables: {
|
|
40
|
+
cornerOrientation,
|
|
41
|
+
edgeOrientation,
|
|
42
|
+
udSlice
|
|
43
|
+
},
|
|
44
|
+
pruningTables: {
|
|
45
|
+
cornerOrientation: generateCube3PruningTable(cornerOrientation),
|
|
46
|
+
edgeOrientation: generateCube3PruningTable(edgeOrientation),
|
|
47
|
+
udSlice: generateCube3PruningTable(udSlice),
|
|
48
|
+
cornerOrientationEdgeOrientation: generateCube3CombinedPruningTable(cornerOrientation, edgeOrientation)
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
export function generateCube3SolverTables() {
|
|
53
|
+
const phase1Tables = generateCube3Phase1Tables();
|
|
54
|
+
const phase2Tables = generateCube3Phase2Tables();
|
|
55
|
+
return {
|
|
56
|
+
phase1Moves: CUBE3_PHASE1_MOVES,
|
|
57
|
+
phase2Moves: CUBE3_PHASE2_MOVES,
|
|
58
|
+
moveTables: {
|
|
59
|
+
cornerOrientation: phase1Tables.moveTables.cornerOrientation,
|
|
60
|
+
edgeOrientation: phase1Tables.moveTables.edgeOrientation,
|
|
61
|
+
udSlice: phase1Tables.moveTables.udSlice,
|
|
62
|
+
cornerPermutation: phase2Tables.moveTables.cornerPermutation,
|
|
63
|
+
udEdgePermutation: phase2Tables.moveTables.udEdgePermutation,
|
|
64
|
+
slicePermutation: phase2Tables.moveTables.slicePermutation
|
|
65
|
+
},
|
|
66
|
+
pruningTables: {
|
|
67
|
+
cornerOrientation: phase1Tables.pruningTables.cornerOrientation,
|
|
68
|
+
edgeOrientation: phase1Tables.pruningTables.edgeOrientation,
|
|
69
|
+
udSlice: phase1Tables.pruningTables.udSlice,
|
|
70
|
+
cornerOrientationEdgeOrientation: phase1Tables.pruningTables.cornerOrientationEdgeOrientation,
|
|
71
|
+
cornerPermutation: phase2Tables.pruningTables.cornerPermutation,
|
|
72
|
+
udEdgePermutation: phase2Tables.pruningTables.udEdgePermutation,
|
|
73
|
+
slicePermutation: phase2Tables.pruningTables.slicePermutation,
|
|
74
|
+
cornerPermutationSlicePermutation: phase2Tables.pruningTables.cornerPermutationSlicePermutation,
|
|
75
|
+
udEdgePermutationSlicePermutation: phase2Tables.pruningTables.udEdgePermutationSlicePermutation
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
export function generateCube3Phase2Tables() {
|
|
80
|
+
const cornerPermutation = generateCube3MoveTable("cornerPermutation", CUBE3_COORDINATE_RANGES.cornerPermutation, CUBE3_PHASE2_MOVES);
|
|
81
|
+
const udEdgePermutation = generateCube3MoveTable("udEdgePermutation", CUBE3_COORDINATE_RANGES.udEdgePermutation, CUBE3_PHASE2_MOVES);
|
|
82
|
+
const slicePermutation = generateCube3MoveTable("slicePermutation", CUBE3_COORDINATE_RANGES.slicePermutation, CUBE3_PHASE2_MOVES);
|
|
83
|
+
return {
|
|
84
|
+
phase2Moves: CUBE3_PHASE2_MOVES,
|
|
85
|
+
moveTables: {
|
|
86
|
+
cornerPermutation,
|
|
87
|
+
udEdgePermutation,
|
|
88
|
+
slicePermutation
|
|
89
|
+
},
|
|
90
|
+
pruningTables: {
|
|
91
|
+
cornerPermutation: generateCube3PruningTable(cornerPermutation),
|
|
92
|
+
udEdgePermutation: generateCube3PruningTable(udEdgePermutation),
|
|
93
|
+
slicePermutation: generateCube3PruningTable(slicePermutation),
|
|
94
|
+
cornerPermutationSlicePermutation: generateCube3CombinedPruningTable(cornerPermutation, slicePermutation),
|
|
95
|
+
udEdgePermutationSlicePermutation: generateCube3CombinedPruningTable(udEdgePermutation, slicePermutation)
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
export function generateCube3MoveTable(coordinate, range, moves) {
|
|
100
|
+
const values = new Int32Array(range * moves.length);
|
|
101
|
+
for (let value = 0; value < range; value += 1) {
|
|
102
|
+
for (let moveIndex = 0; moveIndex < moves.length; moveIndex += 1) {
|
|
103
|
+
values[value * moves.length + moveIndex] = moveCoordinate(coordinate, value, moves[moveIndex]);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
coordinate,
|
|
108
|
+
moves,
|
|
109
|
+
range,
|
|
110
|
+
solvedCoordinate: encodeCube3Coordinates(createSolvedCube3State())[coordinate],
|
|
111
|
+
values,
|
|
112
|
+
checksum: checksum(values)
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
export function generateCube3PruningTable(moveTable) {
|
|
116
|
+
const values = new Uint8Array(moveTable.range);
|
|
117
|
+
values.fill(255);
|
|
118
|
+
values[moveTable.solvedCoordinate] = 0;
|
|
119
|
+
const queue = new Int32Array(moveTable.range);
|
|
120
|
+
let read = 0;
|
|
121
|
+
let write = 1;
|
|
122
|
+
queue[0] = moveTable.solvedCoordinate;
|
|
123
|
+
let maxDepth = 0;
|
|
124
|
+
while (read < write) {
|
|
125
|
+
const current = queue[read];
|
|
126
|
+
read += 1;
|
|
127
|
+
const nextDepth = values[current] + 1;
|
|
128
|
+
for (let moveIndex = 0; moveIndex < moveTable.moves.length; moveIndex += 1) {
|
|
129
|
+
const next = moveTable.values[current * moveTable.moves.length + moveIndex];
|
|
130
|
+
if (values[next] !== 255) {
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
values[next] = nextDepth;
|
|
134
|
+
maxDepth = Math.max(maxDepth, nextDepth);
|
|
135
|
+
queue[write] = next;
|
|
136
|
+
write += 1;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return {
|
|
140
|
+
coordinate: moveTable.coordinate,
|
|
141
|
+
moves: moveTable.moves,
|
|
142
|
+
range: moveTable.range,
|
|
143
|
+
values,
|
|
144
|
+
checksum: checksum(values),
|
|
145
|
+
maxDepth
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
export function generateCube3CombinedPruningTable(tableA, tableB) {
|
|
149
|
+
const combinedRange = tableA.range * tableB.range;
|
|
150
|
+
const values = new Uint8Array(combinedRange);
|
|
151
|
+
values.fill(255);
|
|
152
|
+
const solvedCoordinate = tableA.solvedCoordinate * tableB.range + tableB.solvedCoordinate;
|
|
153
|
+
values[solvedCoordinate] = 0;
|
|
154
|
+
const queue = new Int32Array(combinedRange);
|
|
155
|
+
let read = 0;
|
|
156
|
+
let write = 1;
|
|
157
|
+
queue[0] = solvedCoordinate;
|
|
158
|
+
let maxDepth = 0;
|
|
159
|
+
while (read < write) {
|
|
160
|
+
const current = queue[read];
|
|
161
|
+
read += 1;
|
|
162
|
+
const nextDepth = values[current] + 1;
|
|
163
|
+
const currentA = Math.floor(current / tableB.range);
|
|
164
|
+
const currentB = current % tableB.range;
|
|
165
|
+
for (let moveIndex = 0; moveIndex < tableA.moves.length; moveIndex += 1) {
|
|
166
|
+
const nextA = tableA.values[currentA * tableA.moves.length + moveIndex];
|
|
167
|
+
const nextB = tableB.values[currentB * tableB.moves.length + moveIndex];
|
|
168
|
+
const next = nextA * tableB.range + nextB;
|
|
169
|
+
if (values[next] !== 255) {
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
values[next] = nextDepth;
|
|
173
|
+
maxDepth = Math.max(maxDepth, nextDepth);
|
|
174
|
+
queue[write] = next;
|
|
175
|
+
write += 1;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
const combinedName = `${tableA.coordinate}${tableB.coordinate.charAt(0).toUpperCase() + tableB.coordinate.slice(1)}`;
|
|
179
|
+
return {
|
|
180
|
+
coordinate: combinedName,
|
|
181
|
+
moves: tableA.moves,
|
|
182
|
+
range: combinedRange,
|
|
183
|
+
values,
|
|
184
|
+
checksum: checksum(values),
|
|
185
|
+
maxDepth
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
export function lookupCube3MoveTable(table, coordinate, move) {
|
|
189
|
+
const moveIndex = table.moves.indexOf(move);
|
|
190
|
+
if (moveIndex === -1) {
|
|
191
|
+
throw new RangeError(`Move ${move} is not part of ${table.coordinate} table.`);
|
|
192
|
+
}
|
|
193
|
+
return table.values[coordinate * table.moves.length + moveIndex];
|
|
194
|
+
}
|
|
195
|
+
export function checksum(values) {
|
|
196
|
+
let hash = 0x811c9dc5;
|
|
197
|
+
for (let index = 0; index < values.length; index += 1) {
|
|
198
|
+
hash ^= values[index];
|
|
199
|
+
hash = Math.imul(hash, 0x01000193);
|
|
200
|
+
}
|
|
201
|
+
return hash >>> 0;
|
|
202
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ScrambleOptions, ScrambleResult } from "../../../core/types.js";
|
|
2
|
+
export declare class Cube3WorkerPool {
|
|
3
|
+
private workers;
|
|
4
|
+
private available;
|
|
5
|
+
private pending;
|
|
6
|
+
private queue;
|
|
7
|
+
private nextId;
|
|
8
|
+
private terminated;
|
|
9
|
+
constructor(size?: number);
|
|
10
|
+
generate(options?: ScrambleOptions & {
|
|
11
|
+
skipValidation?: boolean;
|
|
12
|
+
}): Promise<ScrambleResult>;
|
|
13
|
+
generateBatch(count: number, deriveSeed: (index: number) => string | number | undefined): Promise<ScrambleResult[]>;
|
|
14
|
+
terminate(): Promise<number[]>;
|
|
15
|
+
private handleResponse;
|
|
16
|
+
private handleError;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=worker-pool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-pool.d.ts","sourceRoot":"","sources":["../../../../src/puzzles/cube3/solver/worker-pool.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAkC9E,qBAAa,eAAe;IAC1B,OAAO,CAAC,OAAO,CAAgB;IAC/B,OAAO,CAAC,SAAS,CAAgB;IACjC,OAAO,CAAC,OAAO,CAAkC;IACjD,OAAO,CAAC,KAAK,CAAoB;IACjC,OAAO,CAAC,MAAM,CAAK;IACnB,OAAO,CAAC,UAAU,CAAS;gBAEf,IAAI,GAAE,MAAgD;IAsBlE,QAAQ,CAAC,OAAO,GAAE,eAAe,GAAG;QAAE,cAAc,CAAC,EAAE,OAAO,CAAA;KAAO,GAAG,OAAO,CAAC,cAAc,CAAC;IAwB/F,aAAa,CACX,KAAK,EAAE,MAAM,EACb,UAAU,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,GAAG,MAAM,GAAG,SAAS,GACzD,OAAO,CAAC,cAAc,EAAE,CAAC;IAQ5B,SAAS,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAW9B,OAAO,CAAC,cAAc;IAqBtB,OAAO,CAAC,WAAW;CAMpB"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { Worker } from "node:worker_threads";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import os from "node:os";
|
|
5
|
+
function resolveWorkerPath() {
|
|
6
|
+
const currentFile = fileURLToPath(import.meta.url);
|
|
7
|
+
const currentDir = dirname(currentFile);
|
|
8
|
+
const isSource = currentFile.includes("/src/") || currentFile.includes("\\src\\");
|
|
9
|
+
const filename = isSource ? "worker.ts" : "worker.js";
|
|
10
|
+
return join(currentDir, filename);
|
|
11
|
+
}
|
|
12
|
+
function getWorkerExecArgv() {
|
|
13
|
+
const currentFile = fileURLToPath(import.meta.url);
|
|
14
|
+
const isSource = currentFile.includes("/src/") || currentFile.includes("\\src\\");
|
|
15
|
+
if (!isSource)
|
|
16
|
+
return [];
|
|
17
|
+
return ["--import", "tsx"];
|
|
18
|
+
}
|
|
19
|
+
export class Cube3WorkerPool {
|
|
20
|
+
workers = [];
|
|
21
|
+
available = [];
|
|
22
|
+
pending = new Map();
|
|
23
|
+
queue = [];
|
|
24
|
+
nextId = 0;
|
|
25
|
+
terminated = false;
|
|
26
|
+
constructor(size = Math.max(1, Math.min(8, getCpuCount()))) {
|
|
27
|
+
const workerPath = resolveWorkerPath();
|
|
28
|
+
const execArgv = getWorkerExecArgv();
|
|
29
|
+
for (let i = 0; i < size; i++) {
|
|
30
|
+
const worker = new Worker(workerPath, {
|
|
31
|
+
execArgv
|
|
32
|
+
});
|
|
33
|
+
worker.on("message", (response) => {
|
|
34
|
+
this.handleResponse(worker, response);
|
|
35
|
+
});
|
|
36
|
+
worker.on("error", (error) => {
|
|
37
|
+
this.handleError(error);
|
|
38
|
+
});
|
|
39
|
+
this.workers.push(worker);
|
|
40
|
+
this.available.push(worker);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
generate(options = {}) {
|
|
44
|
+
if (this.terminated) {
|
|
45
|
+
return Promise.reject(new Error("Worker pool has been terminated."));
|
|
46
|
+
}
|
|
47
|
+
const id = this.nextId++;
|
|
48
|
+
const task = {
|
|
49
|
+
id,
|
|
50
|
+
...(options.seed !== undefined ? { seed: options.seed } : {}),
|
|
51
|
+
...(options.skipValidation !== undefined ? { skipValidation: options.skipValidation } : {})
|
|
52
|
+
};
|
|
53
|
+
return new Promise((resolve, reject) => {
|
|
54
|
+
this.pending.set(id, { resolve, reject });
|
|
55
|
+
if (this.available.length > 0) {
|
|
56
|
+
const worker = this.available.pop();
|
|
57
|
+
worker.postMessage(task);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
this.queue.push(task);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
generateBatch(count, deriveSeed) {
|
|
65
|
+
const promises = Array.from({ length: count }, (_, index) => {
|
|
66
|
+
const seed = deriveSeed(index);
|
|
67
|
+
return this.generate(seed !== undefined ? { seed } : {});
|
|
68
|
+
});
|
|
69
|
+
return Promise.all(promises);
|
|
70
|
+
}
|
|
71
|
+
terminate() {
|
|
72
|
+
this.terminated = true;
|
|
73
|
+
this.queue = [];
|
|
74
|
+
this.pending.forEach(({ reject }) => {
|
|
75
|
+
reject(new Error("Worker pool terminated."));
|
|
76
|
+
});
|
|
77
|
+
this.pending.clear();
|
|
78
|
+
return Promise.all(this.workers.map((w) => w.terminate()));
|
|
79
|
+
}
|
|
80
|
+
handleResponse(worker, response) {
|
|
81
|
+
const pending = this.pending.get(response.id);
|
|
82
|
+
if (!pending)
|
|
83
|
+
return;
|
|
84
|
+
this.pending.delete(response.id);
|
|
85
|
+
if (response.error) {
|
|
86
|
+
pending.reject(new Error(response.error));
|
|
87
|
+
}
|
|
88
|
+
else if (response.result) {
|
|
89
|
+
pending.resolve(response.result);
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
pending.reject(new Error("Worker returned empty response."));
|
|
93
|
+
}
|
|
94
|
+
if (this.queue.length > 0) {
|
|
95
|
+
const nextTask = this.queue.shift();
|
|
96
|
+
worker.postMessage(nextTask);
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
this.available.push(worker);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
handleError(error) {
|
|
103
|
+
// If a worker crashes, reject all pending tasks
|
|
104
|
+
// In a production system we'd respawn the worker
|
|
105
|
+
this.pending.forEach(({ reject }) => reject(error));
|
|
106
|
+
this.pending.clear();
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function getCpuCount() {
|
|
110
|
+
try {
|
|
111
|
+
return os.cpus().length;
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
return 4;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../../../../src/puzzles/cube3/solver/worker.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { parentPort } from "node:worker_threads";
|
|
2
|
+
import { generateRandomCube3State } from "../random-state.js";
|
|
3
|
+
import { createSolvedCube3State, cube3StatesEqual, isSolvedCube3State } from "../state.js";
|
|
4
|
+
import { applyCube3Algorithm, formatCube3Algorithm, invertCube3Algorithm } from "../moves.js";
|
|
5
|
+
import { formatCube3Facelets, toCube3Facelets } from "../facelets.js";
|
|
6
|
+
import { solveCube3State } from "./index.js";
|
|
7
|
+
let tablesLoaded = false;
|
|
8
|
+
async function ensureTables() {
|
|
9
|
+
if (tablesLoaded)
|
|
10
|
+
return;
|
|
11
|
+
const { loadCube3SolverTables } = await import("./tables.js");
|
|
12
|
+
await loadCube3SolverTables();
|
|
13
|
+
tablesLoaded = true;
|
|
14
|
+
}
|
|
15
|
+
async function generate(task) {
|
|
16
|
+
await ensureTables();
|
|
17
|
+
const options = {
|
|
18
|
+
...(task.seed !== undefined ? { seed: task.seed } : {}),
|
|
19
|
+
...(task.skipValidation !== undefined ? { skipValidation: task.skipValidation } : {})
|
|
20
|
+
};
|
|
21
|
+
const state = generateRandomCube3State(options);
|
|
22
|
+
const solution = await solveCube3State(state);
|
|
23
|
+
const scrambleMoves = invertCube3Algorithm(solution.moves);
|
|
24
|
+
if (!options.skipValidation) {
|
|
25
|
+
const scrambledState = applyCube3Algorithm(createSolvedCube3State(), scrambleMoves);
|
|
26
|
+
if (!cube3StatesEqual(scrambledState, state)) {
|
|
27
|
+
throw new Error("Generated 3x3 scramble does not reproduce the target random state.");
|
|
28
|
+
}
|
|
29
|
+
if (!isSolvedCube3State(solution.state)) {
|
|
30
|
+
throw new Error("Generated 3x3 solution does not solve the target random state.");
|
|
31
|
+
}
|
|
32
|
+
if (scrambleMoves.length < 2) {
|
|
33
|
+
throw new Error("Generated 3x3 scramble is too short.");
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const facelets = toCube3Facelets(state);
|
|
37
|
+
const result = {
|
|
38
|
+
eventId: "333",
|
|
39
|
+
scramble: formatCube3Algorithm(scrambleMoves),
|
|
40
|
+
moves: scrambleMoves,
|
|
41
|
+
quality: "random-state",
|
|
42
|
+
generator: "cube3-two-phase",
|
|
43
|
+
metadata: {
|
|
44
|
+
state,
|
|
45
|
+
facelets,
|
|
46
|
+
faceletString: formatCube3Facelets(facelets),
|
|
47
|
+
solutionMoves: solution.moves,
|
|
48
|
+
solutionDepth: solution.depth,
|
|
49
|
+
phase1Depth: solution.phase1.depth,
|
|
50
|
+
phase2Depth: solution.phase2.depth,
|
|
51
|
+
visitedNodes: solution.visitedNodes
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
if (options.seed !== undefined) {
|
|
55
|
+
result.seed = options.seed;
|
|
56
|
+
}
|
|
57
|
+
return result;
|
|
58
|
+
}
|
|
59
|
+
if (!parentPort) {
|
|
60
|
+
throw new Error("This module must be run as a worker thread.");
|
|
61
|
+
}
|
|
62
|
+
parentPort.on("message", async (task) => {
|
|
63
|
+
try {
|
|
64
|
+
const result = await generate(task);
|
|
65
|
+
const response = { id: task.id, result };
|
|
66
|
+
parentPort.postMessage(response);
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
70
|
+
const response = { id: task.id, error: message };
|
|
71
|
+
parentPort.postMessage(response);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Cube3State } from "./types.js";
|
|
2
|
+
export declare function createSolvedCube3State(): Cube3State;
|
|
3
|
+
export declare function cloneCube3State(state: Cube3State): Cube3State;
|
|
4
|
+
export declare function cube3StatesEqual(left: Cube3State, right: Cube3State): boolean;
|
|
5
|
+
export declare function isSolvedCube3State(state: Cube3State): boolean;
|
|
6
|
+
//# sourceMappingURL=state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../../src/puzzles/cube3/state.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,wBAAgB,sBAAsB,IAAI,UAAU,CAWnD;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU,CAW7D;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,GAAG,OAAO,CAO7E;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAE7D"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { CORNER_COUNT, EDGE_COUNT } from "./types.js";
|
|
2
|
+
export function createSolvedCube3State() {
|
|
3
|
+
return {
|
|
4
|
+
corners: {
|
|
5
|
+
permutation: range(CORNER_COUNT),
|
|
6
|
+
orientation: Array(CORNER_COUNT).fill(0)
|
|
7
|
+
},
|
|
8
|
+
edges: {
|
|
9
|
+
permutation: range(EDGE_COUNT),
|
|
10
|
+
orientation: Array(EDGE_COUNT).fill(0)
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export function cloneCube3State(state) {
|
|
15
|
+
return {
|
|
16
|
+
corners: {
|
|
17
|
+
permutation: [...state.corners.permutation],
|
|
18
|
+
orientation: [...state.corners.orientation]
|
|
19
|
+
},
|
|
20
|
+
edges: {
|
|
21
|
+
permutation: [...state.edges.permutation],
|
|
22
|
+
orientation: [...state.edges.orientation]
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export function cube3StatesEqual(left, right) {
|
|
27
|
+
return (arraysEqual(left.corners.permutation, right.corners.permutation) &&
|
|
28
|
+
arraysEqual(left.corners.orientation, right.corners.orientation) &&
|
|
29
|
+
arraysEqual(left.edges.permutation, right.edges.permutation) &&
|
|
30
|
+
arraysEqual(left.edges.orientation, right.edges.orientation));
|
|
31
|
+
}
|
|
32
|
+
export function isSolvedCube3State(state) {
|
|
33
|
+
return cube3StatesEqual(state, createSolvedCube3State());
|
|
34
|
+
}
|
|
35
|
+
function range(length) {
|
|
36
|
+
return Array.from({ length }, (_, index) => index);
|
|
37
|
+
}
|
|
38
|
+
function arraysEqual(left, right) {
|
|
39
|
+
return left.length === right.length && left.every((value, index) => value === right[index]);
|
|
40
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subset-state.d.ts","sourceRoot":"","sources":["../../../src/puzzles/cube3/subset-state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAK7C,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,GAAG,UAAU,CAsBzF"}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { createSolvedCube3State } from "./state.js";
|
|
2
|
+
// The indices for the U layer pieces are 0, 1, 2, 3.
|
|
3
|
+
export function generateSubsetCube3State(subset, random) {
|
|
4
|
+
const state = createSolvedCube3State();
|
|
5
|
+
if (subset === "pll") {
|
|
6
|
+
shuffleULayerPermutations(state, random);
|
|
7
|
+
}
|
|
8
|
+
else if (subset === "oll" || subset === "ll") {
|
|
9
|
+
shuffleULayerPermutations(state, random);
|
|
10
|
+
randomizeULayerOrientations(state, random, true, true);
|
|
11
|
+
}
|
|
12
|
+
else if (subset === "zbll") {
|
|
13
|
+
shuffleULayerPermutations(state, random);
|
|
14
|
+
randomizeULayerOrientations(state, random, true, false); // corners only
|
|
15
|
+
}
|
|
16
|
+
else if (subset === "lsll") {
|
|
17
|
+
shuffleLSLL(state, random);
|
|
18
|
+
}
|
|
19
|
+
else if (subset === "f2l") {
|
|
20
|
+
shuffleF2L(state, random);
|
|
21
|
+
}
|
|
22
|
+
else if (subset === "cross") {
|
|
23
|
+
shuffleFullCube(state, random);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
throw new Error(`Subset "${subset}" is not supported yet.`);
|
|
27
|
+
}
|
|
28
|
+
return state;
|
|
29
|
+
}
|
|
30
|
+
function shuffleULayerPermutations(state, random) {
|
|
31
|
+
const cornerPerm = [0, 1, 2, 3];
|
|
32
|
+
const edgePerm = [0, 1, 2, 3];
|
|
33
|
+
shuffle(cornerPerm, random);
|
|
34
|
+
shuffle(edgePerm, random);
|
|
35
|
+
if (getParity(cornerPerm) !== getParity(edgePerm)) {
|
|
36
|
+
swap(edgePerm, 0, 1);
|
|
37
|
+
}
|
|
38
|
+
for (let i = 0; i < 4; i++) {
|
|
39
|
+
state.corners.permutation[i] = cornerPerm[i];
|
|
40
|
+
state.edges.permutation[i] = edgePerm[i];
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function randomizeULayerOrientations(state, random, corners, edges) {
|
|
44
|
+
if (corners) {
|
|
45
|
+
let sum = 0;
|
|
46
|
+
for (let i = 0; i < 3; i++) {
|
|
47
|
+
const o = random.nextInt(3);
|
|
48
|
+
state.corners.orientation[i] = o;
|
|
49
|
+
sum += o;
|
|
50
|
+
}
|
|
51
|
+
state.corners.orientation[3] = (3 - (sum % 3)) % 3;
|
|
52
|
+
}
|
|
53
|
+
if (edges) {
|
|
54
|
+
let sum = 0;
|
|
55
|
+
for (let i = 0; i < 3; i++) {
|
|
56
|
+
const o = random.nextInt(2);
|
|
57
|
+
state.edges.orientation[i] = o;
|
|
58
|
+
sum += o;
|
|
59
|
+
}
|
|
60
|
+
state.edges.orientation[3] = (2 - (sum % 2)) % 2;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function shuffle(array, random) {
|
|
64
|
+
for (let i = array.length - 1; i > 0; i--) {
|
|
65
|
+
const j = random.nextInt(i + 1);
|
|
66
|
+
swap(array, i, j);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function swap(array, i, j) {
|
|
70
|
+
const temp = array[i];
|
|
71
|
+
array[i] = array[j];
|
|
72
|
+
array[j] = temp;
|
|
73
|
+
}
|
|
74
|
+
function getParity(array) {
|
|
75
|
+
let inversions = 0;
|
|
76
|
+
for (let i = 0; i < array.length; i++) {
|
|
77
|
+
for (let j = i + 1; j < array.length; j++) {
|
|
78
|
+
if (array[i] > array[j]) {
|
|
79
|
+
inversions++;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return inversions % 2;
|
|
84
|
+
}
|
|
85
|
+
function shuffleLSLL(state, random) {
|
|
86
|
+
const cornerPerm = [0, 1, 2, 3, 4];
|
|
87
|
+
const edgePerm = [0, 1, 2, 3, 8];
|
|
88
|
+
shuffle(cornerPerm, random);
|
|
89
|
+
shuffle(edgePerm, random);
|
|
90
|
+
if (getParity(cornerPerm) !== getParity(edgePerm)) {
|
|
91
|
+
swap(edgePerm, 0, 1);
|
|
92
|
+
}
|
|
93
|
+
const cornerIndices = [0, 1, 2, 3, 4];
|
|
94
|
+
for (let i = 0; i < cornerIndices.length; i++) {
|
|
95
|
+
const idx = cornerIndices[i];
|
|
96
|
+
state.corners.permutation[idx] = cornerPerm[i];
|
|
97
|
+
state.corners.orientation[idx] = random.nextInt(3);
|
|
98
|
+
}
|
|
99
|
+
let cornerSum = 0;
|
|
100
|
+
for (let i = 0; i < 8; i++)
|
|
101
|
+
cornerSum += state.corners.orientation[i];
|
|
102
|
+
state.corners.orientation[4] = (state.corners.orientation[4] + (3 - (cornerSum % 3))) % 3;
|
|
103
|
+
const edgeIndices = [0, 1, 2, 3, 8];
|
|
104
|
+
for (let i = 0; i < edgeIndices.length; i++) {
|
|
105
|
+
const idx = edgeIndices[i];
|
|
106
|
+
state.edges.permutation[idx] = edgePerm[i];
|
|
107
|
+
state.edges.orientation[idx] = random.nextInt(2);
|
|
108
|
+
}
|
|
109
|
+
let edgeSum = 0;
|
|
110
|
+
for (let i = 0; i < 12; i++)
|
|
111
|
+
edgeSum += state.edges.orientation[i];
|
|
112
|
+
state.edges.orientation[8] = (state.edges.orientation[8] + (2 - (edgeSum % 2))) % 2;
|
|
113
|
+
}
|
|
114
|
+
function shuffleF2L(state, random) {
|
|
115
|
+
const cornerPerm = [0, 1, 2, 3, 4, 5, 6, 7];
|
|
116
|
+
const edgePerm = [0, 1, 2, 3, 8, 9, 10, 11];
|
|
117
|
+
shuffle(cornerPerm, random);
|
|
118
|
+
shuffle(edgePerm, random);
|
|
119
|
+
if (getParity(cornerPerm) !== getParity(edgePerm)) {
|
|
120
|
+
swap(edgePerm, 0, 1);
|
|
121
|
+
}
|
|
122
|
+
const edgeIndices = [0, 1, 2, 3, 8, 9, 10, 11];
|
|
123
|
+
for (let i = 0; i < 8; i++) {
|
|
124
|
+
state.corners.permutation[i] = cornerPerm[i];
|
|
125
|
+
state.corners.orientation[i] = random.nextInt(3);
|
|
126
|
+
const idx = edgeIndices[i];
|
|
127
|
+
state.edges.permutation[idx] = edgePerm[i];
|
|
128
|
+
state.edges.orientation[idx] = random.nextInt(2);
|
|
129
|
+
}
|
|
130
|
+
let cornerSum = 0;
|
|
131
|
+
for (let i = 0; i < 8; i++)
|
|
132
|
+
cornerSum += state.corners.orientation[i];
|
|
133
|
+
state.corners.orientation[0] = (state.corners.orientation[0] + (3 - (cornerSum % 3))) % 3;
|
|
134
|
+
let edgeSum = 0;
|
|
135
|
+
for (let i = 0; i < 12; i++)
|
|
136
|
+
edgeSum += state.edges.orientation[i];
|
|
137
|
+
state.edges.orientation[0] = (state.edges.orientation[0] + (2 - (edgeSum % 2))) % 2;
|
|
138
|
+
}
|
|
139
|
+
function shuffleFullCube(state, random) {
|
|
140
|
+
const cornerPerm = [0, 1, 2, 3, 4, 5, 6, 7];
|
|
141
|
+
const edgePerm = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
|
|
142
|
+
shuffle(cornerPerm, random);
|
|
143
|
+
shuffle(edgePerm, random);
|
|
144
|
+
if (getParity(cornerPerm) !== getParity(edgePerm)) {
|
|
145
|
+
swap(edgePerm, 0, 1);
|
|
146
|
+
}
|
|
147
|
+
for (let i = 0; i < 8; i++) {
|
|
148
|
+
state.corners.permutation[i] = cornerPerm[i];
|
|
149
|
+
state.corners.orientation[i] = random.nextInt(3);
|
|
150
|
+
}
|
|
151
|
+
for (let i = 0; i < 12; i++) {
|
|
152
|
+
state.edges.permutation[i] = edgePerm[i];
|
|
153
|
+
state.edges.orientation[i] = random.nextInt(2);
|
|
154
|
+
}
|
|
155
|
+
let cornerSum = 0;
|
|
156
|
+
for (let i = 0; i < 8; i++)
|
|
157
|
+
cornerSum += state.corners.orientation[i];
|
|
158
|
+
state.corners.orientation[0] = (state.corners.orientation[0] + (3 - (cornerSum % 3))) % 3;
|
|
159
|
+
let edgeSum = 0;
|
|
160
|
+
for (let i = 0; i < 12; i++)
|
|
161
|
+
edgeSum += state.edges.orientation[i];
|
|
162
|
+
state.edges.orientation[0] = (state.edges.orientation[0] + (2 - (edgeSum % 2))) % 2;
|
|
163
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export declare const CORNER_COUNT = 8;
|
|
2
|
+
export declare const EDGE_COUNT = 12;
|
|
3
|
+
export type Cube3FaceMove = "U" | "D" | "R" | "L" | "F" | "B";
|
|
4
|
+
export type Cube3Face = "U" | "R" | "F" | "D" | "L" | "B";
|
|
5
|
+
export type Cube3Sticker = Cube3Face;
|
|
6
|
+
export type Cube3MoveSuffix = "" | "2" | "'";
|
|
7
|
+
export type Cube3Move = `${Cube3FaceMove}${Cube3MoveSuffix}`;
|
|
8
|
+
export interface Cube3State {
|
|
9
|
+
corners: {
|
|
10
|
+
permutation: number[];
|
|
11
|
+
orientation: number[];
|
|
12
|
+
};
|
|
13
|
+
edges: {
|
|
14
|
+
permutation: number[];
|
|
15
|
+
orientation: number[];
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export interface Cube3ValidationResult {
|
|
19
|
+
valid: boolean;
|
|
20
|
+
errors: string[];
|
|
21
|
+
}
|
|
22
|
+
export interface Cube3RandomStateOptions {
|
|
23
|
+
seed?: string | number;
|
|
24
|
+
rejectTrivial?: boolean;
|
|
25
|
+
subset?: string;
|
|
26
|
+
}
|
|
27
|
+
export type Cube3Facelets = Record<Cube3Face, Cube3Sticker[]>;
|
|
28
|
+
export declare const CUBE3_MOVES: readonly Cube3Move[];
|
|
29
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/puzzles/cube3/types.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,YAAY,IAAI,CAAC;AAC9B,eAAO,MAAM,UAAU,KAAK,CAAC;AAE7B,MAAM,MAAM,aAAa,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;AAC9D,MAAM,MAAM,SAAS,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;AAC1D,MAAM,MAAM,YAAY,GAAG,SAAS,CAAC;AACrC,MAAM,MAAM,eAAe,GAAG,EAAE,GAAG,GAAG,GAAG,GAAG,CAAC;AAC7C,MAAM,MAAM,SAAS,GAAG,GAAG,aAAa,GAAG,eAAe,EAAE,CAAC;AAE7D,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE;QACP,WAAW,EAAE,MAAM,EAAE,CAAC;QACtB,WAAW,EAAE,MAAM,EAAE,CAAC;KACvB,CAAC;IACF,KAAK,EAAE;QACL,WAAW,EAAE,MAAM,EAAE,CAAC;QACtB,WAAW,EAAE,MAAM,EAAE,CAAC;KACvB,CAAC;CACH;AAED,MAAM,WAAW,qBAAqB;IACpC,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAED,MAAM,WAAW,uBAAuB;IACtC,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,SAAS,EAAE,YAAY,EAAE,CAAC,CAAC;AAE9D,eAAO,MAAM,WAAW,EAAE,SAAS,SAAS,EAmB3C,CAAC"}
|