solve_file.c (1700B)
1 #include "../tool.h" 2 3 #define SOL_BUFFER_LEN 1000 4 #define MAX_SCR 10000 5 #define MAX_SCR_LEN 250 6 7 char *solver; 8 int64_t size = 0, N = 0; 9 unsigned char *buf; 10 char scrambles[MAX_SCR][MAX_SCR_LEN]; 11 12 void run(void) { 13 int64_t i, nsols; 14 long long stats[NISSY_SIZE_SOLVE_STATS]; 15 char sol[SOL_BUFFER_LEN], cube[NISSY_SIZE_CUBE]; 16 17 printf("Solved the following scrambles:\n\n"); 18 for (i = 0; i < N; i++) { 19 printf("%" PRId64 ". %s\n", i+1, scrambles[i]); 20 printf("Solving scramble %s\n", scrambles[i]); 21 if (nissy_applymoves(NISSY_SOLVED_CUBE, scrambles[i], cube) 22 == -1) { 23 printf("Invalid scramble\n"); 24 continue; 25 } 26 nsols = nissy_solve(cube, solver, NISSY_NISSFLAG_NORMAL, 27 0, 20, 1, -1, 0, size, buf, SOL_BUFFER_LEN, sol, stats, 28 NULL, NULL); 29 if (nsols == 0) 30 printf("No solution found\n"); 31 else 32 printf("Solutions:\n%s\n", sol); 33 } 34 } 35 36 int main(int argc, char **argv) { 37 char filename[255], dataid[NISSY_SIZE_DATAID], *scrfilename; 38 FILE *scrfile; 39 40 if (argc < 3) { 41 printf("Error: not enough arguments. " 42 "A solver and a scramble file must be given.\n"); 43 return 1; 44 } 45 46 solver = argv[1]; 47 scrfilename = argv[2]; 48 49 srand(time(NULL)); 50 nissy_setlogger(log_stderr, NULL); 51 52 sprintf(filename, "tables/%s", solver); 53 if (getdata(solver, &buf, filename) != 0) 54 return 1; 55 56 size = nissy_solverinfo(solver, dataid); 57 58 if ((scrfile = fopen(scrfilename, "r")) == NULL) { 59 printf("Error: could not read given file '%s'.\n", 60 scrfilename); 61 return 1; 62 } 63 64 printf("Reading scrambles from file '%s'.\n", scrfilename); 65 for (N = 0; fgets(scrambles[N], MAX_SCR_LEN, scrfile) != NULL; N++) ; 66 fclose(scrfile); 67 68 timerun(run); 69 70 free(buf); 71 return 0; 72 }