diff options
Diffstat (limited to '')
| -rw-r--r-- | tools/302_solve_multisol/solve_multisol.c | 2 | ||||
| -rw-r--r-- | tools/500_pause_resume_stop/pause_resume_stop.c | 89 |
2 files changed, 90 insertions, 1 deletions
diff --git a/tools/302_solve_multisol/solve_multisol.c b/tools/302_solve_multisol/solve_multisol.c index 8f04b5f..a3dfd1f 100644 --- a/tools/302_solve_multisol/solve_multisol.c +++ b/tools/302_solve_multisol/solve_multisol.c | |||
| @@ -25,7 +25,7 @@ void run(void) { | |||
| 25 | printf("%d. %s\n", i+1, scrambles[i]); | 25 | printf("%d. %s\n", i+1, scrambles[i]); |
| 26 | printf("Solving scramble %s\n", scrambles[i]); | 26 | printf("Solving scramble %s\n", scrambles[i]); |
| 27 | if (nissy_applymoves(NISSY_SOLVED_CUBE, scrambles[i], cube) | 27 | if (nissy_applymoves(NISSY_SOLVED_CUBE, scrambles[i], cube) |
| 28 | == -1) { | 28 | != NISSY_OK) { |
| 29 | printf("Invalid scramble\n"); | 29 | printf("Invalid scramble\n"); |
| 30 | continue; | 30 | continue; |
| 31 | } | 31 | } |
diff --git a/tools/500_pause_resume_stop/pause_resume_stop.c b/tools/500_pause_resume_stop/pause_resume_stop.c new file mode 100644 index 0000000..ae3b67f --- /dev/null +++ b/tools/500_pause_resume_stop/pause_resume_stop.c | |||
| @@ -0,0 +1,89 @@ | |||
| 1 | #include "../tool.h" | ||
| 2 | |||
| 3 | /* | ||
| 4 | This tool starts solving a scramble. It then runs for SOLVE_LEN seconds, | ||
| 5 | pauses for PAUSE_LEN seconds, runs again for SOLVE_LEN seconds and so on, | ||
| 6 | until eventually stopping after TOTAL_LEN seconds. | ||
| 7 | */ | ||
| 8 | |||
| 9 | #define SOL_BUFFER_LEN 10000 | ||
| 10 | |||
| 11 | #define SOLVE_LEN 3000 | ||
| 12 | #define PAUSE_LEN 1500 | ||
| 13 | #define TOTAL_LEN 30000 | ||
| 14 | |||
| 15 | char *scramble = | ||
| 16 | "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"; | ||
| 17 | |||
| 18 | char *solver; | ||
| 19 | int64_t size = 0; | ||
| 20 | unsigned char *buf; | ||
| 21 | |||
| 22 | int get_status(void *arg) { | ||
| 23 | struct timespec start, now; | ||
| 24 | double tdsec, tdnano; | ||
| 25 | int tdiff; | ||
| 26 | |||
| 27 | start = *(struct timespec *)arg; | ||
| 28 | clock_gettime(CLOCK_MONOTONIC, &now); | ||
| 29 | |||
| 30 | tdsec = now.tv_sec - start.tv_sec; | ||
| 31 | tdnano = now.tv_nsec - start.tv_nsec; | ||
| 32 | tdiff = 1000 * (tdsec + 1e-9 * tdnano); | ||
| 33 | |||
| 34 | fprintf(stderr, "[tool] Status polled at %dms: ", tdiff); | ||
| 35 | |||
| 36 | if (tdiff > TOTAL_LEN) { | ||
| 37 | fprintf(stderr, "Total time elapsed, stopping\n"); | ||
| 38 | return NISSY_STATUS_STOP; | ||
| 39 | } | ||
| 40 | |||
| 41 | if (tdiff % (SOLVE_LEN + PAUSE_LEN) < SOLVE_LEN) { | ||
| 42 | fprintf(stderr, "Running\n"); | ||
| 43 | return NISSY_STATUS_RUN; | ||
| 44 | } | ||
| 45 | |||
| 46 | fprintf(stderr, "Pausing\n"); | ||
| 47 | return NISSY_STATUS_PAUSE; | ||
| 48 | } | ||
| 49 | |||
| 50 | void run(void) { | ||
| 51 | int64_t n; | ||
| 52 | long long stats[NISSY_SIZE_SOLVE_STATS]; | ||
| 53 | char sol[SOL_BUFFER_LEN], cube[NISSY_SIZE_CUBE]; | ||
| 54 | struct timespec starttime; | ||
| 55 | |||
| 56 | nissy_applymoves(NISSY_SOLVED_CUBE, scramble, cube); | ||
| 57 | clock_gettime(CLOCK_MONOTONIC, &starttime); | ||
| 58 | n = nissy_solve(cube, solver, NISSY_NISSFLAG_NORMAL, | ||
| 59 | 0, 20, 100, -1, 0, size, buf, SOL_BUFFER_LEN, sol, stats, | ||
| 60 | get_status, &starttime); | ||
| 61 | if (n == 0) | ||
| 62 | printf("No solution found\n"); | ||
| 63 | else | ||
| 64 | printf("Solutions:\n%s\n", sol); | ||
| 65 | } | ||
| 66 | |||
| 67 | int main(int argc, char **argv) { | ||
| 68 | char filename[255], dataid[NISSY_SIZE_DATAID]; | ||
| 69 | |||
| 70 | if (argc < 2) { | ||
| 71 | printf("Error: not enough arguments. " | ||
| 72 | "A solver and must be given.\n"); return 1; | ||
| 73 | } | ||
| 74 | |||
| 75 | solver = argv[1]; | ||
| 76 | srand(time(NULL)); | ||
| 77 | nissy_setlogger(log_stderr, NULL); | ||
| 78 | |||
| 79 | sprintf(filename, "tables/%s", solver); | ||
| 80 | if (getdata(solver, &buf, filename) != 0) | ||
| 81 | return 1; | ||
| 82 | |||
| 83 | size = nissy_solverinfo(solver, dataid); | ||
| 84 | |||
| 85 | timerun(run); | ||
| 86 | |||
| 87 | free(buf); | ||
| 88 | return 0; | ||
| 89 | } | ||
