Skip to content

Commit

Permalink
Scramble generation.
Browse files Browse the repository at this point in the history
  • Loading branch information
lgarron committed Oct 23, 2024
1 parent 0cf6f0c commit 68af915
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
Binary file modified bun.lockb
Binary file not shown.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
"devDependencies": {
"@biomejs/biome": "^1.9.4",
"@types/bun": "^1.1.12",
"barely-a-dev-server": "^0.6.1",
"barely-a-dev-server": "^0.6.2",
"csv-parse": "^5.5.6",
"cubing": "^0.31.6",
"esbuild": "0.23.0",
"cubing": "^0.52.3",
"esbuild": "0.24.0",
"serve": "^14.2.4",
"typescript": "^4.8.4"
"typescript": "^5.6.3"
}
}
37 changes: 37 additions & 0 deletions script/generate-scrambles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { rm } from "node:fs/promises";
import { join } from "node:path";
import { file, write } from "bun";
import { twizzleEvents } from "cubing/puzzles";
import { randomScrambleForEvent } from "cubing/scramble";

const allScrambles: Record<string, string[]> = {};

const outputDir = "./dist/scrambles";

rm(outputDir, { recursive: true, force: true });

for (const [event, info] of Object.entries(twizzleEvents)) {
try {
console.log(`[${info.eventName}] Generating…`);
const numScrambles = event === "333mbf" ? 100 : 1;
const eventScrambles: string[] = [];
for (let i = 0; i < numScrambles; i++) {
eventScrambles.push((await randomScrambleForEvent(event)).toString());
}
write(
file(join(outputDir, `${info.eventName}.txt`)),
eventScrambles.join("\n////////\n"),
);
allScrambles[event] = eventScrambles;
} catch (e) {
if (e.toString().includes("unsupported event")) {
continue;
}
throw e;
}
}

write(
file(join(outputDir, "scrambles.json")),
JSON.stringify(allScrambles, null, " "),
);

0 comments on commit 68af915

Please sign in to comment.