Skip to content

Commit

Permalink
Merge pull request #131 from bryanlundberg/add--megaminx-sq1-scrambles
Browse files Browse the repository at this point in the history
add scrambow
  • Loading branch information
bryanlundberg authored Oct 27, 2023
2 parents 3e8d8ad + 273c3be commit 2b46d46
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 50 deletions.
20 changes: 20 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"react": "18.2.0",
"react-dom": "18.2.0",
"recharts": "^2.8.0",
"scrambow": "^1.8.1",
"sharp": "0.32.5",
"tailwindcss": "3.3.3",
"typescript": "5.2.2",
Expand Down
54 changes: 4 additions & 50 deletions src/lib/timer/genScramble.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,7 @@
import { possibleMoves2x2 } from "./moves/possible-moves-2x2.js";
import { possibleMoves3x3 } from "./moves/possible-moves-3x3.js";
import { possibleMoves4x4 } from "./moves/possible-moves-4x4.js";
import { possibleMoves5x5 } from "./moves/possible-moves-5x5.js";
import { possibleMoves6x6 } from "./moves/possible-moves-6x6.js";
import { possibleMoves7x7 } from "./moves/possible-moves-7x7.js";
import { possibleMovesPyraminx } from "./moves/possible-moves-pyraminx.js";
import { possibleMovesSkewb } from "./moves/possible-moves-skewb.js";
import { Scrambow } from "scrambow";

export default function genScramble(category) {
let possibleMoves;
let scrambleSize;
if (category === "2x2") {
possibleMoves = possibleMoves2x2;
scrambleSize = 9;
} else if (category === "3x3" || category === "3x3 OH") {
possibleMoves = possibleMoves3x3;
scrambleSize = 20;
} else if (category === "4x4") {
possibleMoves = possibleMoves4x4;
scrambleSize = 40;
} else if (category === "5x5") {
possibleMoves = possibleMoves5x5;
scrambleSize = 60;
} else if (category === "6x6") {
possibleMoves = possibleMoves6x6;
scrambleSize = 80;
} else if (category === "7x7") {
possibleMoves = possibleMoves7x7;
scrambleSize = 100;
} else if (category === "Skewb") {
possibleMoves = possibleMovesSkewb;
scrambleSize = 8;
} else if (category === "Pyraminx") {
possibleMoves = possibleMovesPyraminx;
scrambleSize = 11;
} else {
return "Invalid category";
}

const scramble = [];
let lastMove = "";

for (let i = 0; i < scrambleSize; i++) {
let move = possibleMoves[Math.floor(Math.random() * possibleMoves.length)];
while (move.charAt(0) === lastMove.charAt(0)) {
move = possibleMoves[Math.floor(Math.random() * possibleMoves.length)];
}
scramble.push(move);
lastMove = move;
}
return scramble.join(" ");
const scramble = new Scrambow(category);
const newScramble = scramble.get(1);
return newScramble[0].scramble_string;
}

0 comments on commit 2b46d46

Please sign in to comment.