@cubingcenter/scrambler 0.5.3 → 0.6.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 +24 -9
- package/dist/cli/index.js +0 -0
- package/dist/core/api.d.ts.map +1 -1
- package/dist/core/api.js +11 -1
- package/dist/core/types.d.ts +1 -1
- package/dist/core/types.d.ts.map +1 -1
- package/dist/puzzles/cube4/index.d.ts +4 -2
- package/dist/puzzles/cube4/index.d.ts.map +1 -1
- package/dist/puzzles/cube4/index.js +3 -1
- package/dist/puzzles/cube4/random-state.d.ts +16 -0
- package/dist/puzzles/cube4/random-state.d.ts.map +1 -0
- package/dist/puzzles/cube4/random-state.js +76 -0
- package/dist/puzzles/cube4/reduction/browser-loader.d.ts +18 -0
- package/dist/puzzles/cube4/reduction/browser-loader.d.ts.map +1 -0
- package/dist/puzzles/cube4/reduction/browser-loader.js +95 -0
- package/dist/puzzles/cube4/reduction/center1.d.ts +65 -0
- package/dist/puzzles/cube4/reduction/center1.d.ts.map +1 -0
- package/dist/puzzles/cube4/reduction/center1.js +245 -0
- package/dist/puzzles/cube4/reduction/center2.d.ts +91 -0
- package/dist/puzzles/cube4/reduction/center2.d.ts.map +1 -0
- package/dist/puzzles/cube4/reduction/center2.js +449 -0
- package/dist/puzzles/cube4/reduction/center3.d.ts +47 -0
- package/dist/puzzles/cube4/reduction/center3.d.ts.map +1 -0
- package/dist/puzzles/cube4/reduction/center3.js +278 -0
- package/dist/puzzles/cube4/reduction/edge3.d.ts +100 -0
- package/dist/puzzles/cube4/reduction/edge3.d.ts.map +1 -0
- package/dist/puzzles/cube4/reduction/edge3.js +511 -0
- package/dist/puzzles/cube4/reduction/generated/center1-distance.bin +1 -0
- package/dist/puzzles/cube4/reduction/generated/center1-manifest.json +46 -0
- package/dist/puzzles/cube4/reduction/generated/center1-move-maps.bin +0 -0
- package/dist/puzzles/cube4/reduction/generated/center2-ct-move.bin +0 -0
- package/dist/puzzles/cube4/reduction/generated/center2-manifest.json +87 -0
- package/dist/puzzles/cube4/reduction/generated/center2-pruning.bin +1 -0
- package/dist/puzzles/cube4/reduction/generated/center2-rl-move.bin +0 -0
- package/dist/puzzles/cube4/reduction/generated/center3-manifest.json +40 -0
- package/dist/puzzles/cube4/reduction/generated/center3-move.bin +0 -0
- package/dist/puzzles/cube4/reduction/generated/center3-pruning.bin +0 -0
- package/dist/puzzles/cube4/reduction/generated/edge3-distances.bin +1 -0
- package/dist/puzzles/cube4/reduction/generated/edge3-manifest.json +12 -0
- package/dist/puzzles/cube4/reduction/geometry.d.ts +33 -0
- package/dist/puzzles/cube4/reduction/geometry.d.ts.map +1 -0
- package/dist/puzzles/cube4/reduction/geometry.js +302 -0
- package/dist/puzzles/cube4/reduction/node-loader.d.ts +17 -0
- package/dist/puzzles/cube4/reduction/node-loader.d.ts.map +1 -0
- package/dist/puzzles/cube4/reduction/node-loader.js +98 -0
- package/dist/puzzles/cube4/reduction/pairing-coordinate.d.ts +130 -0
- package/dist/puzzles/cube4/reduction/pairing-coordinate.d.ts.map +1 -0
- package/dist/puzzles/cube4/reduction/pairing-coordinate.js +281 -0
- package/dist/puzzles/cube4/reduction/phase3-search.d.ts +42 -0
- package/dist/puzzles/cube4/reduction/phase3-search.d.ts.map +1 -0
- package/dist/puzzles/cube4/reduction/phase3-search.js +133 -0
- package/dist/puzzles/cube4/reduction/phase3.d.ts +34 -0
- package/dist/puzzles/cube4/reduction/phase3.d.ts.map +1 -0
- package/dist/puzzles/cube4/reduction/phase3.js +83 -0
- package/dist/puzzles/cube4/reduction/phase4.d.ts +35 -0
- package/dist/puzzles/cube4/reduction/phase4.d.ts.map +1 -0
- package/dist/puzzles/cube4/reduction/phase4.js +82 -0
- package/dist/puzzles/cube4/reduction/solve.d.ts +31 -0
- package/dist/puzzles/cube4/reduction/solve.d.ts.map +1 -0
- package/dist/puzzles/cube4/reduction/solve.js +311 -0
- package/dist/puzzles/cube4/scrambler.d.ts +9 -1
- package/dist/puzzles/cube4/scrambler.d.ts.map +1 -1
- package/dist/puzzles/cube4/scrambler.js +123 -81
- package/dist/puzzles/cube4/types.d.ts +6 -0
- package/dist/puzzles/cube4/types.d.ts.map +1 -1
- package/dist/puzzles/cube4/validation.d.ts +6 -0
- package/dist/puzzles/cube4/validation.d.ts.map +1 -0
- package/dist/puzzles/cube4/validation.js +91 -0
- package/dist/puzzles/fto/coordinates.d.ts +53 -0
- package/dist/puzzles/fto/coordinates.d.ts.map +1 -0
- package/dist/puzzles/fto/coordinates.js +228 -0
- package/dist/puzzles/fto/facelets.d.ts +6 -0
- package/dist/puzzles/fto/facelets.d.ts.map +1 -0
- package/dist/puzzles/fto/facelets.js +99 -0
- package/dist/puzzles/fto/index.d.ts +12 -0
- package/dist/puzzles/fto/index.d.ts.map +1 -0
- package/dist/puzzles/fto/index.js +13 -0
- package/dist/puzzles/fto/moves.d.ts +12 -0
- package/dist/puzzles/fto/moves.d.ts.map +1 -0
- package/dist/puzzles/fto/moves.js +115 -0
- package/dist/puzzles/fto/random-state.d.ts +17 -0
- package/dist/puzzles/fto/random-state.d.ts.map +1 -0
- package/dist/puzzles/fto/random-state.js +40 -0
- package/dist/puzzles/fto/scrambler.d.ts +6 -0
- package/dist/puzzles/fto/scrambler.d.ts.map +1 -0
- package/dist/puzzles/fto/scrambler.js +49 -0
- package/dist/puzzles/fto/solver/engine.d.ts +18 -0
- package/dist/puzzles/fto/solver/engine.d.ts.map +1 -0
- package/dist/puzzles/fto/solver/engine.js +1168 -0
- package/dist/puzzles/fto/solver/index.d.ts +2 -0
- package/dist/puzzles/fto/solver/index.d.ts.map +1 -0
- package/dist/puzzles/fto/solver/index.js +1 -0
- package/dist/puzzles/fto/state.d.ts +16 -0
- package/dist/puzzles/fto/state.d.ts.map +1 -0
- package/dist/puzzles/fto/state.js +61 -0
- package/dist/puzzles/fto/types.d.ts +32 -0
- package/dist/puzzles/fto/types.d.ts.map +1 -0
- package/dist/puzzles/fto/types.js +46 -0
- package/dist/puzzles/fto/validation.d.ts +19 -0
- package/dist/puzzles/fto/validation.d.ts.map +1 -0
- package/dist/puzzles/fto/validation.js +143 -0
- package/dist/puzzles/index.d.ts +2 -0
- package/dist/puzzles/index.d.ts.map +1 -1
- package/dist/puzzles/index.js +6 -0
- package/dist/puzzles/skewb/index.d.ts +1 -1
- package/dist/puzzles/skewb/index.d.ts.map +1 -1
- package/dist/puzzles/skewb/index.js +1 -1
- package/dist/puzzles/skewb/random-state.d.ts.map +1 -1
- package/dist/puzzles/skewb/random-state.js +4 -1
- package/dist/puzzles/sq1/facelets.d.ts +12 -0
- package/dist/puzzles/sq1/facelets.d.ts.map +1 -0
- package/dist/puzzles/sq1/facelets.js +26 -0
- package/dist/puzzles/sq1/index.d.ts +10 -0
- package/dist/puzzles/sq1/index.d.ts.map +1 -0
- package/dist/puzzles/sq1/index.js +11 -0
- package/dist/puzzles/sq1/moves.d.ts +55 -0
- package/dist/puzzles/sq1/moves.d.ts.map +1 -0
- package/dist/puzzles/sq1/moves.js +220 -0
- package/dist/puzzles/sq1/random-state.d.ts +6 -0
- package/dist/puzzles/sq1/random-state.d.ts.map +1 -0
- package/dist/puzzles/sq1/random-state.js +49 -0
- package/dist/puzzles/sq1/scrambler.d.ts +10 -0
- package/dist/puzzles/sq1/scrambler.d.ts.map +1 -0
- package/dist/puzzles/sq1/scrambler.js +90 -0
- package/dist/puzzles/sq1/solver/browser-loader.d.ts +5 -0
- package/dist/puzzles/sq1/solver/browser-loader.d.ts.map +1 -0
- package/dist/puzzles/sq1/solver/browser-loader.js +92 -0
- package/dist/puzzles/sq1/solver/full-cube.d.ts +53 -0
- package/dist/puzzles/sq1/solver/full-cube.d.ts.map +1 -0
- package/dist/puzzles/sq1/solver/full-cube.js +281 -0
- package/dist/puzzles/sq1/solver/generated/manifest.json +50 -0
- package/dist/puzzles/sq1/solver/generated/shape-bottom-move.bin +0 -0
- package/dist/puzzles/sq1/solver/generated/shape-idx.bin +0 -0
- package/dist/puzzles/sq1/solver/generated/shape-prun.bin +0 -0
- package/dist/puzzles/sq1/solver/generated/shape-top-move.bin +0 -0
- package/dist/puzzles/sq1/solver/generated/shape-twist-move.bin +0 -0
- package/dist/puzzles/sq1/solver/generated/square-bottom-move.bin +0 -0
- package/dist/puzzles/sq1/solver/generated/square-prun.bin +0 -0
- package/dist/puzzles/sq1/solver/generated/square-top-move.bin +0 -0
- package/dist/puzzles/sq1/solver/generated/square-twist-move.bin +0 -0
- package/dist/puzzles/sq1/solver/index.d.ts +5 -0
- package/dist/puzzles/sq1/solver/index.d.ts.map +1 -0
- package/dist/puzzles/sq1/solver/index.js +4 -0
- package/dist/puzzles/sq1/solver/node-loader.d.ts +4 -0
- package/dist/puzzles/sq1/solver/node-loader.d.ts.map +1 -0
- package/dist/puzzles/sq1/solver/node-loader.js +113 -0
- package/dist/puzzles/sq1/solver/search.d.ts +27 -0
- package/dist/puzzles/sq1/solver/search.d.ts.map +1 -0
- package/dist/puzzles/sq1/solver/search.js +225 -0
- package/dist/puzzles/sq1/solver/shape.d.ts +22 -0
- package/dist/puzzles/sq1/solver/shape.d.ts.map +1 -0
- package/dist/puzzles/sq1/solver/shape.js +185 -0
- package/dist/puzzles/sq1/solver/square.d.ts +10 -0
- package/dist/puzzles/sq1/solver/square.d.ts.map +1 -0
- package/dist/puzzles/sq1/solver/square.js +90 -0
- package/dist/puzzles/sq1/solver/table-metadata.d.ts +48 -0
- package/dist/puzzles/sq1/solver/table-metadata.d.ts.map +1 -0
- package/dist/puzzles/sq1/solver/table-metadata.js +47 -0
- package/dist/puzzles/sq1/solver/tables.d.ts +17 -0
- package/dist/puzzles/sq1/solver/tables.d.ts.map +1 -0
- package/dist/puzzles/sq1/solver/tables.js +66 -0
- package/dist/puzzles/sq1/state.d.ts +10 -0
- package/dist/puzzles/sq1/state.d.ts.map +1 -0
- package/dist/puzzles/sq1/state.js +74 -0
- package/dist/puzzles/sq1/types.d.ts +32 -0
- package/dist/puzzles/sq1/types.d.ts.map +1 -0
- package/dist/puzzles/sq1/types.js +1 -0
- package/dist/puzzles/sq1/validation.d.ts +7 -0
- package/dist/puzzles/sq1/validation.d.ts.map +1 -0
- package/dist/puzzles/sq1/validation.js +64 -0
- package/dist/random/prng.d.ts.map +1 -1
- package/dist/random/prng.js +9 -4
- package/dist-cjs/core/api.js +11 -1
- package/dist-cjs/puzzles/cube4/index.js +11 -4
- package/dist-cjs/puzzles/cube4/random-state.js +79 -0
- package/dist-cjs/puzzles/cube4/reduction/browser-loader.js +100 -0
- package/dist-cjs/puzzles/cube4/reduction/center1.js +258 -0
- package/dist-cjs/puzzles/cube4/reduction/center2.js +462 -0
- package/dist-cjs/puzzles/cube4/reduction/center3.js +284 -0
- package/dist-cjs/puzzles/cube4/reduction/edge3.js +522 -0
- package/dist-cjs/puzzles/cube4/reduction/generated/center1-distance.bin +1 -0
- package/dist-cjs/puzzles/cube4/reduction/generated/center1-manifest.json +46 -0
- package/dist-cjs/puzzles/cube4/reduction/generated/center1-move-maps.bin +0 -0
- package/dist-cjs/puzzles/cube4/reduction/generated/center2-ct-move.bin +0 -0
- package/dist-cjs/puzzles/cube4/reduction/generated/center2-manifest.json +87 -0
- package/dist-cjs/puzzles/cube4/reduction/generated/center2-pruning.bin +1 -0
- package/dist-cjs/puzzles/cube4/reduction/generated/center2-rl-move.bin +0 -0
- package/dist-cjs/puzzles/cube4/reduction/generated/center3-manifest.json +40 -0
- package/dist-cjs/puzzles/cube4/reduction/generated/center3-move.bin +0 -0
- package/dist-cjs/puzzles/cube4/reduction/generated/center3-pruning.bin +0 -0
- package/dist-cjs/puzzles/cube4/reduction/generated/edge3-distances.bin +1 -0
- package/dist-cjs/puzzles/cube4/reduction/generated/edge3-manifest.json +12 -0
- package/dist-cjs/puzzles/cube4/reduction/geometry.js +308 -0
- package/dist-cjs/puzzles/cube4/reduction/node-loader.js +104 -0
- package/dist-cjs/puzzles/cube4/reduction/pairing-coordinate.js +294 -0
- package/dist-cjs/puzzles/cube4/reduction/phase3-search.js +138 -0
- package/dist-cjs/puzzles/cube4/reduction/phase3.js +86 -0
- package/dist-cjs/puzzles/cube4/reduction/phase4.js +87 -0
- package/dist-cjs/puzzles/cube4/reduction/solve.js +314 -0
- package/dist-cjs/puzzles/cube4/scrambler.js +122 -79
- package/dist-cjs/puzzles/cube4/validation.js +97 -0
- package/dist-cjs/puzzles/fto/coordinates.js +240 -0
- package/dist-cjs/puzzles/fto/facelets.js +104 -0
- package/dist-cjs/puzzles/fto/index.js +68 -0
- package/dist-cjs/puzzles/fto/moves.js +126 -0
- package/dist-cjs/puzzles/fto/random-state.js +43 -0
- package/dist-cjs/puzzles/fto/scrambler.js +53 -0
- package/dist-cjs/puzzles/fto/solver/engine.js +1175 -0
- package/dist-cjs/puzzles/fto/solver/index.js +9 -0
- package/dist-cjs/puzzles/fto/state.js +69 -0
- package/dist-cjs/puzzles/fto/types.js +49 -0
- package/dist-cjs/puzzles/fto/validation.js +147 -0
- package/dist-cjs/puzzles/index.js +7 -1
- package/dist-cjs/puzzles/skewb/index.js +2 -1
- package/dist-cjs/puzzles/skewb/random-state.js +4 -1
- package/dist-cjs/puzzles/sq1/facelets.js +30 -0
- package/dist-cjs/puzzles/sq1/index.js +52 -0
- package/dist-cjs/puzzles/sq1/moves.js +234 -0
- package/dist-cjs/puzzles/sq1/random-state.js +52 -0
- package/dist-cjs/puzzles/sq1/scrambler.js +95 -0
- package/dist-cjs/puzzles/sq1/solver/browser-loader.js +97 -0
- package/dist-cjs/puzzles/sq1/solver/full-cube.js +289 -0
- package/dist-cjs/puzzles/sq1/solver/generated/manifest.json +50 -0
- package/dist-cjs/puzzles/sq1/solver/generated/shape-bottom-move.bin +0 -0
- package/dist-cjs/puzzles/sq1/solver/generated/shape-idx.bin +0 -0
- package/dist-cjs/puzzles/sq1/solver/generated/shape-prun.bin +0 -0
- package/dist-cjs/puzzles/sq1/solver/generated/shape-top-move.bin +0 -0
- package/dist-cjs/puzzles/sq1/solver/generated/shape-twist-move.bin +0 -0
- package/dist-cjs/puzzles/sq1/solver/generated/square-bottom-move.bin +0 -0
- package/dist-cjs/puzzles/sq1/solver/generated/square-prun.bin +0 -0
- package/dist-cjs/puzzles/sq1/solver/generated/square-top-move.bin +0 -0
- package/dist-cjs/puzzles/sq1/solver/generated/square-twist-move.bin +0 -0
- package/dist-cjs/puzzles/sq1/solver/index.js +18 -0
- package/dist-cjs/puzzles/sq1/solver/node-loader.js +120 -0
- package/dist-cjs/puzzles/sq1/solver/search.js +229 -0
- package/dist-cjs/puzzles/sq1/solver/shape.js +191 -0
- package/dist-cjs/puzzles/sq1/solver/square.js +93 -0
- package/dist-cjs/puzzles/sq1/solver/table-metadata.js +50 -0
- package/dist-cjs/puzzles/sq1/solver/tables.js +106 -0
- package/dist-cjs/puzzles/sq1/state.js +81 -0
- package/dist-cjs/puzzles/sq1/types.js +2 -0
- package/dist-cjs/puzzles/sq1/validation.js +68 -0
- package/dist-cjs/random/prng.js +9 -4
- package/package.json +43 -14
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.readGeneratedSquare1SolverTables = readGeneratedSquare1SolverTables;
|
|
7
|
+
exports.checksum = checksum;
|
|
8
|
+
const node_fs_1 = require("node:fs");
|
|
9
|
+
const node_module_1 = require("node:module");
|
|
10
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
11
|
+
const table_metadata_js_1 = require("./table-metadata.js");
|
|
12
|
+
const GENERATED_DIRECTORY = "puzzles/sq1/solver/generated";
|
|
13
|
+
function readGeneratedSquare1SolverTables() {
|
|
14
|
+
const assetDirectory = resolveGeneratedAssetDirectory();
|
|
15
|
+
const manifest = JSON.parse((0, node_fs_1.readFileSync)(node_path_1.default.join(assetDirectory, "manifest.json"), "utf8"));
|
|
16
|
+
if (manifest.version !== 1) {
|
|
17
|
+
throw new Error(`Unsupported square1 solver table manifest version: ${manifest.version}`);
|
|
18
|
+
}
|
|
19
|
+
const shapeIdx = readInt32Table(assetDirectory, manifest.files.shapeIdx, table_metadata_js_1.SQ1_SOLVER_TABLE_METADATA.shapeIdx.checksum);
|
|
20
|
+
const shapePrun = readInt8Table(assetDirectory, manifest.files.shapePrun, table_metadata_js_1.SQ1_SOLVER_TABLE_METADATA.shapePrun.checksum);
|
|
21
|
+
const shapeTopMove = readInt32Table(assetDirectory, manifest.files.shapeTopMove, table_metadata_js_1.SQ1_SOLVER_TABLE_METADATA.shapeTopMove.checksum);
|
|
22
|
+
const shapeBottomMove = readInt32Table(assetDirectory, manifest.files.shapeBottomMove, table_metadata_js_1.SQ1_SOLVER_TABLE_METADATA.shapeBottomMove.checksum);
|
|
23
|
+
const shapeTwistMove = readInt32Table(assetDirectory, manifest.files.shapeTwistMove, table_metadata_js_1.SQ1_SOLVER_TABLE_METADATA.shapeTwistMove.checksum);
|
|
24
|
+
const squareTwistMove = readUint16Table(assetDirectory, manifest.files.squareTwistMove, table_metadata_js_1.SQ1_SOLVER_TABLE_METADATA.squareTwistMove.checksum);
|
|
25
|
+
const squareTopMove = readUint16Table(assetDirectory, manifest.files.squareTopMove, table_metadata_js_1.SQ1_SOLVER_TABLE_METADATA.squareTopMove.checksum);
|
|
26
|
+
const squareBottomMove = readUint16Table(assetDirectory, manifest.files.squareBottomMove, table_metadata_js_1.SQ1_SOLVER_TABLE_METADATA.squareBottomMove.checksum);
|
|
27
|
+
const squarePrun = readInt8Table(assetDirectory, manifest.files.squarePrun, table_metadata_js_1.SQ1_SOLVER_TABLE_METADATA.squarePrun.checksum);
|
|
28
|
+
return {
|
|
29
|
+
shapeIdx,
|
|
30
|
+
shapePrun,
|
|
31
|
+
shapeTopMove,
|
|
32
|
+
shapeBottomMove,
|
|
33
|
+
shapeTwistMove,
|
|
34
|
+
squareTwistMove,
|
|
35
|
+
squareTopMove,
|
|
36
|
+
squareBottomMove,
|
|
37
|
+
squarePrun
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function readInt32Table(assetDirectory, entry, expectedChecksum) {
|
|
41
|
+
const buffer = (0, node_fs_1.readFileSync)(node_path_1.default.join(assetDirectory, entry.file));
|
|
42
|
+
if (buffer.length !== entry.entries * 4) {
|
|
43
|
+
throw new Error(`Invalid byte size for ${entry.file}`);
|
|
44
|
+
}
|
|
45
|
+
const values = new Int32Array(entry.entries);
|
|
46
|
+
for (let index = 0; index < values.length; index += 1) {
|
|
47
|
+
values[index] = buffer.readInt32LE(index * 4);
|
|
48
|
+
}
|
|
49
|
+
if (expectedChecksum !== 0) {
|
|
50
|
+
assertChecksum(entry.file, checksum(values), expectedChecksum);
|
|
51
|
+
}
|
|
52
|
+
return values;
|
|
53
|
+
}
|
|
54
|
+
function readUint16Table(assetDirectory, entry, expectedChecksum) {
|
|
55
|
+
const buffer = (0, node_fs_1.readFileSync)(node_path_1.default.join(assetDirectory, entry.file));
|
|
56
|
+
if (buffer.length !== entry.entries * 2) {
|
|
57
|
+
throw new Error(`Invalid byte size for ${entry.file}`);
|
|
58
|
+
}
|
|
59
|
+
const values = new Uint16Array(entry.entries);
|
|
60
|
+
for (let index = 0; index < values.length; index += 1) {
|
|
61
|
+
values[index] = buffer.readUInt16LE(index * 2);
|
|
62
|
+
}
|
|
63
|
+
if (expectedChecksum !== 0) {
|
|
64
|
+
assertChecksum(entry.file, checksum(values), expectedChecksum);
|
|
65
|
+
}
|
|
66
|
+
return values;
|
|
67
|
+
}
|
|
68
|
+
function readInt8Table(assetDirectory, entry, expectedChecksum) {
|
|
69
|
+
const buffer = (0, node_fs_1.readFileSync)(node_path_1.default.join(assetDirectory, entry.file));
|
|
70
|
+
if (buffer.length !== entry.entries) {
|
|
71
|
+
throw new Error(`Invalid byte size for ${entry.file}`);
|
|
72
|
+
}
|
|
73
|
+
const values = new Int8Array(buffer);
|
|
74
|
+
if (expectedChecksum !== 0) {
|
|
75
|
+
assertChecksum(entry.file, checksum(values), expectedChecksum);
|
|
76
|
+
}
|
|
77
|
+
return values;
|
|
78
|
+
}
|
|
79
|
+
function resolveGeneratedAssetDirectory() {
|
|
80
|
+
const envDirectory = process.env.CUBINGCENTER_SCRAMBLER_TABLES_DIR;
|
|
81
|
+
if (envDirectory && (0, node_fs_1.existsSync)(node_path_1.default.join(envDirectory, "manifest.json"))) {
|
|
82
|
+
return envDirectory;
|
|
83
|
+
}
|
|
84
|
+
for (const candidate of getAssetDirectoryCandidates()) {
|
|
85
|
+
if ((0, node_fs_1.existsSync)(node_path_1.default.join(candidate, "manifest.json"))) {
|
|
86
|
+
return candidate;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
throw new Error("Unable to find generated Square-1 solver tables. Run pnpm sq1:tables.");
|
|
90
|
+
}
|
|
91
|
+
function getAssetDirectoryCandidates() {
|
|
92
|
+
const cwd = process.cwd();
|
|
93
|
+
const candidates = [
|
|
94
|
+
node_path_1.default.join(cwd, "src", GENERATED_DIRECTORY),
|
|
95
|
+
node_path_1.default.join(cwd, "dist", GENERATED_DIRECTORY),
|
|
96
|
+
node_path_1.default.join(cwd, "dist-cjs", GENERATED_DIRECTORY)
|
|
97
|
+
];
|
|
98
|
+
try {
|
|
99
|
+
const requireFromCwd = (0, node_module_1.createRequire)(node_path_1.default.join(cwd, "package.json"));
|
|
100
|
+
const packageEntry = requireFromCwd.resolve("@cubingcenter/scrambler");
|
|
101
|
+
candidates.push(node_path_1.default.join(node_path_1.default.dirname(packageEntry), GENERATED_DIRECTORY));
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
// Source-tree usage is covered by the cwd candidates.
|
|
105
|
+
}
|
|
106
|
+
return candidates;
|
|
107
|
+
}
|
|
108
|
+
function assertChecksum(file, actual, expected) {
|
|
109
|
+
if (actual !== expected) {
|
|
110
|
+
throw new Error(`Checksum mismatch for ${file}: expected ${expected}, received ${actual}.`);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
function checksum(values) {
|
|
114
|
+
let hash = 0x811c9dc5;
|
|
115
|
+
for (let index = 0; index < values.length; index += 1) {
|
|
116
|
+
hash ^= values[index];
|
|
117
|
+
hash = Math.imul(hash, 0x01000193);
|
|
118
|
+
}
|
|
119
|
+
return hash >>> 0;
|
|
120
|
+
}
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Square1Searcher = exports.INVERSE_SOLUTION = void 0;
|
|
4
|
+
const full_cube_js_1 = require("./full-cube.js");
|
|
5
|
+
const tables_js_1 = require("./tables.js");
|
|
6
|
+
exports.INVERSE_SOLUTION = 0x2;
|
|
7
|
+
class Square1Searcher {
|
|
8
|
+
tables;
|
|
9
|
+
move = new Array(100);
|
|
10
|
+
c = new full_cube_js_1.FullCube();
|
|
11
|
+
d = new full_cube_js_1.FullCube();
|
|
12
|
+
length1 = 0;
|
|
13
|
+
movelen1 = 0;
|
|
14
|
+
maxlen2 = 0;
|
|
15
|
+
verbose = 0;
|
|
16
|
+
solString = "";
|
|
17
|
+
solMoves = [];
|
|
18
|
+
constructor(tables) {
|
|
19
|
+
this.tables = tables || (0, tables_js_1.getSquare1SolverTablesSync)();
|
|
20
|
+
}
|
|
21
|
+
solution(c, verbose = 0) {
|
|
22
|
+
this.c.copy(c);
|
|
23
|
+
this.verbose = verbose;
|
|
24
|
+
this.solString = "";
|
|
25
|
+
this.solMoves = [];
|
|
26
|
+
const shape = c.getShapeIdx(this.tables.shapeIdx);
|
|
27
|
+
for (this.length1 = this.tables.shapePrun[shape]; this.length1 < 100; this.length1++) {
|
|
28
|
+
this.maxlen2 = Math.min(31 - this.length1, 17);
|
|
29
|
+
if (this.idaPhase1(shape, this.tables.shapePrun[shape], this.length1, 0, -1)) {
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
moves: this.solMoves,
|
|
35
|
+
scramble: this.solString,
|
|
36
|
+
depth: this.solMoves.length
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
idaPhase1(shape, prunvalue, maxl, depth, lm) {
|
|
40
|
+
if (prunvalue === 0 && maxl < 4) {
|
|
41
|
+
this.movelen1 = depth;
|
|
42
|
+
return maxl === 0 && this.initPhase2();
|
|
43
|
+
}
|
|
44
|
+
// try twist
|
|
45
|
+
if (lm !== 0) {
|
|
46
|
+
const shapex = this.tables.shapeTwistMove[shape];
|
|
47
|
+
const prun = this.tables.shapePrun[shapex];
|
|
48
|
+
if (prun < maxl) {
|
|
49
|
+
this.move[depth] = 0;
|
|
50
|
+
if (this.idaPhase1(shapex, prun, maxl - 1, depth + 1, 0)) {
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
// try top layer
|
|
56
|
+
if (lm <= 0) {
|
|
57
|
+
let m = 0;
|
|
58
|
+
let shapex = shape;
|
|
59
|
+
while (true) {
|
|
60
|
+
const topVal = this.tables.shapeTopMove[shapex];
|
|
61
|
+
m += topVal & 0xf;
|
|
62
|
+
shapex = topVal >> 4;
|
|
63
|
+
if (m >= 12)
|
|
64
|
+
break;
|
|
65
|
+
const prun = this.tables.shapePrun[shapex];
|
|
66
|
+
if (prun > maxl)
|
|
67
|
+
break;
|
|
68
|
+
else if (prun < maxl) {
|
|
69
|
+
this.move[depth] = m;
|
|
70
|
+
if (this.idaPhase1(shapex, prun, maxl - 1, depth + 1, 1)) {
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
// try bottom layer
|
|
77
|
+
if (lm <= 1) {
|
|
78
|
+
let m = 0;
|
|
79
|
+
let shapex = shape;
|
|
80
|
+
while (true) {
|
|
81
|
+
const botVal = this.tables.shapeBottomMove[shapex];
|
|
82
|
+
m += botVal & 0xf;
|
|
83
|
+
shapex = botVal >> 4;
|
|
84
|
+
if (m >= 6)
|
|
85
|
+
break;
|
|
86
|
+
const prun = this.tables.shapePrun[shapex];
|
|
87
|
+
if (prun > maxl)
|
|
88
|
+
break;
|
|
89
|
+
else if (prun < maxl) {
|
|
90
|
+
this.move[depth] = -m;
|
|
91
|
+
if (this.idaPhase1(shapex, prun, maxl - 1, depth + 1, 2)) {
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
initPhase2() {
|
|
100
|
+
this.d.copy(this.c);
|
|
101
|
+
for (let i = 0; i < this.movelen1; i++) {
|
|
102
|
+
this.d.doMove(this.move[i]);
|
|
103
|
+
}
|
|
104
|
+
const sq = this.d.getSquare();
|
|
105
|
+
const prun = Math.max(this.tables.squarePrun[(sq.edgeperm << 1) | sq.ml], this.tables.squarePrun[(sq.cornperm << 1) | sq.ml]);
|
|
106
|
+
for (let i = prun; i < this.maxlen2; i++) {
|
|
107
|
+
if (this.idaPhase2(sq.edgeperm, sq.cornperm, sq.topEdgeFirst, sq.botEdgeFirst, sq.ml, i, this.movelen1, 0)) {
|
|
108
|
+
this.formatSolution(i + this.movelen1);
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
idaPhase2(edge, corner, topEdgeFirst, botEdgeFirst, ml, maxl, depth, lm) {
|
|
115
|
+
if (maxl === 0 && !topEdgeFirst && botEdgeFirst) {
|
|
116
|
+
return edge === 0 && corner === 0 && ml === 0;
|
|
117
|
+
}
|
|
118
|
+
// try twist
|
|
119
|
+
if (lm !== 0 && topEdgeFirst === botEdgeFirst) {
|
|
120
|
+
const edgex = this.tables.squareTwistMove[edge];
|
|
121
|
+
const cornerx = this.tables.squareTwistMove[corner];
|
|
122
|
+
if (this.tables.squarePrun[(edgex << 1) | (1 - ml)] < maxl &&
|
|
123
|
+
this.tables.squarePrun[(cornerx << 1) | (1 - ml)] < maxl) {
|
|
124
|
+
this.move[depth] = 0;
|
|
125
|
+
if (this.idaPhase2(edgex, cornerx, topEdgeFirst, botEdgeFirst, 1 - ml, maxl - 1, depth + 1, 0)) {
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
// try top layer
|
|
131
|
+
if (lm <= 0) {
|
|
132
|
+
let topEdgeFirstx = !topEdgeFirst;
|
|
133
|
+
let edgex = topEdgeFirstx ? this.tables.squareTopMove[edge] : edge;
|
|
134
|
+
let cornerx = topEdgeFirstx ? corner : this.tables.squareTopMove[corner];
|
|
135
|
+
let m = topEdgeFirstx ? 1 : 2;
|
|
136
|
+
let prun1 = this.tables.squarePrun[(edgex << 1) | ml];
|
|
137
|
+
let prun2 = this.tables.squarePrun[(cornerx << 1) | ml];
|
|
138
|
+
while (m < 12 && prun1 <= maxl && prun2 <= maxl) {
|
|
139
|
+
if (prun1 < maxl && prun2 < maxl) {
|
|
140
|
+
this.move[depth] = m;
|
|
141
|
+
if (this.idaPhase2(edgex, cornerx, topEdgeFirstx, botEdgeFirst, ml, maxl - 1, depth + 1, 1)) {
|
|
142
|
+
return true;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
topEdgeFirstx = !topEdgeFirstx;
|
|
146
|
+
if (topEdgeFirstx) {
|
|
147
|
+
edgex = this.tables.squareTopMove[edgex];
|
|
148
|
+
prun1 = this.tables.squarePrun[(edgex << 1) | ml];
|
|
149
|
+
m += 1;
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
cornerx = this.tables.squareTopMove[cornerx];
|
|
153
|
+
prun2 = this.tables.squarePrun[(cornerx << 1) | ml];
|
|
154
|
+
m += 2;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
// try bottom layer
|
|
159
|
+
if (lm <= 1) {
|
|
160
|
+
let botEdgeFirstx = !botEdgeFirst;
|
|
161
|
+
let edgex = botEdgeFirstx ? this.tables.squareBottomMove[edge] : edge;
|
|
162
|
+
let cornerx = botEdgeFirstx ? corner : this.tables.squareBottomMove[corner];
|
|
163
|
+
let m = botEdgeFirstx ? 1 : 2;
|
|
164
|
+
let prun1 = this.tables.squarePrun[(edgex << 1) | ml];
|
|
165
|
+
let prun2 = this.tables.squarePrun[(cornerx << 1) | ml];
|
|
166
|
+
while (m < (maxl > 6 ? 6 : 12) && prun1 <= maxl && prun2 <= maxl) {
|
|
167
|
+
if (prun1 < maxl && prun2 < maxl) {
|
|
168
|
+
this.move[depth] = -m;
|
|
169
|
+
if (this.idaPhase2(edgex, cornerx, topEdgeFirst, botEdgeFirstx, ml, maxl - 1, depth + 1, 2)) {
|
|
170
|
+
return true;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
botEdgeFirstx = !botEdgeFirstx;
|
|
174
|
+
if (botEdgeFirstx) {
|
|
175
|
+
edgex = this.tables.squareBottomMove[edgex];
|
|
176
|
+
prun1 = this.tables.squarePrun[(edgex << 1) | ml];
|
|
177
|
+
m += 1;
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
cornerx = this.tables.squareBottomMove[cornerx];
|
|
181
|
+
prun2 = this.tables.squarePrun[(cornerx << 1) | ml];
|
|
182
|
+
m += 2;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
formatSolution(len) {
|
|
189
|
+
const outputMoves = new Array(len);
|
|
190
|
+
if ((this.verbose & exports.INVERSE_SOLUTION) !== 0) {
|
|
191
|
+
for (let i = len - 1; i >= 0; i--) {
|
|
192
|
+
const val = this.move[i];
|
|
193
|
+
outputMoves[len - 1 - i] = val > 0 ? 12 - val : val < 0 ? -12 - val : val;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
for (let i = 0; i < len; i++) {
|
|
198
|
+
outputMoves[i] = this.move[i];
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
const tokens = [];
|
|
202
|
+
let top = 0;
|
|
203
|
+
let bottom = 0;
|
|
204
|
+
for (let i = 0; i < len; i++) {
|
|
205
|
+
const val = outputMoves[i];
|
|
206
|
+
if (val > 0) {
|
|
207
|
+
top = val > 6 ? val - 12 : val;
|
|
208
|
+
}
|
|
209
|
+
else if (val < 0) {
|
|
210
|
+
bottom = -val > 6 ? -val - 12 : -val;
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
tokens.push(`(${top}, ${bottom})`, "/");
|
|
214
|
+
top = 0;
|
|
215
|
+
bottom = 0;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
if (top !== 0 || bottom !== 0) {
|
|
219
|
+
tokens.push(`(${top}, ${bottom})`);
|
|
220
|
+
}
|
|
221
|
+
// Clean up empty leading (0, 0)
|
|
222
|
+
if (tokens.length >= 2 && tokens[0] === "(0, 0)") {
|
|
223
|
+
tokens.shift();
|
|
224
|
+
}
|
|
225
|
+
this.solMoves = tokens;
|
|
226
|
+
this.solString = tokens.join(" ").replace(/\s*\/\s*/g, " / ").replace(/\s+/g, " ").trim();
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
exports.Square1Searcher = Square1Searcher;
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Shape tables and transitions for Square-1 (Phase 1).
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ShapeState = void 0;
|
|
7
|
+
exports.bitCount = bitCount;
|
|
8
|
+
exports.generateShapeTables = generateShapeTables;
|
|
9
|
+
const halflayer = [
|
|
10
|
+
0x00, 0x03, 0x06, 0x0c, 0x0f, 0x18, 0x1b, 0x1e,
|
|
11
|
+
0x30, 0x33, 0x36, 0x3c, 0x3f
|
|
12
|
+
];
|
|
13
|
+
function bitCount(n) {
|
|
14
|
+
let count = 0;
|
|
15
|
+
let v = n >>> 0;
|
|
16
|
+
while (v > 0) {
|
|
17
|
+
count += v & 1;
|
|
18
|
+
v >>>= 1;
|
|
19
|
+
}
|
|
20
|
+
return count;
|
|
21
|
+
}
|
|
22
|
+
class ShapeState {
|
|
23
|
+
top = 0;
|
|
24
|
+
bottom = 0;
|
|
25
|
+
parity = 0;
|
|
26
|
+
getIdx(shapeIdx) {
|
|
27
|
+
const shp = ((this.top << 12) | this.bottom) >>> 0;
|
|
28
|
+
let low = 0;
|
|
29
|
+
let high = shapeIdx.length - 1;
|
|
30
|
+
while (low <= high) {
|
|
31
|
+
const mid = (low + high) >>> 1;
|
|
32
|
+
const midVal = shapeIdx[mid] >>> 0;
|
|
33
|
+
if (midVal < shp)
|
|
34
|
+
low = mid + 1;
|
|
35
|
+
else if (midVal > shp)
|
|
36
|
+
high = mid - 1;
|
|
37
|
+
else
|
|
38
|
+
return (mid << 1) | this.parity;
|
|
39
|
+
}
|
|
40
|
+
return 0;
|
|
41
|
+
}
|
|
42
|
+
setIdx(idx, shapeIdx) {
|
|
43
|
+
this.parity = idx & 1;
|
|
44
|
+
const val = shapeIdx[idx >> 1];
|
|
45
|
+
this.bottom = val & 0xfff;
|
|
46
|
+
this.top = (val >> 12) & 0xfff;
|
|
47
|
+
}
|
|
48
|
+
topMove() {
|
|
49
|
+
let move = 0;
|
|
50
|
+
let moveParity = 0;
|
|
51
|
+
do {
|
|
52
|
+
if ((this.top & 0x800) === 0) {
|
|
53
|
+
move += 1;
|
|
54
|
+
this.top = (this.top << 1) & 0xfff;
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
move += 2;
|
|
58
|
+
this.top = ((this.top << 2) ^ 0x3003) & 0xfff;
|
|
59
|
+
}
|
|
60
|
+
moveParity = 1 - moveParity;
|
|
61
|
+
} while ((bitCount(this.top & 0x3f) & 1) !== 0);
|
|
62
|
+
if ((bitCount(this.top) & 2) === 0) {
|
|
63
|
+
this.parity ^= moveParity;
|
|
64
|
+
}
|
|
65
|
+
return move;
|
|
66
|
+
}
|
|
67
|
+
bottomMove() {
|
|
68
|
+
let move = 0;
|
|
69
|
+
let moveParity = 0;
|
|
70
|
+
do {
|
|
71
|
+
if ((this.bottom & 0x800) === 0) {
|
|
72
|
+
move += 1;
|
|
73
|
+
this.bottom = (this.bottom << 1) & 0xfff;
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
move += 2;
|
|
77
|
+
this.bottom = ((this.bottom << 2) ^ 0x3003) & 0xfff;
|
|
78
|
+
}
|
|
79
|
+
moveParity = 1 - moveParity;
|
|
80
|
+
} while ((bitCount(this.bottom & 0x3f) & 1) !== 0);
|
|
81
|
+
if ((bitCount(this.bottom) & 2) === 0) {
|
|
82
|
+
this.parity ^= moveParity;
|
|
83
|
+
}
|
|
84
|
+
return move;
|
|
85
|
+
}
|
|
86
|
+
twistMove() {
|
|
87
|
+
const temp = this.top & 0x3f;
|
|
88
|
+
const p1 = bitCount(temp);
|
|
89
|
+
const p3 = bitCount(this.bottom & 0xfc0);
|
|
90
|
+
this.parity ^= 1 & ((p1 & p3) >> 1);
|
|
91
|
+
this.top = (this.top & 0xfc0) | ((this.bottom >> 6) & 0x3f);
|
|
92
|
+
this.bottom = (this.bottom & 0x3f) | (temp << 6);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
exports.ShapeState = ShapeState;
|
|
96
|
+
function generateShapeTables() {
|
|
97
|
+
const shapeIdx = new Int32Array(3678);
|
|
98
|
+
const shapePrun = new Int8Array(3678 * 2);
|
|
99
|
+
const shapeTopMove = new Int32Array(3678 * 2);
|
|
100
|
+
const shapeBottomMove = new Int32Array(3678 * 2);
|
|
101
|
+
const shapeTwistMove = new Int32Array(3678 * 2);
|
|
102
|
+
// 1. Build ShapeIdx
|
|
103
|
+
let count = 0;
|
|
104
|
+
for (let i = 0; i < 13 * 13 * 13 * 13; i++) {
|
|
105
|
+
const dr = halflayer[i % 13];
|
|
106
|
+
const dl = halflayer[Math.floor(i / 13) % 13];
|
|
107
|
+
const ur = halflayer[Math.floor(i / (13 * 13)) % 13];
|
|
108
|
+
const ul = halflayer[Math.floor(i / (13 * 13 * 13))];
|
|
109
|
+
const value = (ul << 18) | (ur << 12) | (dl << 6) | dr;
|
|
110
|
+
if (bitCount(value) === 16) {
|
|
111
|
+
shapeIdx[count++] = value;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
// 2. Build Shape moves
|
|
115
|
+
const s = new ShapeState();
|
|
116
|
+
for (let i = 0; i < 3678 * 2; i++) {
|
|
117
|
+
s.setIdx(i, shapeIdx);
|
|
118
|
+
shapeTopMove[i] = s.topMove() | (s.getIdx(shapeIdx) << 4);
|
|
119
|
+
s.setIdx(i, shapeIdx);
|
|
120
|
+
shapeBottomMove[i] = s.bottomMove() | (s.getIdx(shapeIdx) << 4);
|
|
121
|
+
s.setIdx(i, shapeIdx);
|
|
122
|
+
s.twistMove();
|
|
123
|
+
shapeTwistMove[i] = s.getIdx(shapeIdx);
|
|
124
|
+
}
|
|
125
|
+
// 3. Build ShapePrun
|
|
126
|
+
shapePrun.fill(-1);
|
|
127
|
+
const getIdxForShape = (shp) => {
|
|
128
|
+
let low = 0;
|
|
129
|
+
let high = shapeIdx.length - 1;
|
|
130
|
+
const key = (shp & 0xffffff) >>> 0;
|
|
131
|
+
while (low <= high) {
|
|
132
|
+
const mid = (low + high) >>> 1;
|
|
133
|
+
const midVal = (shapeIdx[mid]) >>> 0;
|
|
134
|
+
if (midVal < key)
|
|
135
|
+
low = mid + 1;
|
|
136
|
+
else if (midVal > key)
|
|
137
|
+
high = mid - 1;
|
|
138
|
+
else
|
|
139
|
+
return (mid << 1) | (shp >>> 24);
|
|
140
|
+
}
|
|
141
|
+
return 0;
|
|
142
|
+
};
|
|
143
|
+
shapePrun[getIdxForShape(0x0db66db)] = 0;
|
|
144
|
+
shapePrun[getIdxForShape(0x1db6db6)] = 0;
|
|
145
|
+
shapePrun[getIdxForShape(0x16db6db)] = 0;
|
|
146
|
+
shapePrun[getIdxForShape(0x06dbdb6)] = 0;
|
|
147
|
+
let done = 4;
|
|
148
|
+
let done0 = 0;
|
|
149
|
+
let depth = -1;
|
|
150
|
+
while (done !== done0) {
|
|
151
|
+
done0 = done;
|
|
152
|
+
depth++;
|
|
153
|
+
for (let i = 0; i < 3678 * 2; i++) {
|
|
154
|
+
if (shapePrun[i] !== depth)
|
|
155
|
+
continue;
|
|
156
|
+
// twist
|
|
157
|
+
const idxTwist = shapeTwistMove[i];
|
|
158
|
+
if (shapePrun[idxTwist] === -1) {
|
|
159
|
+
done++;
|
|
160
|
+
shapePrun[idxTwist] = depth + 1;
|
|
161
|
+
}
|
|
162
|
+
// top moves
|
|
163
|
+
for (let m = 0, inc = 0, idx = i; m !== 12; m += inc) {
|
|
164
|
+
const topVal = shapeTopMove[idx];
|
|
165
|
+
inc = topVal & 0xf;
|
|
166
|
+
idx = topVal >> 4;
|
|
167
|
+
if (shapePrun[idx] === -1) {
|
|
168
|
+
done++;
|
|
169
|
+
shapePrun[idx] = depth + 1;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
// bottom moves
|
|
173
|
+
for (let m = 0, inc = 0, idx = i; m !== 12; m += inc) {
|
|
174
|
+
const botVal = shapeBottomMove[idx];
|
|
175
|
+
inc = botVal & 0xf;
|
|
176
|
+
idx = botVal >> 4;
|
|
177
|
+
if (shapePrun[idx] === -1) {
|
|
178
|
+
done++;
|
|
179
|
+
shapePrun[idx] = depth + 1;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return {
|
|
185
|
+
shapeIdx,
|
|
186
|
+
shapePrun,
|
|
187
|
+
shapeTopMove,
|
|
188
|
+
shapeBottomMove,
|
|
189
|
+
shapeTwistMove
|
|
190
|
+
};
|
|
191
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Permutation tables and distance pruning for Square-1 in Cube/Cube shape (Phase 2).
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.generateSquareTables = generateSquareTables;
|
|
7
|
+
const full_cube_js_1 = require("./full-cube.js");
|
|
8
|
+
function generateSquareTables() {
|
|
9
|
+
const squarePrun = new Int8Array(40320 * 2);
|
|
10
|
+
const squareTwistMove = new Uint16Array(40320);
|
|
11
|
+
const squareTopMove = new Uint16Array(40320);
|
|
12
|
+
const squareBottomMove = new Uint16Array(40320);
|
|
13
|
+
const pos = new Uint8Array(8);
|
|
14
|
+
for (let i = 0; i < 40320; i++) {
|
|
15
|
+
// twist
|
|
16
|
+
(0, full_cube_js_1.set8Perm)(pos, i);
|
|
17
|
+
let temp = pos[2];
|
|
18
|
+
pos[2] = pos[4];
|
|
19
|
+
pos[4] = temp;
|
|
20
|
+
temp = pos[3];
|
|
21
|
+
pos[3] = pos[5];
|
|
22
|
+
pos[5] = temp;
|
|
23
|
+
squareTwistMove[i] = (0, full_cube_js_1.get8Perm)(pos);
|
|
24
|
+
// top layer turn
|
|
25
|
+
(0, full_cube_js_1.set8Perm)(pos, i);
|
|
26
|
+
temp = pos[0];
|
|
27
|
+
pos[0] = pos[1];
|
|
28
|
+
pos[1] = pos[2];
|
|
29
|
+
pos[2] = pos[3];
|
|
30
|
+
pos[3] = temp;
|
|
31
|
+
squareTopMove[i] = (0, full_cube_js_1.get8Perm)(pos);
|
|
32
|
+
// bottom layer turn
|
|
33
|
+
(0, full_cube_js_1.set8Perm)(pos, i);
|
|
34
|
+
temp = pos[4];
|
|
35
|
+
pos[4] = pos[5];
|
|
36
|
+
pos[5] = pos[6];
|
|
37
|
+
pos[6] = pos[7];
|
|
38
|
+
pos[7] = temp;
|
|
39
|
+
squareBottomMove[i] = (0, full_cube_js_1.get8Perm)(pos);
|
|
40
|
+
}
|
|
41
|
+
squarePrun.fill(-1);
|
|
42
|
+
squarePrun[0] = 0;
|
|
43
|
+
let sqDepth = 0;
|
|
44
|
+
let sqDone = 1;
|
|
45
|
+
while (sqDone < 40320 * 2) {
|
|
46
|
+
const inv = sqDepth >= 11;
|
|
47
|
+
const find = inv ? -1 : sqDepth;
|
|
48
|
+
const check = inv ? sqDepth : -1;
|
|
49
|
+
sqDepth++;
|
|
50
|
+
OUTER: for (let i = 0; i < 40320 * 2; i++) {
|
|
51
|
+
if (squarePrun[i] !== find)
|
|
52
|
+
continue;
|
|
53
|
+
let perm = i >> 1;
|
|
54
|
+
const ml = i & 1;
|
|
55
|
+
// twist
|
|
56
|
+
const idx = (squareTwistMove[perm] << 1) | (1 - ml);
|
|
57
|
+
if (squarePrun[idx] === check) {
|
|
58
|
+
sqDone++;
|
|
59
|
+
squarePrun[inv ? i : idx] = sqDepth;
|
|
60
|
+
if (inv)
|
|
61
|
+
continue OUTER;
|
|
62
|
+
}
|
|
63
|
+
// top layer turns
|
|
64
|
+
for (let m = 0; m < 4; m++) {
|
|
65
|
+
perm = squareTopMove[perm];
|
|
66
|
+
const idxTop = (perm << 1) | ml;
|
|
67
|
+
if (squarePrun[idxTop] === check) {
|
|
68
|
+
sqDone++;
|
|
69
|
+
squarePrun[inv ? i : idxTop] = sqDepth;
|
|
70
|
+
if (inv)
|
|
71
|
+
continue OUTER;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
// bottom layer turns
|
|
75
|
+
for (let m = 0; m < 4; m++) {
|
|
76
|
+
perm = squareBottomMove[perm];
|
|
77
|
+
const idxBot = (perm << 1) | ml;
|
|
78
|
+
if (squarePrun[idxBot] === check) {
|
|
79
|
+
sqDone++;
|
|
80
|
+
squarePrun[inv ? i : idxBot] = sqDepth;
|
|
81
|
+
if (inv)
|
|
82
|
+
continue OUTER;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
squarePrun,
|
|
89
|
+
squareTwistMove,
|
|
90
|
+
squareTopMove,
|
|
91
|
+
squareBottomMove
|
|
92
|
+
};
|
|
93
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SQ1_SOLVER_TABLE_METADATA = void 0;
|
|
4
|
+
exports.SQ1_SOLVER_TABLE_METADATA = {
|
|
5
|
+
shapeIdx: {
|
|
6
|
+
entries: 3678,
|
|
7
|
+
file: "shape-idx.bin",
|
|
8
|
+
checksum: 3187990008
|
|
9
|
+
},
|
|
10
|
+
shapePrun: {
|
|
11
|
+
entries: 7356,
|
|
12
|
+
file: "shape-prun.bin",
|
|
13
|
+
checksum: 2116325776
|
|
14
|
+
},
|
|
15
|
+
shapeTopMove: {
|
|
16
|
+
entries: 7356,
|
|
17
|
+
file: "shape-top-move.bin",
|
|
18
|
+
checksum: 4112891337
|
|
19
|
+
},
|
|
20
|
+
shapeBottomMove: {
|
|
21
|
+
entries: 7356,
|
|
22
|
+
file: "shape-bottom-move.bin",
|
|
23
|
+
checksum: 161984121
|
|
24
|
+
},
|
|
25
|
+
shapeTwistMove: {
|
|
26
|
+
entries: 7356,
|
|
27
|
+
file: "shape-twist-move.bin",
|
|
28
|
+
checksum: 694153781
|
|
29
|
+
},
|
|
30
|
+
squareTwistMove: {
|
|
31
|
+
entries: 40320,
|
|
32
|
+
file: "square-twist-move.bin",
|
|
33
|
+
checksum: 4150758597
|
|
34
|
+
},
|
|
35
|
+
squareTopMove: {
|
|
36
|
+
entries: 40320,
|
|
37
|
+
file: "square-top-move.bin",
|
|
38
|
+
checksum: 1003750981
|
|
39
|
+
},
|
|
40
|
+
squareBottomMove: {
|
|
41
|
+
entries: 40320,
|
|
42
|
+
file: "square-bottom-move.bin",
|
|
43
|
+
checksum: 2028613829
|
|
44
|
+
},
|
|
45
|
+
squarePrun: {
|
|
46
|
+
entries: 80640,
|
|
47
|
+
file: "square-prun.bin",
|
|
48
|
+
checksum: 1475475221
|
|
49
|
+
}
|
|
50
|
+
};
|