Skip to content

Commit

Permalink
[search] Avoid 2' suffixes in 2x2x2 scrambles.
Browse files Browse the repository at this point in the history
  • Loading branch information
lgarron committed Apr 4, 2024
1 parent bc110c4 commit c62f0b1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 46 deletions.
33 changes: 21 additions & 12 deletions src/cubing/search/inside/api.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type { Alg } from "../../alg";
import {
type KPuzzleDefinition,
KPattern,
type KPatternData,
KPuzzle,
type KPatternData,
type KPuzzleDefinition,
} from "../../kpuzzle";
import { puzzles } from "../../puzzles";
import { setIsInsideWorker } from "./inside-worker";
import { preInitialize222, solve222HTMSubOptimal } from "./solve/puzzles/2x2x2";
import { preInitialize222, solve222 } from "./solve/puzzles/2x2x2";
import {
initialize333,
random333OrientedScramble,
Expand All @@ -32,8 +32,8 @@ import {
import { getRandomSquare1Scramble } from "./solve/puzzles/sq1";
import {
wasmRandomScrambleForEvent,
type TwsearchOptions,
wasmTwsearch,
type TwsearchOptions,
} from "./solve/twsearch";

const IDLE_PREFETCH_TIMEOUT_MS = 1000;
Expand Down Expand Up @@ -81,9 +81,24 @@ async function randomScrambleForEvent(
eventID: string,
options?: { isPrefetch?: boolean },
): Promise<Alg> {
function wasm(): Promise<Alg> {
return measurePerf(
`wasmRandomScrambleForEvent(${JSON.stringify(eventID)})`,
() => wasmRandomScrambleForEvent(eventID),
{
isPrefetch: options?.isPrefetch,
},
);
}

switch (eventID) {
// case "333":
case "222":
return (await wasm()).experimentalSimplify({
puzzleSpecificSimplifyOptions: {
quantumMoveOrder: () => 4,
},
});
// case "444":
case "555":
case "666":
Expand All @@ -103,13 +118,7 @@ async function randomScrambleForEvent(
// case "master_tetraminx":
// case "kilominx":
// case "redi_cube":m
return measurePerf(
`wasmRandomScrambleForEvent(${JSON.stringify(eventID)})`,
() => wasmRandomScrambleForEvent(eventID),
{
isPrefetch: options?.isPrefetch,
},
);
return wasm();
case "333":
case "333oh":
case "333ft":
Expand Down Expand Up @@ -234,7 +243,7 @@ export const insideAPI = {

solve222ToString: async (patternData: KPatternData): Promise<string> => {
const pattern = new KPattern(await puzzles["2x2x2"].kpuzzle(), patternData);
return (await solve222HTMSubOptimal(pattern)).toString();
return (await solve222(pattern)).toString();
},

solveSkewbToString: async (patternData: KPatternData): Promise<string> => {
Expand Down
35 changes: 1 addition & 34 deletions src/cubing/search/inside/solve/puzzles/2x2x2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type { Alg } from "../../../../alg";
import type { KPuzzle } from "../../../../kpuzzle";
import { KPattern } from "../../../../kpuzzle";
import { cube2x2x2, puzzles } from "../../../../puzzles";
import { experimentalNormalize2x2x2Orientation } from "../../../../puzzles/cubing-private";
import { mustBeInsideWorker } from "../../inside-worker";
import type { SGSCachedData } from "../parseSGS";
import { TrembleSolver } from "../tremble";
Expand Down Expand Up @@ -31,43 +30,11 @@ export async function preInitialize222(): Promise<void> {
await getCachedTrembleSolver();
}

export async function solve222HTMSubOptimal(
pattern: KPattern,
maxDepth: number = 11,
): Promise<Alg> {
mustBeInsideWorker();
return await wasmTwsearch((await cube2x2x2.kpuzzle()).definition, pattern, {
generatorMoves: "UFLR".split(""), // TODO: <U, F, R>
maxDepth,
});
}

// TODO: fix def consistency.
// TODO: why is this ending up with the wrong rotation sometimes?
export async function solve222HTMOptimal(
pattern: KPattern,
maxDepth: number = 11,
): Promise<Alg> {
mustBeInsideWorker();
const { normalizedPattern, normalizationAlg } =
experimentalNormalize2x2x2Orientation(pattern);
const orientedResult = await wasmTwsearch(
(await cube2x2x2.kpuzzle()).definition,
normalizedPattern,
{
generatorMoves: "UFLR".split(""), // TODO: <U, F, R>
maxDepth,
},
);
return normalizationAlg.concat(orientedResult);
}

// TODO: fix def consistency.
export async function solve222ForScramble(pattern: KPattern): Promise<Alg> {
export async function solve222(pattern: KPattern): Promise<Alg> {
mustBeInsideWorker();
return wasmTwsearch((await cube2x2x2.kpuzzle()).definition, pattern, {
generatorMoves: "UFLR".split(""),
minDepth: 11,
});
}

Expand Down

0 comments on commit c62f0b1

Please sign in to comment.