@cubingcenter/scrambler 0.4.1 → 0.5.1
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 +21 -0
- package/dist/core/api.d.ts.map +1 -1
- package/dist/core/api.js +6 -1
- package/dist/puzzles/pyraminx/facelets.d.ts.map +1 -1
- package/dist/puzzles/pyraminx/facelets.js +43 -17
- package/dist/puzzles/pyraminx/random-state.d.ts.map +1 -1
- package/dist/puzzles/pyraminx/random-state.js +63 -29
- package/dist/puzzles/pyraminx/scrambler.d.ts.map +1 -1
- package/dist/puzzles/pyraminx/scrambler.js +35 -26
- package/dist/puzzles/pyraminx/solver/search.d.ts +3 -0
- package/dist/puzzles/pyraminx/solver/search.d.ts.map +1 -1
- package/dist/puzzles/pyraminx/solver/search.js +60 -5
- package/dist/puzzles/pyraminx/solver/tables.d.ts +1 -0
- package/dist/puzzles/pyraminx/solver/tables.d.ts.map +1 -1
- package/dist/puzzles/pyraminx/solver/tables.js +3 -0
- package/dist/puzzles/skewb/facelets.d.ts.map +1 -1
- package/dist/puzzles/skewb/facelets.js +46 -23
- package/dist/puzzles/skewb/index.d.ts +2 -1
- package/dist/puzzles/skewb/index.d.ts.map +1 -1
- package/dist/puzzles/skewb/index.js +2 -1
- package/dist/puzzles/skewb/random-state.d.ts +1 -1
- package/dist/puzzles/skewb/random-state.d.ts.map +1 -1
- package/dist/puzzles/skewb/random-state.js +25 -18
- package/dist/puzzles/skewb/scrambler.d.ts.map +1 -1
- package/dist/puzzles/skewb/scrambler.js +27 -16
- package/dist/puzzles/skewb/solver/browser-loader.d.ts +20 -0
- package/dist/puzzles/skewb/solver/browser-loader.d.ts.map +1 -0
- package/dist/puzzles/skewb/solver/browser-loader.js +86 -0
- package/dist/puzzles/skewb/solver/generated/centers-table.bin +0 -0
- package/dist/puzzles/skewb/solver/generated/helpers.bin +0 -0
- package/dist/puzzles/skewb/solver/generated/manifest.json +31 -0
- package/dist/puzzles/skewb/solver/generated/orientation-table.bin +0 -0
- package/dist/puzzles/skewb/solver/generated/permutation-table.bin +0 -0
- package/dist/puzzles/skewb/solver/generated/policy.bin +0 -0
- package/dist/puzzles/skewb/solver/generated-assets.d.ts +10 -0
- package/dist/puzzles/skewb/solver/generated-assets.d.ts.map +1 -0
- package/dist/puzzles/skewb/solver/generated-assets.js +24 -0
- package/dist/puzzles/skewb/solver/index.d.ts +5 -0
- package/dist/puzzles/skewb/solver/index.d.ts.map +1 -0
- package/dist/puzzles/skewb/solver/index.js +4 -0
- package/dist/puzzles/skewb/solver/node-loader.d.ts +10 -0
- package/dist/puzzles/skewb/solver/node-loader.d.ts.map +1 -0
- package/dist/puzzles/skewb/solver/node-loader.js +91 -0
- package/dist/puzzles/skewb/solver/search.d.ts +14 -0
- package/dist/puzzles/skewb/solver/search.d.ts.map +1 -0
- package/dist/puzzles/skewb/solver/search.js +120 -0
- package/dist/puzzles/skewb/solver/table-metadata.d.ts +27 -0
- package/dist/puzzles/skewb/solver/table-metadata.d.ts.map +1 -0
- package/dist/puzzles/skewb/solver/table-metadata.js +26 -0
- package/dist/puzzles/skewb/solver/tables.d.ts +69 -0
- package/dist/puzzles/skewb/solver/tables.d.ts.map +1 -0
- package/dist/puzzles/skewb/solver/tables.js +511 -0
- package/dist/random/prng.d.ts.map +1 -1
- package/dist/random/prng.js +25 -2
- package/dist-cjs/core/api.js +6 -1
- package/dist-cjs/puzzles/pyraminx/facelets.js +43 -17
- package/dist-cjs/puzzles/pyraminx/random-state.js +63 -29
- package/dist-cjs/puzzles/pyraminx/scrambler.js +34 -25
- package/dist-cjs/puzzles/pyraminx/solver/search.js +62 -4
- package/dist-cjs/puzzles/pyraminx/solver/tables.js +4 -0
- package/dist-cjs/puzzles/skewb/facelets.js +46 -23
- package/dist-cjs/puzzles/skewb/index.js +49 -11
- package/dist-cjs/puzzles/skewb/random-state.js +25 -18
- package/dist-cjs/puzzles/skewb/scrambler.js +26 -15
- package/dist-cjs/puzzles/skewb/solver/browser-loader.js +91 -0
- package/dist-cjs/puzzles/skewb/solver/generated/centers-table.bin +0 -0
- package/dist-cjs/puzzles/skewb/solver/generated/helpers.bin +0 -0
- package/dist-cjs/puzzles/skewb/solver/generated/manifest.json +31 -0
- package/dist-cjs/puzzles/skewb/solver/generated/orientation-table.bin +0 -0
- package/dist-cjs/puzzles/skewb/solver/generated/permutation-table.bin +0 -0
- package/dist-cjs/puzzles/skewb/solver/generated/policy.bin +0 -0
- package/dist-cjs/puzzles/skewb/solver/generated-assets.js +60 -0
- package/dist-cjs/puzzles/skewb/solver/index.js +23 -0
- package/dist-cjs/puzzles/skewb/solver/node-loader.js +97 -0
- package/dist-cjs/puzzles/skewb/solver/search.js +130 -0
- package/dist-cjs/puzzles/skewb/solver/table-metadata.js +29 -0
- package/dist-cjs/puzzles/skewb/solver/tables.js +543 -0
- package/dist-cjs/random/prng.js +25 -2
- package/package.json +6 -3
- package/dist/puzzles/skewb/solver.d.ts +0 -11
- package/dist/puzzles/skewb/solver.d.ts.map +0 -1
- package/dist/puzzles/skewb/solver.js +0 -149
- package/dist-cjs/puzzles/skewb/solver.js +0 -160
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.solveSkewb = solveSkewb;
|
|
4
|
+
exports.solveSkewbWithInfo = solveSkewbWithInfo;
|
|
5
|
+
exports.solveSkewbIndices = solveSkewbIndices;
|
|
6
|
+
exports.solveSkewbIndicesSync = solveSkewbIndicesSync;
|
|
7
|
+
exports.solveSkewbSync = solveSkewbSync;
|
|
8
|
+
exports.verifySkewbScramble = verifySkewbScramble;
|
|
9
|
+
exports.verifySkewbScrambleIndices = verifySkewbScrambleIndices;
|
|
10
|
+
exports.verifySkewbSolution = verifySkewbSolution;
|
|
11
|
+
const tables_js_1 = require("./tables.js");
|
|
12
|
+
async function solveSkewb(state) {
|
|
13
|
+
await (0, tables_js_1.ensureTablesLoaded)();
|
|
14
|
+
return solveWithTables(state).moves;
|
|
15
|
+
}
|
|
16
|
+
async function solveSkewbWithInfo(state) {
|
|
17
|
+
await (0, tables_js_1.ensureTablesLoaded)();
|
|
18
|
+
return solveWithTables(state);
|
|
19
|
+
}
|
|
20
|
+
// Index-based solve for the hot scramble path: returns the solution as move
|
|
21
|
+
// indices (0..7) in walk order. The inverse of index m is m ^ 1 (moves are
|
|
22
|
+
// paired R/R', U/U', L/L', B/B').
|
|
23
|
+
async function solveSkewbIndices(state) {
|
|
24
|
+
await (0, tables_js_1.ensureTablesLoaded)();
|
|
25
|
+
return solveWithTablesIndices(state);
|
|
26
|
+
}
|
|
27
|
+
function solveSkewbIndicesSync(state) {
|
|
28
|
+
if (!tables_js_1.POLICY_TABLE) {
|
|
29
|
+
throw new Error("Skewb solver tables not loaded. Call ensureTablesLoaded() first.");
|
|
30
|
+
}
|
|
31
|
+
return solveWithTablesIndices(state);
|
|
32
|
+
}
|
|
33
|
+
// Synchronous variant for scripts that have already ensured tables are loaded
|
|
34
|
+
function solveSkewbSync(state) {
|
|
35
|
+
if (!tables_js_1.POLICY_TABLE) {
|
|
36
|
+
throw new Error("Skewb solver tables not loaded. Call ensureTablesLoaded() first.");
|
|
37
|
+
}
|
|
38
|
+
return solveWithTables(state).moves;
|
|
39
|
+
}
|
|
40
|
+
function solveWithTables(state) {
|
|
41
|
+
const indices = solveWithTablesIndices(state);
|
|
42
|
+
const moves = indices.map((index) => tables_js_1.SKEWB_MOVES[index]);
|
|
43
|
+
return { moves, depth: moves.length };
|
|
44
|
+
}
|
|
45
|
+
function solveWithTablesIndices(state) {
|
|
46
|
+
const policy = tables_js_1.POLICY_TABLE;
|
|
47
|
+
const permTable = tables_js_1.PERMUTATION_TABLE;
|
|
48
|
+
const orientTable = tables_js_1.ORIENTATION_TABLE;
|
|
49
|
+
const centersTable = tables_js_1.CENTERS_TABLE;
|
|
50
|
+
if (state.corners.permutation[0] !== 0) {
|
|
51
|
+
throw new Error("The Skewb solver requires the UFR corner (index 0) to be fixed " +
|
|
52
|
+
"as the frame of reference. Please normalize the state before solving.");
|
|
53
|
+
}
|
|
54
|
+
let r7 = (0, tables_js_1.getPerm7Index)(state.corners.permutation);
|
|
55
|
+
let rO = (0, tables_js_1.getOrientationIndex)(state.corners.orientation);
|
|
56
|
+
let rC = (0, tables_js_1.getCenterIndex)(state.centers);
|
|
57
|
+
let rank = (0, tables_js_1.rankFromComponents)(r7, rO, rC);
|
|
58
|
+
if (rank === tables_js_1.SOLVED_RANK) {
|
|
59
|
+
return [];
|
|
60
|
+
}
|
|
61
|
+
const moves = [];
|
|
62
|
+
while (rank !== tables_js_1.SOLVED_RANK) {
|
|
63
|
+
const m = (0, tables_js_1.getPolicyMoveFromPacked)(policy, rank);
|
|
64
|
+
moves.push(m);
|
|
65
|
+
r7 = permTable[r7 * tables_js_1.MOVE_COUNT + m];
|
|
66
|
+
rO = orientTable[rO * tables_js_1.MOVE_COUNT + m];
|
|
67
|
+
rC = centersTable[rC * tables_js_1.MOVE_COUNT + m];
|
|
68
|
+
rank = (0, tables_js_1.rankFromComponents)(r7, rO, rC);
|
|
69
|
+
}
|
|
70
|
+
return moves;
|
|
71
|
+
}
|
|
72
|
+
// ---------------------------------------------------------------------------
|
|
73
|
+
// Coordinate-walking verification (no full state clones)
|
|
74
|
+
// ---------------------------------------------------------------------------
|
|
75
|
+
const MOVE_INDEX = {};
|
|
76
|
+
for (let i = 0; i < tables_js_1.SKEWB_MOVES.length; i++) {
|
|
77
|
+
MOVE_INDEX[tables_js_1.SKEWB_MOVES[i]] = i;
|
|
78
|
+
}
|
|
79
|
+
function walkSkewbCoordinates(start, moves) {
|
|
80
|
+
const permTable = tables_js_1.PERMUTATION_TABLE;
|
|
81
|
+
const orientTable = tables_js_1.ORIENTATION_TABLE;
|
|
82
|
+
const centersTable = tables_js_1.CENTERS_TABLE;
|
|
83
|
+
if (!permTable || !orientTable || !centersTable) {
|
|
84
|
+
throw new Error("Skewb solver tables not loaded. Call ensureTablesLoaded() first.");
|
|
85
|
+
}
|
|
86
|
+
let { r7, rO, rC } = start;
|
|
87
|
+
for (const move of moves) {
|
|
88
|
+
const m = MOVE_INDEX[move];
|
|
89
|
+
r7 = permTable[r7 * tables_js_1.MOVE_COUNT + m];
|
|
90
|
+
rO = orientTable[rO * tables_js_1.MOVE_COUNT + m];
|
|
91
|
+
rC = centersTable[rC * tables_js_1.MOVE_COUNT + m];
|
|
92
|
+
}
|
|
93
|
+
return { r7, rO, rC };
|
|
94
|
+
}
|
|
95
|
+
function verifySkewbScramble(state, scrambleMoves) {
|
|
96
|
+
const final = walkSkewbCoordinates({ r7: 0, rO: 0, rC: 0 }, scrambleMoves);
|
|
97
|
+
return (final.r7 === (0, tables_js_1.getPerm7Index)(state.corners.permutation) &&
|
|
98
|
+
final.rO === (0, tables_js_1.getOrientationIndex)(state.corners.orientation) &&
|
|
99
|
+
final.rC === (0, tables_js_1.getCenterIndex)(state.centers));
|
|
100
|
+
}
|
|
101
|
+
// Numeric verification for the hot scramble path: replays the scramble (the
|
|
102
|
+
// solution reversed with m ^ 1 inverses) without any string parsing.
|
|
103
|
+
function verifySkewbScrambleIndices(state, solution) {
|
|
104
|
+
const permTable = tables_js_1.PERMUTATION_TABLE;
|
|
105
|
+
const orientTable = tables_js_1.ORIENTATION_TABLE;
|
|
106
|
+
const centersTable = tables_js_1.CENTERS_TABLE;
|
|
107
|
+
if (!permTable || !orientTable || !centersTable) {
|
|
108
|
+
throw new Error("Skewb solver tables not loaded. Call ensureTablesLoaded() first.");
|
|
109
|
+
}
|
|
110
|
+
let r7 = 0;
|
|
111
|
+
let rO = 0;
|
|
112
|
+
let rC = 0;
|
|
113
|
+
for (let index = solution.length - 1; index >= 0; index -= 1) {
|
|
114
|
+
const m = solution[index] ^ 1;
|
|
115
|
+
r7 = permTable[r7 * tables_js_1.MOVE_COUNT + m];
|
|
116
|
+
rO = orientTable[rO * tables_js_1.MOVE_COUNT + m];
|
|
117
|
+
rC = centersTable[rC * tables_js_1.MOVE_COUNT + m];
|
|
118
|
+
}
|
|
119
|
+
return (r7 === (0, tables_js_1.getPerm7Index)(state.corners.permutation) &&
|
|
120
|
+
rO === (0, tables_js_1.getOrientationIndex)(state.corners.orientation) &&
|
|
121
|
+
rC === (0, tables_js_1.getCenterIndex)(state.centers));
|
|
122
|
+
}
|
|
123
|
+
function verifySkewbSolution(state, solutionMoves) {
|
|
124
|
+
const final = walkSkewbCoordinates({
|
|
125
|
+
r7: (0, tables_js_1.getPerm7Index)(state.corners.permutation),
|
|
126
|
+
rO: (0, tables_js_1.getOrientationIndex)(state.corners.orientation),
|
|
127
|
+
rC: (0, tables_js_1.getCenterIndex)(state.centers)
|
|
128
|
+
}, solutionMoves);
|
|
129
|
+
return final.r7 === 0 && final.rO === 0 && final.rC === 0;
|
|
130
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SKEWB_SOLVER_TABLE_METADATA = void 0;
|
|
4
|
+
exports.SKEWB_SOLVER_TABLE_METADATA = {
|
|
5
|
+
permutationTable: {
|
|
6
|
+
entries: 40320, // PERMUTATION_COUNT (5040) * MOVE_COUNT (8)
|
|
7
|
+
checksum: 3073532981
|
|
8
|
+
},
|
|
9
|
+
orientationTable: {
|
|
10
|
+
entries: 17496, // ORIENTATION_COUNT (2187) * MOVE_COUNT (8)
|
|
11
|
+
checksum: 2128852053
|
|
12
|
+
},
|
|
13
|
+
centersTable: {
|
|
14
|
+
entries: 5760, // CENTER_COUNT (720) * MOVE_COUNT (8)
|
|
15
|
+
checksum: 360885765
|
|
16
|
+
},
|
|
17
|
+
helpers: {
|
|
18
|
+
evenCenterRankBytes: 1440, // 720 * 2 (Uint16, sentinel 65535)
|
|
19
|
+
orientClassBytes: 2187,
|
|
20
|
+
r7SetsEntries: 12960, // EVEN_CENTER_COUNT (360) * ORIENT_CLASS_COUNT (9) * PER_SET_SIZE (4)
|
|
21
|
+
entries: 1440 + 2187 + 12960 * 2,
|
|
22
|
+
checksum: 4284555735
|
|
23
|
+
},
|
|
24
|
+
policyTable: {
|
|
25
|
+
entries: 1180980, // ceil(STATE_COUNT (3_149_280) * 3 / 8)
|
|
26
|
+
checksum: 1294485891,
|
|
27
|
+
maxDepth: 11
|
|
28
|
+
}
|
|
29
|
+
};
|