Skip to content

Commit

Permalink
Merge pull request #62 from torjusti/fix/52
Browse files Browse the repository at this point in the history
Fix issue #52
  • Loading branch information
torjusti authored Aug 8, 2021
2 parents 626efbb + 91eb517 commit 29ae40f
Show file tree
Hide file tree
Showing 6 changed files with 2,221 additions and 1,680 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cube-solver",
"version": "2.4.0",
"version": "2.4.1",
"description": "Solve Rubik's cube using the Kociemba algorithm.",
"author": "Torjus Iveland <torjusti@gmail.com>",
"main": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion src/Search.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class Search {
const formatted = formatAlgorithm(solution.solution);

if (solutionRotation) {
// If we have rotations in the scramble, apply them to the solution
// If we have rotations in the scramble, apply the inverse to the solution
// and then parse again to remove the rotations. This results in a
// solution that can be applied from the result scramble orientation.
return formatAlgorithm(parseAlgorithm(`${solutionRotation} ${formatted}`));
Expand Down
8 changes: 6 additions & 2 deletions src/algorithms.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,14 @@ const normalize = (moves) => {
// Replace wide moves with rotations + moves.
moves = moves.reduce((acc, move) => {
const axis = move.charAt(0);
const pow = move.charAt(1);
const pow = powers[move.charAt(1)];

if (wideMoves[axis]) {
return acc.concat(wideMoves[axis].map((m) => m + pow));
for (let i = 0; i <= pow; i += 1) {
acc = acc.concat(wideMoves[axis]);
}

return acc;
}

return acc.concat(move);
Expand Down
31 changes: 29 additions & 2 deletions src/tests/__snapshots__/algorithms.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,37 @@ Array [
3,
9,
8,
11,
9,
9,
9,
8,
3,
9,
5,
3,
3,
3,
]
`;

exports[`algorithms should strip rotations from algorithms correctly 2`] = `
Array [
9,
9,
9,
6,
6,
6,
0,
0,
0,
6,
6,
6,
9,
9,
9,
6,
6,
6,
]
`;
6 changes: 5 additions & 1 deletion src/tests/algorithms.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as algorithms from '../algorithms';

describe('algorithms', () => {
it('allow parsing invalid algorithms', () => {
it('should not allow parsing invalid algorithms', () => {
expect(() => {
algorithms.parseAlgorithm("R U R' U' 1337 R' F R F'");
}).toThrowError();
Expand All @@ -15,5 +15,9 @@ describe('algorithms', () => {
it('should strip rotations from algorithms correctly', () => {
expect(algorithms.parseAlgorithm("x R u R' u' y' z2 R' f R f'"))
.toMatchSnapshot();

// Regression: Wide moves described using inverted rotations would
// add powers multiple times to a single move, crashing the parser.
expect(algorithms.parseAlgorithm("f' r' u' b' l' d'")).toMatchSnapshot();
});
});
Loading

0 comments on commit 29ae40f

Please sign in to comment.