diff options
Diffstat (limited to 'tools/400_solvetest/solve_test.c')
| -rw-r--r-- | tools/400_solvetest/solve_test.c | 120 |
1 files changed, 0 insertions, 120 deletions
diff --git a/tools/400_solvetest/solve_test.c b/tools/400_solvetest/solve_test.c deleted file mode 100644 index 73e6e8e..0000000 --- a/tools/400_solvetest/solve_test.c +++ /dev/null | |||
| @@ -1,120 +0,0 @@ | |||
| 1 | #include "../tool.h" | ||
| 2 | #include "scrambles.h" | ||
| 3 | |||
| 4 | #define SOL_BUFFER_LEN 100000 | ||
| 5 | |||
| 6 | char *solver; | ||
| 7 | int64_t size = 0; | ||
| 8 | unsigned char *buf; | ||
| 9 | |||
| 10 | bool check_one(char *actual, char *expected) { | ||
| 11 | unsigned i; | ||
| 12 | size_t l_actual, l_expected; | ||
| 13 | |||
| 14 | for (l_actual = 0; actual[l_actual] != '\n'; l_actual++) ; | ||
| 15 | l_expected = strlen(expected); | ||
| 16 | if (l_actual > l_expected) | ||
| 17 | return false; | ||
| 18 | for (i = 0; i < l_expected; i++) { | ||
| 19 | if (!strncmp(actual, &expected[i], l_actual)) | ||
| 20 | return true; | ||
| 21 | while(expected[i] != '\n') i++; | ||
| 22 | } | ||
| 23 | return false; | ||
| 24 | } | ||
| 25 | |||
| 26 | bool check_all(char *actual, char *expected) { | ||
| 27 | unsigned i, found, n_expected; | ||
| 28 | size_t l_actual; | ||
| 29 | |||
| 30 | l_actual = strlen(actual); | ||
| 31 | if (l_actual != strlen(expected)) | ||
| 32 | return false; | ||
| 33 | |||
| 34 | for (i = 0, n_expected = 0; expected[i]; i++) | ||
| 35 | n_expected += expected[i] == '\n'; | ||
| 36 | |||
| 37 | for (i = 0, found = 0; i < l_actual; i++) | ||
| 38 | if (i == 0 || actual[i-1] == '\n') | ||
| 39 | found += check_one(&actual[i], expected); | ||
| 40 | |||
| 41 | return found == n_expected; | ||
| 42 | } | ||
| 43 | |||
| 44 | void run(void) { | ||
| 45 | int i; | ||
| 46 | int64_t n; | ||
| 47 | long long stats[NISSY_SIZE_SOLVE_STATS]; | ||
| 48 | char sol[SOL_BUFFER_LEN], cube[NISSY_SIZE_CUBE]; | ||
| 49 | |||
| 50 | for (i = 0; s[i].scramble[0]; i++) { | ||
| 51 | printf("\n%d. %s\n", i, s[i].scramble); | ||
| 52 | |||
| 53 | /* Single solution */ | ||
| 54 | if (nissy_applymoves(NISSY_SOLVED_CUBE, s[i].scramble, cube) | ||
| 55 | == -1) { | ||
| 56 | printf("Invalid scramble\n"); | ||
| 57 | continue; | ||
| 58 | } | ||
| 59 | n = nissy_solve(cube, solver, NISSY_NISSFLAG_NORMAL, | ||
| 60 | 0, 20, 1, -1, 0, size, buf, SOL_BUFFER_LEN, sol, stats, | ||
| 61 | NULL, NULL); | ||
| 62 | if (n == 0) { | ||
| 63 | printf("Error: no solution\n"); | ||
| 64 | return; | ||
| 65 | } | ||
| 66 | if (check_one(sol, s[i].solutions)) { | ||
| 67 | printf("Single solution is correct\n"); | ||
| 68 | } else { | ||
| 69 | printf("Error!\n"); | ||
| 70 | printf("Found solution(s):\n%s", sol); | ||
| 71 | printf("Valid solution(s):\n%s", s[i].solutions); | ||
| 72 | return; | ||
| 73 | } | ||
| 74 | |||
| 75 | /* Multiple solutions */ | ||
| 76 | if (nissy_applymoves(NISSY_SOLVED_CUBE, s[i].scramble, cube) | ||
| 77 | == -1) { | ||
| 78 | printf("Invalid scramble\n"); | ||
| 79 | continue; | ||
| 80 | } | ||
| 81 | n = nissy_solve(cube, solver, NISSY_NISSFLAG_NORMAL, | ||
| 82 | 0, 20, 100, 0, 0, size, buf, SOL_BUFFER_LEN, sol, stats, | ||
| 83 | NULL, NULL); | ||
| 84 | if (check_all(sol, s[i].solutions)) { | ||
| 85 | printf("All solutions are correct\n"); | ||
| 86 | } else { | ||
| 87 | printf("Error!\n"); | ||
| 88 | printf("Found solution(s):\n%s", sol); | ||
| 89 | printf("Valid solution(s):\n%s", s[i].solutions); | ||
| 90 | return; | ||
| 91 | } | ||
| 92 | } | ||
| 93 | |||
| 94 | printf("\nAll scrambles solved correctly\n"); | ||
| 95 | } | ||
| 96 | |||
| 97 | int main(int argc, char **argv) { | ||
| 98 | char filename[255], dataid[NISSY_SIZE_DATAID]; | ||
| 99 | |||
| 100 | if (argc < 2) { | ||
| 101 | printf("Error: not enough arguments. " | ||
| 102 | "A solver must be given.\n"); | ||
| 103 | return 1; | ||
| 104 | } | ||
| 105 | |||
| 106 | solver = argv[1]; | ||
| 107 | srand(time(NULL)); | ||
| 108 | nissy_setlogger(log_stderr, NULL); | ||
| 109 | |||
| 110 | sprintf(filename, "tables/%s", solver); | ||
| 111 | if (getdata(solver, &buf, filename) != 0) | ||
| 112 | return 1; | ||
| 113 | |||
| 114 | size = nissy_solverinfo(solver, dataid); | ||
| 115 | |||
| 116 | timerun(run); | ||
| 117 | |||
| 118 | free(buf); | ||
| 119 | return 0; | ||
| 120 | } | ||
