Skip to content

Commit

Permalink
[scramble] Pyraminx.
Browse files Browse the repository at this point in the history
  • Loading branch information
lgarron committed Aug 4, 2021
1 parent 884f861 commit b97e940
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 9 deletions.
10 changes: 9 additions & 1 deletion src/cubing/search/inside/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ import {
random444Scramble,
} from "./solve/puzzles/4x4x4";
import { solveMegaminx } from "./solve/puzzles/megaminx";
import { solvePyraminx } from "./solve/puzzles/pyraminx";
import {
randomPyraminxScrambleFixedOrientation,
solvePyraminx,
} from "./solve/puzzles/pyraminx";
import {
randomSkewbFixedCornerScramble,
solveSkewb,
Expand Down Expand Up @@ -116,6 +119,11 @@ export const insideAPI = {
"randomSkewbFixedCornerScramble",
randomSkewbFixedCornerScramble,
);
case "pyram":
return measurePerf(
"randomPyraminxScrambleFixedOrientation",
randomPyraminxScrambleFixedOrientation,
);
default:
throw new Error(`unsupported event: ${eventID}`);
}
Expand Down
12 changes: 9 additions & 3 deletions src/cubing/search/inside/solve/puzzles/pyraminx.sgs.json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@ import { puzzles } from "../../../../puzzles";
import { parseSGS, SGSCachedData } from "../parseSGS";

let cachedData: Promise<SGSCachedData> | null = null;
export async function cachedSGSDataPyraminx() {
return (cachedData ??= sgsDataPyraminx());
export async function sgsDataPyraminx() {
return (cachedData ??= uncachedSGSDataPyraminx());
}

export async function sgsDataPyraminxFixedOrientation(): Promise<SGSCachedData> {
return {
ordering: (await sgsDataPyraminx()).ordering.slice(1),
};
}

// TODO: Reduce info.
async function sgsDataPyraminx(): Promise<SGSCachedData> {
async function uncachedSGSDataPyraminx(): Promise<SGSCachedData> {
return parseSGS(
await puzzles.pyraminx.def(),
`SubgroupSizes 12 9 12 3 10 3 8 6 2 3 3 3 3
Expand Down
19 changes: 16 additions & 3 deletions src/cubing/search/inside/solve/puzzles/pyraminx.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { puzzles } from "../../../../puzzles";
import type { Alg } from "../../../../alg";
import type { Transformation } from "../../../../kpuzzle";
import { puzzles } from "../../../../puzzles";
import { mustBeInsideWorker } from "../../inside-worker";
import type { SGSCachedData } from "../parseSGS";
import { TrembleSolver } from "../tremble";
import { randomStateFromSGS, TrembleSolver } from "../tremble";
import { sgsDataPyraminxFixedOrientation } from "./pyraminx.sgs.json";

const TREMBLE_DEPTH = 3;

Expand All @@ -13,7 +14,7 @@ async function getCachedTrembleSolver(): Promise<TrembleSolver> {
cachedTrembleSolver ||
(cachedTrembleSolver = (async (): Promise<TrembleSolver> => {
const sgs = await import("./pyraminx.sgs.json");
const json: SGSCachedData = await sgs.cachedSGSDataPyraminx();
const json: SGSCachedData = await sgs.sgsDataPyraminx();
return new TrembleSolver(
await puzzles.pyraminx.def(),
json,
Expand All @@ -33,3 +34,15 @@ export async function solvePyraminx(state: Transformation): Promise<Alg> {
const alg = await trembleSolver.solve(state, TREMBLE_DEPTH, () => 3); // TODO: Attach quantum move order lookup to puzzle.
return alg;
}

export async function randomPyraminxStateFixedOrientation(): Promise<Transformation> {
// Note: this sets all center orientations to 0.
return randomStateFromSGS(
await puzzles.pyraminx.def(),
await sgsDataPyraminxFixedOrientation(),
);
}

export async function randomPyraminxScrambleFixedOrientation(): Promise<Alg> {
return solvePyraminx(await randomPyraminxStateFixedOrientation());
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<option value="333oh">3x3x3 One-Handed</option>
<option value="clock">Clock</option>
<option value="minx">Megaminx</option>
<!-- <option value="pyram">Pyraminx</option> -->
<option value="pyram">Pyraminx</option>
<option value="skewb">Skewb</option>
<!-- <option value="sq1">Square-1</option> -->
<option value="444bf">4x4x4 Blindfolded</option>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ window.addEventListener("DOMContentLoaded", () => {
"333oh": "3x3x3",
"clock": "clock",
"minx": "megaminx",
// "pyram": "pyraminx",
"pyram": "pyraminx",
"skewb": "skewb",
// "sq1": "square1",
"444bf": "4x4x4",
Expand Down

0 comments on commit b97e940

Please sign in to comment.