Skip to content

Commit

Permalink
Fix analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
simonkellly committed May 25, 2024
1 parent dfab86c commit 0709114
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 20 deletions.
9 changes: 5 additions & 4 deletions src/lib/dnfAnalyser.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Alg } from 'cubing/alg';
import { KPattern, KTransformation } from 'cubing/kpuzzle';
import { cube3x3x3 } from 'cubing/puzzles';
import { extractAlgs } from './solutionParser';
import { Penalty } from './db';
import { extractAlgs } from './solutionParser';

export const SOLVED = 'Solved';
export const PLUS_TWO = '+2';
Expand Down Expand Up @@ -173,10 +173,12 @@ function checkPlusTwo(solvedState: KTransformation, solvedPattern: KPattern) {
}
}
return false;

}

export async function penaltyChecker(scramble: string, solution: string): Promise<Penalty> {
export async function penaltyChecker(
scramble: string,
solution: string
): Promise<Penalty> {
const puzzle = await cube3x3x3.kpuzzle();

const scrambleTransformation = puzzle.algToTransformation(scramble);
Expand Down Expand Up @@ -218,7 +220,6 @@ export async function dnfAnalyser(

if (isSolved) return SOLVED;


const isInverseAlg = checkInverseAlg(
scramblePattern,
algs.map(a => a[0])
Expand Down
5 changes: 4 additions & 1 deletion src/lib/solutionParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,10 @@ export async function extractAlgs(
}

return [
foundComm.replaceAll(',', ', ').replaceAll(':', ': '),
foundComm
.replaceAll(',', ', ')
.replaceAll(':', ': ')
.replaceAll('][', '] ['),
comment,
moveIdx,
];
Expand Down
24 changes: 11 additions & 13 deletions src/timer/resultsCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function SolveDialog({
const deleteSolve = () => {
db.solves.delete(solve.id);
close(false);
}
};

const solutionStr = solve.solution.map(s => s.move).join(' ');

Expand All @@ -73,11 +73,13 @@ function SolveDialog({
? `DNF(${convertTimeToText(solve.time)})`
: convertSolveToText(solve);

const twistyUrl = 'https://alpha.twizzle.net/edit/?' + new URLSearchParams({
"setup-alg": solve.scramble,
"alg": solve.parsed?.join('\n') || solutionStr,
}).toString();

const twistyUrl =
'https://alpha.twizzle.net/edit/?' +
new URLSearchParams({
'setup-alg': solve.scramble,
alg: solve.parsed?.join('\n') || solutionStr,
}).toString();

return (
<Dialog open={true} onOpenChange={close}>
<DialogContent className="sm:max-w-[425px]">
Expand All @@ -103,18 +105,14 @@ function SolveDialog({
<li className="font-medium">Algs in solve:</li>
<ScrollArea className="h-64">
{!solve.parsed && solutionStr}
{solve.parsed && solve.parsed.map((alg, i) => (
<li key={i + ' ' + alg}>{alg}</li>
))}
{solve.parsed &&
solve.parsed.map((alg, i) => <li key={i + ' ' + alg}>{alg}</li>)}
</ScrollArea>
</ul>
{analysis && <p className="font-medium">{analysis}</p>}
<DialogFooter>

<Button type="submit" asChild>
<a href={twistyUrl}>
Twisty
</a>
<a href={twistyUrl}>Twisty</a>
</Button>
<Button variant="secondary" type="button" onClick={analyse}>
Analyse
Expand Down
6 changes: 4 additions & 2 deletions src/timer/useCubeTimer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,10 @@ export default function useCubeTimer() {
const solution = solutionMoves.map(move => move.move);
const solutionStr = solution.join(' ');

const penalty = await penaltyChecker(TimerStore.state.originalScramble, solutionStr);
const penalty = await penaltyChecker(
TimerStore.state.originalScramble,
solutionStr
);

newScramble();

Expand All @@ -147,7 +150,6 @@ export default function useCubeTimer() {
} as Solve;

await db.solves.add(solve);

}, [stopwatch]);

const updateStateFromSpaceBar = useCallback(
Expand Down

0 comments on commit 0709114

Please sign in to comment.