diff options
Diffstat (limited to 'tools/301_solve_file/solve_file.c')
| -rw-r--r-- | tools/301_solve_file/solve_file.c | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/tools/301_solve_file/solve_file.c b/tools/301_solve_file/solve_file.c new file mode 100644 index 0000000..aa45df0 --- /dev/null +++ b/tools/301_solve_file/solve_file.c | |||
| @@ -0,0 +1,71 @@ | |||
| 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 | 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[22]; | ||
| 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, size, buf, SOL_BUFFER_LEN, sol, stats); | ||
| 28 | if (nsols == 0) | ||
| 29 | printf("No solution found\n"); | ||
| 30 | else | ||
| 31 | printf("Solutions:\n%s\n", sol); | ||
| 32 | } | ||
| 33 | } | ||
| 34 | |||
| 35 | int main(int argc, char **argv) { | ||
| 36 | char filename[255], *scrfilename; | ||
| 37 | FILE *scrfile; | ||
| 38 | |||
| 39 | if (argc < 3) { | ||
| 40 | printf("Error: not enough arguments. " | ||
| 41 | "A solver and a scramble file must be given.\n"); | ||
| 42 | return 1; | ||
| 43 | } | ||
| 44 | |||
| 45 | solver = argv[1]; | ||
| 46 | scrfilename = argv[2]; | ||
| 47 | |||
| 48 | srand(time(NULL)); | ||
| 49 | nissy_setlogger(log_stderr); | ||
| 50 | |||
| 51 | sprintf(filename, "tables/%s", solver); | ||
| 52 | if (getdata(solver, &buf, filename) != 0) | ||
| 53 | return 1; | ||
| 54 | |||
| 55 | size = nissy_datasize(solver); | ||
| 56 | |||
| 57 | if ((scrfile = fopen(scrfilename, "r")) == NULL) { | ||
| 58 | printf("Error: could not read given file '%s'.\n", | ||
| 59 | scrfilename); | ||
| 60 | return 1; | ||
| 61 | } | ||
| 62 | |||
| 63 | printf("Reading scrambles from file '%s'.\n", scrfilename); | ||
| 64 | for (N = 0; fgets(scrambles[N], MAX_SCR_LEN, scrfile) != NULL; N++) ; | ||
| 65 | fclose(scrfile); | ||
| 66 | |||
| 67 | timerun(run); | ||
| 68 | |||
| 69 | free(buf); | ||
| 70 | return 0; | ||
| 71 | } | ||
