Skip to content

Commit

Permalink
Fix double slice moves
Browse files Browse the repository at this point in the history
  • Loading branch information
simonkellly committed May 20, 2024
1 parent f3d4d20 commit f8035b6
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 12 deletions.
4 changes: 3 additions & 1 deletion src/components/timer/timerStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ async function setScrambleFromCubeState(originalScramble: Alg | string) {
.applyAlg(scrambleAlg.invert())
.applyAlg(solved.invert());

const customScramble = await experimentalSolve3x3x3IgnoringCenters(newPattern);
const customScramble =
await experimentalSolve3x3x3IgnoringCenters(newPattern);
TimerStore.setState(state => ({
...state,
scrambleAlg: scrambleAlg.toString(),
Expand Down Expand Up @@ -161,6 +162,7 @@ export const useCubeTimer = () => {

console.log('Scramble:', TimerStore.state.originalScramble);
console.log(algs.join('\n'));
console.log('Solution:', solution);

newScramble();
};
Expand Down
44 changes: 34 additions & 10 deletions src/lib/solutionParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,15 @@ export function convertToSliceMoves(moves: string[]) {
}

const moveFace = move[0];
if (
moveFace != opposite[lastMove[0]] ||
move.length + lastMove.length != 3
) {
const isOppositeFaces = moveFace == opposite[lastMove[0]];
const isBothTwo =
move.length == 2 &&
move[1] === '2' &&
lastMove.length == 2 &&
lastMove[1] === '2';
const isAltDirections = move.length + lastMove.length == 3;

if (!isOppositeFaces || !(isBothTwo || isAltDirections)) {
lastMove = move;
newMoves.push(move);
return;
Expand All @@ -124,6 +129,11 @@ export function convertToSliceMoves(moves: string[]) {
newMoves.push('x');
}

if (lower == 'L2') {
newMoves.push('M2');
newMoves.push('x2');
}

if (lower == 'B') {
newMoves.push('S');
newMoves.push("z'");
Expand All @@ -133,6 +143,10 @@ export function convertToSliceMoves(moves: string[]) {
newMoves.push("S'");
newMoves.push('z');
}
if (lower == 'B2') {
newMoves.push('S2');
newMoves.push('z2');
}

if (lower == 'D') {
newMoves.push("E'");
Expand All @@ -144,6 +158,11 @@ export function convertToSliceMoves(moves: string[]) {
newMoves.push('y');
}

if (lower == 'D2') {
newMoves.push('E2');
newMoves.push('y2');
}

lastMove = null;
});

Expand Down Expand Up @@ -221,12 +240,15 @@ function uncancelTransformation(
return null;
}

function simplify(alg: string) {
export function simplify(alg: string) {
return Alg.fromString(alg)
.experimentalSimplify({
cancel: { puzzleSpecificModWrap: 'canonical-centered' },
cancel: {
puzzleSpecificModWrap: 'canonical-centered',
directional: 'any-direction',
},
puzzleLoader: cube3x3x3,
depth: 0,
depth: 1,
})
.toString();
}
Expand Down Expand Up @@ -266,10 +288,12 @@ export async function extractAlgs(solution: string): Promise<string[]> {
if (moves.length > 0) comms.push(moves);

return comms.map(comm => {
const alg = simplify(
removeRotations(convertToSliceMoves(simplify(comm).split(' '))).join(' ')
);
console.log(alg);
let foundComm = commutator.search({
algorithm: simplify(
removeRotations(convertToSliceMoves(comm.split(' '))).join(' ')
),
algorithm: alg,
outerBracket: true,
})[0];

Expand Down
14 changes: 13 additions & 1 deletion tests/parse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,18 @@ test('Extract slice alg (FK)', async () => {
expect(extracted[0]).toBe("[S U L: [E', L2]]");
});

test('Extract slice alg (GJ) with double moves', async () => {
const extracted = await extractAlgs("R' L F R' F' L R' D R D' L L R' R'");
expect(extracted.length).toBe(1);
expect(extracted[0]).toBe("[S U L: [E', L2]]");
});

test('Extract slice alg (FK) with extra moves', async () => {
const extracted = await extractAlgs(
"R U B D D' B' U' R' F' B L D L' R F' F' L R' D L' F B'"
);
expect(extracted.length).toBe(1);
expect(extracted[0]).toBe("[S U L: [E', L2]]");
expect(extracted[0]).toBe("[M': [U R' U', M']]");
});

test('Converts slice moves M', () => {
Expand All @@ -61,3 +67,9 @@ test('Converts slice moves S', () => {
const converted = convertToSliceMoves(alg.split(' '));
expect(converted.join(' ')).toBe("S' z");
});

test('Converts double moves to slice moves', () => {
const alg = 'F2 B2';
const converted = convertToSliceMoves(alg.split(' '));
expect(converted.join(' ')).toBe('S2 z2');
});

0 comments on commit f8035b6

Please sign in to comment.