Skip to content

Commit

Permalink
Support 2e2c algs
Browse files Browse the repository at this point in the history
  • Loading branch information
simonkellly committed May 22, 2024
1 parent 8b79411 commit a439417
Showing 1 changed file with 32 additions and 11 deletions.
43 changes: 32 additions & 11 deletions src/lib/solutionParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,10 @@ export function convertToSliceMoves(moves: string[]) {
return newMoves;
}

function checkTransformationIs3Cycle(

function checkTransformationIsAlg(
transformation: KTransformation
): [isEdge: boolean, isCorner: boolean] {
): [isEdge3Cycle: boolean, isCorner3Cycle: boolean, is2E2C: boolean] {
const corners = transformation.transformationData['CORNERS'];
const edges = transformation.transformationData['EDGES'];

Expand All @@ -237,7 +238,7 @@ function checkTransformationIs3Cycle(
const positionMatches = corners.permutation[i] == i;
const orientationMatches = corners.orientationDelta[i] == 0;

if (positionMatches && !orientationMatches) return [false, false];
if (positionMatches && !orientationMatches) return [false, false, false];
if (positionMatches && orientationMatches) cornerCount++;
}

Expand All @@ -246,13 +247,14 @@ function checkTransformationIs3Cycle(
const positionMatches = edges.permutation[i] == i;
const orientationMatches = edges.orientationDelta[i] == 0;

if (positionMatches && !orientationMatches) return [false, false];
if (positionMatches && !orientationMatches) return [false, false, false];
if (positionMatches && orientationMatches) edgeCount++;
}

return [
cornerCount == 8 && edgeCount == 9,
cornerCount == 5 && edgeCount == 12,
cornerCount == 6 && edgeCount == 10,
];
}

Expand All @@ -263,14 +265,16 @@ function uncancelTransformation(
alg: string;
isEdge: boolean;
isCorner: boolean;
is2E2C: boolean;
length: number;
} {
const initialCheck = checkTransformationIs3Cycle(transformation);
if (initialCheck[0] || initialCheck[1]) {
const initialCheck = checkTransformationIsAlg(transformation);
if (initialCheck[0] || initialCheck[1] || initialCheck[2]) {
return {
alg: '',
isEdge: initialCheck[0],
isCorner: initialCheck[1],
is2E2C: initialCheck[2],
length: 0,
};
}
Expand All @@ -285,12 +289,13 @@ function uncancelTransformation(
for (const amount of POSSIBLE_AMOUNTS) {
const newAlg = `${alg} ${move}${amount}`;
const newTransformation = transformation.applyAlg(`${move}${amount}`);
const check = checkTransformationIs3Cycle(newTransformation);
if (check[0] || check[1]) {
const check = checkTransformationIsAlg(newTransformation);
if (check[0] || check[1] || check[2]) {
return {
alg: newAlg.trimStart(),
isEdge: check[0],
isCorner: check[1],
is2E2C: check[2],
length: depth,
};
}
Expand Down Expand Up @@ -321,7 +326,13 @@ export function simplify(alg: string) {
export async function extractAlgs(
moveSet: string[]
): Promise<[string, number][]> {
const comms: [string, number, boolean, boolean][] = [];
const comms: [
alg: string,
moveIdx: number,
isEdge: boolean,
isCorner: boolean,
is2E2C: boolean
][] = [];

let moves = '';
let count = 0;
Expand All @@ -348,6 +359,7 @@ export async function extractAlgs(
moveIdx,
uncancelled.isEdge,
uncancelled.isCorner,
uncancelled.is2E2C,
]);

count = uncancelled.length;
Expand All @@ -357,10 +369,10 @@ export async function extractAlgs(
}

if (moves.length > 0) {
const [isEdge, isCorner] = checkTransformationIs3Cycle(
const [isEdge, isCorner, is2E2C] = checkTransformationIsAlg(
puzzle.algToTransformation(moves)
);
comms.push([moves, moveIdx, isEdge, isCorner]);
comms.push([moves, moveIdx, isEdge, isCorner, is2E2C]);
}

return comms.map(val => {
Expand All @@ -369,6 +381,14 @@ export async function extractAlgs(
const simplifiedComm = simplify(comm);
let foundComm: string | undefined;

const is2E2C = val[4];
if (is2E2C) {
return [simplifiedComm.toString(), val[1]] as [
string,
number,
];
}

const isEdgeComm = val[2];
if (isEdgeComm) {
const slicesWithRotations = convertToSliceMoves(
Expand Down Expand Up @@ -409,3 +429,4 @@ export async function extractAlgs(
];
});
}

0 comments on commit a439417

Please sign in to comment.