solve_small.c (1473B)
1 #include "../tool.h" 2 3 #define SOL_BUFFER_LEN 1000 4 5 char *solver; 6 int64_t size = 0; 7 char *buf; 8 9 char *scrambles[] = { 10 /* 12 optimal */ 11 "R D' R2 D R U2 R' D' R U2 R D R'", 12 13 /* 12 optimal */ 14 "RLUD RLUD RLUD", 15 16 /* FMC2019 A1 - 16 optimal */ 17 "R' U' F D2 L2 F R2 U2 R2 B D2 L B2 D' B2 L' R' B D2 B U2 L U2 R' U' F", 18 19 /* FMC2024 A1 - 19 optimal */ 20 "R' U' F D R F2 D L F D2 F2 L' U R' L2 D' R2 F2 R2 D L2 U2 R' U' F", 21 NULL 22 }; 23 24 void run(void) { 25 int i; 26 int64_t n; 27 long long stats[NISSY_SIZE_SOLVE_STATS]; 28 char sol[SOL_BUFFER_LEN], cube[22]; 29 30 printf("Solved the following scrambles:\n\n"); 31 for (i = 0; scrambles[i] != NULL; i++) { 32 printf("%d. %s\n", i+1, scrambles[i]); 33 printf("Solving scramble %s\n", scrambles[i]); 34 if (nissy_applymoves(NISSY_SOLVED_CUBE, scrambles[i], cube) 35 == -1) { 36 printf("Invalid scramble\n"); 37 continue; 38 } 39 n = nissy_solve(cube, solver, NISSY_NISSFLAG_NORMAL, 40 0, 20, 1, -1, size, buf, SOL_BUFFER_LEN, sol, stats); 41 if (n == 0) 42 printf("No solution found\n"); 43 else 44 printf("Solutions:\n%s\n", sol); 45 } 46 } 47 48 int main(int argc, char **argv) { 49 char filename[255]; 50 51 if (argc < 2) { 52 printf("Error: not enough arguments. " 53 "A solver must be given.\n"); 54 return 1; 55 } 56 57 solver = argv[1]; 58 srand(time(NULL)); 59 nissy_setlogger(log_stderr); 60 61 62 sprintf(filename, "tables/%s", solver); 63 if (getdata(solver, &buf, filename) != 0) 64 return 1; 65 66 size = nissy_datasize(solver); 67 68 timerun(run); 69 70 free(buf); 71 return 0; 72 }