diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2025-07-31 08:38:37 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2025-07-31 08:38:37 +0200 |
| commit | e2b154c40acaac4e7a7b3e379ada0404519c3750 (patch) | |
| tree | 2ddca6533b03180eee1cd199d1c5a56586211a65 /tools/400_solvetest | |
| parent | 36c317ebd1cf1dba8a8cbec494f4d3971e6cefd3 (diff) | |
| download | nissy-core-e2b154c40acaac4e7a7b3e379ada0404519c3750.tar.gz nissy-core-e2b154c40acaac4e7a7b3e379ada0404519c3750.zip | |
Added solvetest for EO (broken for now)
Diffstat (limited to 'tools/400_solvetest')
| -rw-r--r-- | tools/400_solvetest/scrambles.h | 62 | ||||
| -rw-r--r-- | tools/400_solvetest/solve_test.c | 120 |
2 files changed, 0 insertions, 182 deletions
diff --git a/tools/400_solvetest/scrambles.h b/tools/400_solvetest/scrambles.h deleted file mode 100644 index 59037be..0000000 --- a/tools/400_solvetest/scrambles.h +++ /dev/null | |||
| @@ -1,62 +0,0 @@ | |||
| 1 | struct { | ||
| 2 | char *scramble; | ||
| 3 | char *solutions; | ||
| 4 | } s[] = { | ||
| 5 | [0] = { | ||
| 6 | .scramble = "R' D R U R' D' R U'", | ||
| 7 | .solutions = | ||
| 8 | "U R' D R U' R' D' R\n" | ||
| 9 | "B' D2 B U' B' D2 B U\n" | ||
| 10 | }, | ||
| 11 | [1] = { | ||
| 12 | .scramble = "R' L U2 R L' B2", | ||
| 13 | .solutions = | ||
| 14 | "B2 R' L U2 R L'\n" | ||
| 15 | "R L' B2 R' L U2\n" | ||
| 16 | "R B2 R' L U2 L'\n" | ||
| 17 | "L' B2 R' L U2 R\n" | ||
| 18 | }, | ||
| 19 | [2] = { | ||
| 20 | .scramble = "R2 U2 R2 U2 R2 U2", | ||
| 21 | .solutions = | ||
| 22 | "U2 R2 U2 R2 U2 R2\n" | ||
| 23 | "D2 L2 U2 L2 D2 R2\n" | ||
| 24 | "U2 L2 D2 R2 D2 L2\n" | ||
| 25 | "D2 R2 D2 L2 U2 L2\n" | ||
| 26 | "R2 U2 R2 U2 R2 U2\n" | ||
| 27 | "L2 D2 R2 D2 L2 U2\n" | ||
| 28 | "R2 D2 L2 U2 L2 D2\n" | ||
| 29 | "L2 U2 L2 D2 R2 D2\n" | ||
| 30 | }, | ||
| 31 | [3] = { | ||
| 32 | .scramble = "R U2 R' U' R U2 L' U R' U' L", /* J-perm */ | ||
| 33 | .solutions = | ||
| 34 | "R2 D' R' D R' B2 L U' L' B2\n" | ||
| 35 | "B2 L U L' B2 R D' R D R2\n" | ||
| 36 | }, | ||
| 37 | [4] = { | ||
| 38 | .scramble = "R' U' F D2 L2 F R2 U2 R2 B D2 L B2" | ||
| 39 | "D' B2 L' R' B D2 B U2 L U2 R' U' F", /* FMC2019 A1 */ | ||
| 40 | .solutions = | ||
| 41 | "D2 F' U2 D2 F' L2 D R2 D F B2 R' L2 F' U' D\n" | ||
| 42 | }, | ||
| 43 | [5] = { | ||
| 44 | .scramble = "L B' D2 R2 L2 B' U2 D2 R L' U F2", /* Taken from 6 */ | ||
| 45 | .solutions = | ||
| 46 | "B2 R2 L2 D F2 B2 R' L F' U2 B L'\n" | ||
| 47 | "F2 U' R' L U2 D2 B R2 L2 D2 B L'\n" | ||
| 48 | }, | ||
| 49 | [6] = { | ||
| 50 | .scramble = "R L' B R L' D R L' F R L' U" | ||
| 51 | "R' L F R L' D R L' B R L' U", /* Random thing */ | ||
| 52 | .solutions = | ||
| 53 | "U' R L' B' D2 F R' L F2 B2 U' F2 R2 L2 U2\n" | ||
| 54 | "U' R L' B' R2 L2 U2 B' U2 D2 R' L D B2 U2\n" | ||
| 55 | "D2 R' L F R' B' R U B U L F' U' F' D\n" | ||
| 56 | "D' R' L B' U2 F R L' F2 B2 D' R2 L2 B2 D2\n" | ||
| 57 | "D' R' L B' D2 R2 L2 B' U2 D2 R L' U F2 D2\n" | ||
| 58 | }, | ||
| 59 | { | ||
| 60 | .scramble = "", /* End-of-list signal */ | ||
| 61 | } | ||
| 62 | }; | ||
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 | } | ||
