@cubingcenter/scrambler 0.5.2 → 0.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/puzzles/cube2/random-state.d.ts.map +1 -1
- package/dist/puzzles/cube2/random-state.js +4 -10
- package/dist/puzzles/cube2/solver/browser-loader.d.ts +2 -2
- package/dist/puzzles/cube2/solver/browser-loader.d.ts.map +1 -1
- package/dist/puzzles/cube2/solver/browser-loader.js +2 -2
- package/dist/puzzles/cube2/solver/generated/manifest.json +3 -3
- package/dist/puzzles/cube2/solver/generated/policy.bin +0 -0
- package/dist/puzzles/cube2/solver/generated-assets.d.ts +1 -1
- package/dist/puzzles/cube2/solver/generated-assets.d.ts.map +1 -1
- package/dist/puzzles/cube2/solver/index.d.ts +1 -1
- package/dist/puzzles/cube2/solver/index.d.ts.map +1 -1
- package/dist/puzzles/cube2/solver/index.js +1 -1
- package/dist/puzzles/cube2/solver/node-loader.d.ts +1 -1
- package/dist/puzzles/cube2/solver/node-loader.d.ts.map +1 -1
- package/dist/puzzles/cube2/solver/node-loader.js +2 -2
- package/dist/puzzles/cube2/solver/search.d.ts.map +1 -1
- package/dist/puzzles/cube2/solver/search.js +12 -32
- package/dist/puzzles/cube2/solver/table-metadata.d.ts +2 -2
- package/dist/puzzles/cube2/solver/table-metadata.js +2 -2
- package/dist/puzzles/cube2/solver/tables.d.ts +1 -1
- package/dist/puzzles/cube2/solver/tables.d.ts.map +1 -1
- package/dist/puzzles/cube2/solver/tables.js +36 -13
- package/dist/puzzles/cube2/state.d.ts.map +1 -1
- package/dist/puzzles/cube2/state.js +3 -1
- package/dist/puzzles/cube2/validation.d.ts +1 -0
- package/dist/puzzles/cube2/validation.d.ts.map +1 -1
- package/dist/puzzles/cube2/validation.js +38 -7
- package/dist/puzzles/cube3/facelets.d.ts.map +1 -1
- package/dist/puzzles/cube3/facelets.js +53 -28
- package/dist/puzzles/cube3/random-state.d.ts.map +1 -1
- package/dist/puzzles/cube3/random-state.js +9 -2
- package/dist/puzzles/cube3/scrambler.js +1 -1
- package/dist/puzzles/cube3/state.d.ts.map +1 -1
- package/dist/puzzles/cube3/state.js +4 -1
- package/dist/puzzles/cube3/validation.d.ts.map +1 -1
- package/dist/puzzles/cube3/validation.js +5 -2
- package/dist/puzzles/skewb/random-state.d.ts +1 -0
- package/dist/puzzles/skewb/random-state.d.ts.map +1 -1
- package/dist/puzzles/skewb/random-state.js +9 -1
- package/dist/puzzles/skewb/scrambler.d.ts.map +1 -1
- package/dist/puzzles/skewb/scrambler.js +6 -2
- package/dist/puzzles/skewb/solver/tables.d.ts +1 -0
- package/dist/puzzles/skewb/solver/tables.d.ts.map +1 -1
- package/dist/puzzles/skewb/solver/tables.js +11 -5
- package/dist-cjs/puzzles/cube2/random-state.js +3 -9
- package/dist-cjs/puzzles/cube2/solver/browser-loader.js +2 -2
- package/dist-cjs/puzzles/cube2/solver/generated/manifest.json +3 -3
- package/dist-cjs/puzzles/cube2/solver/generated/policy.bin +0 -0
- package/dist-cjs/puzzles/cube2/solver/index.js +2 -2
- package/dist-cjs/puzzles/cube2/solver/node-loader.js +2 -2
- package/dist-cjs/puzzles/cube2/solver/search.js +11 -31
- package/dist-cjs/puzzles/cube2/solver/table-metadata.js +2 -2
- package/dist-cjs/puzzles/cube2/solver/tables.js +37 -14
- package/dist-cjs/puzzles/cube2/state.js +3 -1
- package/dist-cjs/puzzles/cube2/validation.js +39 -7
- package/dist-cjs/puzzles/cube3/facelets.js +53 -28
- package/dist-cjs/puzzles/cube3/random-state.js +8 -1
- package/dist-cjs/puzzles/cube3/scrambler.js +1 -1
- package/dist-cjs/puzzles/cube3/state.js +4 -1
- package/dist-cjs/puzzles/cube3/validation.js +5 -2
- package/dist-cjs/puzzles/skewb/random-state.js +9 -0
- package/dist-cjs/puzzles/skewb/scrambler.js +5 -1
- package/dist-cjs/puzzles/skewb/solver/tables.js +12 -6
- package/package.json +1 -1
- package/dist/puzzles/cube2/solver/generated/distances.bin +0 -1
- package/dist/puzzles/cube3/solver/browser-worker-pool.d.ts +0 -31
- package/dist/puzzles/cube3/solver/browser-worker-pool.d.ts.map +0 -1
- package/dist/puzzles/cube3/solver/browser-worker-pool.js +0 -118
- package/dist/puzzles/cube3/solver/browser-worker.d.ts +0 -2
- package/dist/puzzles/cube3/solver/browser-worker.d.ts.map +0 -1
- package/dist/puzzles/cube3/solver/browser-worker.js +0 -71
- package/dist/puzzles/cube3/solver/worker-pool.d.ts +0 -18
- package/dist/puzzles/cube3/solver/worker-pool.d.ts.map +0 -1
- package/dist/puzzles/cube3/solver/worker-pool.js +0 -116
- package/dist/puzzles/cube3/solver/worker.d.ts +0 -2
- package/dist/puzzles/cube3/solver/worker.d.ts.map +0 -1
- package/dist/puzzles/cube3/solver/worker.js +0 -73
- package/dist-cjs/puzzles/cube2/solver/generated/distances.bin +0 -1
|
@@ -34,9 +34,12 @@ function validateCube3State(state) {
|
|
|
34
34
|
errors
|
|
35
35
|
};
|
|
36
36
|
}
|
|
37
|
+
// The 18 single-move states, precomputed once so the hot random-state path
|
|
38
|
+
// checks "one move from solved" with pure comparisons instead of 18 full
|
|
39
|
+
// move applications per generated state.
|
|
40
|
+
const ONE_MOVE_FROM_SOLVED_STATES = types_js_1.CUBE3_MOVES.map((move) => (0, moves_js_1.applyCube3Move)((0, state_js_1.createSolvedCube3State)(), move));
|
|
37
41
|
function isOneMoveFromSolvedCube3State(state) {
|
|
38
|
-
|
|
39
|
-
return types_js_1.CUBE3_MOVES.some((move) => (0, state_js_1.cube3StatesEqual)((0, moves_js_1.applyCube3Move)(solved, move), state));
|
|
42
|
+
return ONE_MOVE_FROM_SOLVED_STATES.some((candidate) => (0, state_js_1.cube3StatesEqual)(candidate, state));
|
|
40
43
|
}
|
|
41
44
|
function isAllowedRandomCube3State(state) {
|
|
42
45
|
return validateCube3State(state).valid &&
|
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateRandomSkewbState = generateRandomSkewbState;
|
|
4
|
+
exports.generateRandomSkewbStateSync = generateRandomSkewbStateSync;
|
|
4
5
|
const index_js_1 = require("../../random/index.js");
|
|
5
6
|
const index_js_2 = require("./solver/index.js");
|
|
6
7
|
async function generateRandomSkewbState(options = {}) {
|
|
7
8
|
await (0, index_js_2.ensureTablesLoaded)();
|
|
9
|
+
return generateRandomSkewbStateSync(options);
|
|
10
|
+
}
|
|
11
|
+
// Synchronous variant for callers that have already ensured the tables are
|
|
12
|
+
// loaded (e.g. the scrambler after the first call): no per-call await hop.
|
|
13
|
+
function generateRandomSkewbStateSync(options = {}) {
|
|
14
|
+
if (!(0, index_js_2.areSkewbTablesLoaded)()) {
|
|
15
|
+
throw new Error("Skewb solver tables not loaded. Call ensureTablesLoaded() first.");
|
|
16
|
+
}
|
|
8
17
|
const random = (0, index_js_1.createRandomSource)(options.seed);
|
|
9
18
|
const rejectTrivial = options.rejectTrivial ?? true;
|
|
10
19
|
const trivialRanks = rejectTrivial ? getTrivialRanks() : null;
|
|
@@ -20,7 +20,11 @@ exports.skewbScrambleGenerator = {
|
|
|
20
20
|
},
|
|
21
21
|
};
|
|
22
22
|
async function generateSkewbScramble(options = {}) {
|
|
23
|
-
|
|
23
|
+
// generateRandomSkewbStateSync guarantees the tables are loaded, so use
|
|
24
|
+
// the sync state generation on every call after the first (no await hop).
|
|
25
|
+
const state = (0, index_js_1.areSkewbTablesLoaded)()
|
|
26
|
+
? (0, random_state_js_1.generateRandomSkewbStateSync)(options)
|
|
27
|
+
: await (0, random_state_js_1.generateRandomSkewbState)(options);
|
|
24
28
|
// generateRandomSkewbState guarantees the tables are loaded, so use the
|
|
25
29
|
// sync solve on every call after the first (no extra microtask).
|
|
26
30
|
const solution = (0, index_js_1.areSkewbTablesLoaded)()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SOLVED_RANK = exports.CENTER_UNRANK = exports.PERM7_UNRANK = exports.R7_SETS = exports.ORIENT_CLASS = exports.EVEN_CENTER_FULL = exports.EVEN_CENTER_RANK = exports.POLICY_TABLE = exports.CENTERS_TABLE = exports.ORIENTATION_TABLE = exports.PERMUTATION_TABLE = exports.SKEWB_MOVES = exports.POLICY_PACKED_ENTRIES = exports.STATE_COUNT = exports.MOVE_COUNT = exports.PER_SET_SIZE = exports.ORIENT_CLASS_COUNT = exports.EVEN_CENTER_COUNT = exports.CENTER_COUNT = exports.ORIENTATION_COUNT = exports.PERMUTATION_COUNT = void 0;
|
|
3
|
+
exports.SOLVED_RANK = exports.ORIENT_UNRANK = exports.CENTER_UNRANK = exports.PERM7_UNRANK = exports.R7_SETS = exports.ORIENT_CLASS = exports.EVEN_CENTER_FULL = exports.EVEN_CENTER_RANK = exports.POLICY_TABLE = exports.CENTERS_TABLE = exports.ORIENTATION_TABLE = exports.PERMUTATION_TABLE = exports.SKEWB_MOVES = exports.POLICY_PACKED_ENTRIES = exports.STATE_COUNT = exports.MOVE_COUNT = exports.PER_SET_SIZE = exports.ORIENT_CLASS_COUNT = exports.EVEN_CENTER_COUNT = exports.CENTER_COUNT = exports.ORIENTATION_COUNT = exports.PERMUTATION_COUNT = void 0;
|
|
4
4
|
exports.getPermutationIndex = getPermutationIndex;
|
|
5
5
|
exports.getPermutationFromIndex = getPermutationFromIndex;
|
|
6
6
|
exports.getOrientationIndex = getOrientationIndex;
|
|
@@ -181,6 +181,7 @@ exports.ORIENT_CLASS = null; // rO -> class 0..8
|
|
|
181
181
|
exports.R7_SETS = null; // (rC_even * 9 + class) * 4 + i
|
|
182
182
|
exports.PERM7_UNRANK = null; // r7 * 7 + i -> piece at corner i+1 (derived at load)
|
|
183
183
|
exports.CENTER_UNRANK = null; // rC * 6 + i -> center piece (derived at load)
|
|
184
|
+
exports.ORIENT_UNRANK = null; // rO * 7 + i -> orientation of corner i+1 (derived at load)
|
|
184
185
|
exports.SOLVED_RANK = 0;
|
|
185
186
|
async function ensureTablesLoaded() {
|
|
186
187
|
if (tablesLoaded)
|
|
@@ -217,6 +218,12 @@ function assignTables(tables) {
|
|
|
217
218
|
for (let i = 0; i < 6; i++)
|
|
218
219
|
exports.CENTER_UNRANK[rC * 6 + i] = centers[i];
|
|
219
220
|
}
|
|
221
|
+
exports.ORIENT_UNRANK = new Uint8Array(exports.ORIENTATION_COUNT * 7);
|
|
222
|
+
for (let rO = 0; rO < exports.ORIENTATION_COUNT; rO++) {
|
|
223
|
+
const orient = getOrientationFromIndex(rO);
|
|
224
|
+
for (let i = 0; i < 7; i++)
|
|
225
|
+
exports.ORIENT_UNRANK[rO * 7 + i] = orient[i + 1];
|
|
226
|
+
}
|
|
220
227
|
exports.SOLVED_RANK = rankFromComponents(0, 0, 0);
|
|
221
228
|
tablesLoaded = true;
|
|
222
229
|
}
|
|
@@ -232,6 +239,7 @@ function resetTablesForTests() {
|
|
|
232
239
|
exports.R7_SETS = null;
|
|
233
240
|
exports.PERM7_UNRANK = null;
|
|
234
241
|
exports.CENTER_UNRANK = null;
|
|
242
|
+
exports.ORIENT_UNRANK = null;
|
|
235
243
|
}
|
|
236
244
|
// ---------------------------------------------------------------------------
|
|
237
245
|
// Compact rank helpers
|
|
@@ -277,11 +285,9 @@ function getStateFromRank(rank) {
|
|
|
277
285
|
perm[i + 1] = exports.PERM7_UNRANK[permBase + i];
|
|
278
286
|
const orient = new Array(8);
|
|
279
287
|
orient[0] = 0;
|
|
280
|
-
|
|
281
|
-
for (let i = 1; i < 8; i++)
|
|
282
|
-
orient[i] =
|
|
283
|
-
val = Math.floor(val / 3);
|
|
284
|
-
}
|
|
288
|
+
const orientBase = rO * 7;
|
|
289
|
+
for (let i = 1; i < 8; i++)
|
|
290
|
+
orient[i] = exports.ORIENT_UNRANK[orientBase + i - 1];
|
|
285
291
|
const centers = new Array(6);
|
|
286
292
|
const centerBase = exports.EVEN_CENTER_FULL[even] * 6;
|
|
287
293
|
for (let i = 0; i < 6; i++)
|