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