diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2024-06-23 12:09:37 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2024-06-23 12:09:37 +0200 |
| commit | 05bdcfef13ef2bdd05df6af13a74ec3cd7fcd22f (patch) | |
| tree | 1d5512f3e31dd86414d386713a82336db5edf0f5 | |
| parent | 71c0188306377940ae172dceb58f2bd5f4fcdb4f (diff) | |
| download | nissy-core-05bdcfef13ef2bdd05df6af13a74ec3cd7fcd22f.tar.gz nissy-core-05bdcfef13ef2bdd05df6af13a74ec3cd7fcd22f.zip | |
Cleanup
| -rw-r--r-- | TODO.txt | 22 | ||||
| -rw-r--r-- | src/cube.h | 14 | ||||
| -rw-r--r-- | src/cube_public.h | 91 | ||||
| -rw-r--r-- | src/solve_generic.h | 98 | ||||
| -rw-r--r-- | test/090_solve_simple/01_U_U3.in | 8 | ||||
| -rw-r--r-- | test/090_solve_simple/01_U_U3.out | 1 | ||||
| -rw-r--r-- | test/090_solve_simple/02_MUMU_alloptimal.in | 8 | ||||
| -rw-r--r-- | test/090_solve_simple/02_MUMU_alloptimal.out | 4 | ||||
| -rw-r--r-- | test/090_solve_simple/solve_simple_tests.c | 48 |
9 files changed, 73 insertions, 221 deletions
| @@ -1,26 +1,22 @@ | |||
| 1 | Shell and nissy_run | ||
| 2 | x done shell.c, but it is ugly (as expected) | ||
| 3 | - move stuff from solve_generic to cube_public | ||
| 4 | - make shell a bit nicer? | ||
| 5 | |||
| 6 | Fixes | ||
| 7 | - tables/tables.c: fix, use new nissy_gendata and nissy_datasize | ||
| 8 | |||
| 9 | Solver | 1 | Solver |
| 2 | - write a solver (how many tricks? some, but not all are needed) | ||
| 10 | - benchmark for solve | 3 | - benchmark for solve |
| 11 | table generation, where to keep tables? in benchmark folder or in tables/? | 4 | table generation, where to keep tables? in benchmark folder or in tables/? |
| 12 | - write a solver (how many tricks? some, but not all are needed) | 5 | - remove solve_simple and maybe the whole solve_generic |
| 13 | 6 | ||
| 14 | More utilities for tables (in cube.h) | 7 | Cleanup cube_public and interface |
| 15 | - cleanup solve and gendata in cube.h and cube_public.h | 8 | - remove options, use only solver name |
| 16 | - check hash of generated data | 9 | cleanup also benchmark |
| 10 | - write a generic parse + dispatch to solver | ||
| 11 | (maybe use helper function from solve_h48 for parsing hXkY) | ||
| 17 | 12 | ||
| 18 | Goal: find out which k value is best | 13 | Goal: find out which k value is best |
| 19 | - temporarily call current table and solver "k4" instead of h48 | 14 | - temporarily call current table and solver "k4" instead of h48 |
| 20 | - write table generation and solver for k2 and k1 | 15 | - write table generation and solver for k2 and k1 |
| 21 | - benchmark for different sizes! | 16 | - benchmark for different sizes! |
| 22 | 17 | ||
| 23 | Read / write: replace by convertcube only? | 18 | Improvements |
| 19 | - check hash of generated data | ||
| 24 | 20 | ||
| 25 | ## H48 optimal solver (some has already been implemented) | 21 | ## H48 optimal solver (some has already been implemented) |
| 26 | 22 | ||
| @@ -34,19 +34,7 @@ int64_t nissy_frommoves( | |||
| 34 | char result[static 22] | 34 | char result[static 22] |
| 35 | ); | 35 | ); |
| 36 | 36 | ||
| 37 | int64_t nissy_readcube( | 37 | int64_t nissy_convert( |
| 38 | const char *format, | ||
| 39 | const char *cube_string, | ||
| 40 | char result[static 22] | ||
| 41 | ); | ||
| 42 | |||
| 43 | int64_t nissy_writecube( | ||
| 44 | const char *format, | ||
| 45 | const char cube[static 22], | ||
| 46 | char *result | ||
| 47 | ); | ||
| 48 | |||
| 49 | int64_t nissy_convertcube( | ||
| 50 | const char *format_in, | 38 | const char *format_in, |
| 51 | const char *format_out, | 39 | const char *format_out, |
| 52 | const char *cube_string, | 40 | const char *cube_string, |
diff --git a/src/cube_public.h b/src/cube_public.h index 69809d7..ea1d28d 100644 --- a/src/cube_public.h +++ b/src/cube_public.h | |||
| @@ -89,20 +89,6 @@ nissy_frommoves( | |||
| 89 | } | 89 | } |
| 90 | 90 | ||
| 91 | int64_t | 91 | int64_t |
| 92 | nissy_readcube( | ||
| 93 | const char *format, | ||
| 94 | const char *cube_string, | ||
| 95 | char result[static 22] | ||
| 96 | ) | ||
| 97 | { | ||
| 98 | cube_t res; | ||
| 99 | |||
| 100 | res = readcube(format, cube_string); | ||
| 101 | |||
| 102 | return write_result(res, result); | ||
| 103 | } | ||
| 104 | |||
| 105 | int64_t | ||
| 106 | nissy_convertcube( | 92 | nissy_convertcube( |
| 107 | const char *format_in, | 93 | const char *format_in, |
| 108 | const char *format_out, | 94 | const char *format_out, |
| @@ -119,16 +105,6 @@ nissy_convertcube( | |||
| 119 | } | 105 | } |
| 120 | 106 | ||
| 121 | int64_t | 107 | int64_t |
| 122 | nissy_writecube( | ||
| 123 | const char *format, | ||
| 124 | const char cube[static 22], | ||
| 125 | char *result | ||
| 126 | ) | ||
| 127 | { | ||
| 128 | return nissy_convertcube("B32", format, cube, result); | ||
| 129 | } | ||
| 130 | |||
| 131 | int64_t | ||
| 132 | nissy_datasize( | 108 | nissy_datasize( |
| 133 | const char *solver, | 109 | const char *solver, |
| 134 | const char *options | 110 | const char *options |
| @@ -145,8 +121,22 @@ nissy_gendata( | |||
| 145 | void *data | 121 | void *data |
| 146 | ) | 122 | ) |
| 147 | { | 123 | { |
| 148 | /* TODO: move gendata here? */ | 124 | int64_t ret; |
| 149 | return gendata(solver, options, data); | 125 | uint8_t maxdepth, h, i, j; |
| 126 | |||
| 127 | if (!strcmp(solver, "H48")) { | ||
| 128 | /* options are in the form "h;maxdepth" */ | ||
| 129 | for (i = 0; options[i] != ';'; i++) ; | ||
| 130 | for (j = i; options[j]; j++) ; | ||
| 131 | h = atoi(options); | ||
| 132 | maxdepth = atoi(&options[i+1]); | ||
| 133 | ret = gendata_h48(data, h, maxdepth); | ||
| 134 | } else { | ||
| 135 | LOG("gendata: implemented only for H48 solver\n"); | ||
| 136 | ret = -1; | ||
| 137 | } | ||
| 138 | |||
| 139 | return ret; | ||
| 150 | } | 140 | } |
| 151 | 141 | ||
| 152 | int64_t | 142 | int64_t |
| @@ -163,8 +153,53 @@ nissy_solve( | |||
| 163 | char *solutions | 153 | char *solutions |
| 164 | ) | 154 | ) |
| 165 | { | 155 | { |
| 166 | /* TODO: move solve_generic here? */ | 156 | cube_t c; |
| 167 | return -1; | 157 | int64_t ret; |
| 158 | |||
| 159 | c = readcube_B32(cube); | ||
| 160 | |||
| 161 | if (!issolvable(c)) { | ||
| 162 | LOG("solve: cube is not solvable\n"); | ||
| 163 | return -1; | ||
| 164 | } | ||
| 165 | |||
| 166 | if (minmoves < 0) { | ||
| 167 | LOG("solve: 'minmoves' is negative, setting it to 0\n"); | ||
| 168 | minmoves = 0; | ||
| 169 | } | ||
| 170 | |||
| 171 | if (maxmoves < 0) { | ||
| 172 | LOG("solve: 'maxmoves' is negative, setting it to 20\n"); | ||
| 173 | maxmoves = 20; | ||
| 174 | } | ||
| 175 | |||
| 176 | if (maxsolutions < 0) { | ||
| 177 | LOG("solve: 'maxsols' is negative, stopping\n"); | ||
| 178 | return -1; | ||
| 179 | } | ||
| 180 | |||
| 181 | if (maxsolutions == 0) { | ||
| 182 | LOG("solve: 'maxsols' is 0, returning no solution\n"); | ||
| 183 | return 0; | ||
| 184 | } | ||
| 185 | |||
| 186 | if (solutions == NULL) { | ||
| 187 | LOG("solve: return parameter 'solutions' is NULL, stopping\n"); | ||
| 188 | return -1; | ||
| 189 | } | ||
| 190 | |||
| 191 | if (!strcmp(solver, "h48")) { | ||
| 192 | LOG("h48 solver not implemented yet\n"); | ||
| 193 | ret = -1; | ||
| 194 | } else if (!strcmp(solver, "simple")) { | ||
| 195 | ret = solve_simple( | ||
| 196 | c, minmoves, maxmoves, maxsolutions, optimal, solutions); | ||
| 197 | } else { | ||
| 198 | LOG("solve: unknown solver '%s'\n", solver); | ||
| 199 | ret = -1; | ||
| 200 | } | ||
| 201 | |||
| 202 | return ret; | ||
| 168 | } | 203 | } |
| 169 | 204 | ||
| 170 | void | 205 | void |
diff --git a/src/solve_generic.h b/src/solve_generic.h index 6a1dcf3..d1d1469 100644 --- a/src/solve_generic.h +++ b/src/solve_generic.h | |||
| @@ -16,47 +16,6 @@ _static int64_t solve_generic(cube_t, const char *, int8_t, int8_t, int64_t, | |||
| 16 | _static uint8_t estimate_simple(cube_t); | 16 | _static uint8_t estimate_simple(cube_t); |
| 17 | _static int64_t solve_simple(cube_t, int8_t, int8_t, int64_t, int8_t, char *); | 17 | _static int64_t solve_simple(cube_t, int8_t, int8_t, int64_t, int8_t, char *); |
| 18 | 18 | ||
| 19 | int64_t | ||
| 20 | solve( | ||
| 21 | cube_t cube, | ||
| 22 | const char *solver, | ||
| 23 | const char *options, | ||
| 24 | const char *nisstype, | ||
| 25 | int8_t minmoves, | ||
| 26 | int8_t maxmoves, | ||
| 27 | int64_t maxsols, | ||
| 28 | int8_t optimal, | ||
| 29 | const void *data, | ||
| 30 | char *solutions | ||
| 31 | ) | ||
| 32 | { | ||
| 33 | DBG_WARN(!strcmp(options, ""), | ||
| 34 | "solve: 'options' not implemented yet, ignoring\n"); | ||
| 35 | |||
| 36 | DBG_WARN(!strcmp(nisstype, ""), | ||
| 37 | "solve: NISS not implemented yet, ignoring 'nisstype'\n"); | ||
| 38 | |||
| 39 | DBG_WARN(data == NULL, | ||
| 40 | "solve: 'data' not implemented yet, ignoring\n"); | ||
| 41 | |||
| 42 | if (!strcmp(solver, "optimal") || !strcmp(solver, "simple")) { | ||
| 43 | return solve_simple( | ||
| 44 | cube, | ||
| 45 | minmoves, | ||
| 46 | maxmoves, | ||
| 47 | maxsols, | ||
| 48 | optimal, | ||
| 49 | solutions | ||
| 50 | ); | ||
| 51 | } else { | ||
| 52 | LOG("solve: unknown solver '%s'\n", solver); | ||
| 53 | return -1; | ||
| 54 | } | ||
| 55 | |||
| 56 | LOG("solve: error\n"); | ||
| 57 | return -1; | ||
| 58 | } | ||
| 59 | |||
| 60 | _static void | 19 | _static void |
| 61 | solve_generic_appendsolution(dfsarg_generic_t *arg) | 20 | solve_generic_appendsolution(dfsarg_generic_t *arg) |
| 62 | { | 21 | { |
| @@ -125,11 +84,6 @@ solve_generic( | |||
| 125 | dfsarg_generic_t arg; | 84 | dfsarg_generic_t arg; |
| 126 | int64_t ret, tmp, first; | 85 | int64_t ret, tmp, first; |
| 127 | 86 | ||
| 128 | if (!issolvable(cube)) { | ||
| 129 | LOG("solve: cube is not solvable\n"); | ||
| 130 | return -1; | ||
| 131 | } | ||
| 132 | |||
| 133 | if (issolved(cube)) { | 87 | if (issolved(cube)) { |
| 134 | LOG("solve: cube is already solved\n"); | 88 | LOG("solve: cube is already solved\n"); |
| 135 | sols[0] = '\n'; | 89 | sols[0] = '\n'; |
| @@ -137,34 +91,6 @@ solve_generic( | |||
| 137 | return 1; | 91 | return 1; |
| 138 | } | 92 | } |
| 139 | 93 | ||
| 140 | DBG_WARN(!strcmp(nisstype, ""), | ||
| 141 | "solve: NISS not implemented yet, 'nisstype' ignored\n"); | ||
| 142 | |||
| 143 | if (minmoves < 0) { | ||
| 144 | LOG("solve: 'minmoves' is negative, setting to 0\n"); | ||
| 145 | minmoves = 0; | ||
| 146 | } | ||
| 147 | |||
| 148 | if (maxmoves < 0) { | ||
| 149 | LOG("solve: invalid 'maxmoves', setting to 20\n"); | ||
| 150 | maxmoves = 20; | ||
| 151 | } | ||
| 152 | |||
| 153 | if (maxsols < 0) { | ||
| 154 | LOG("solve: 'maxsols' is negative\n"); | ||
| 155 | return -1; | ||
| 156 | } | ||
| 157 | |||
| 158 | if (maxsols == 0) { | ||
| 159 | LOG("solve: 'maxsols' is 0\n"); | ||
| 160 | return 0; | ||
| 161 | } | ||
| 162 | |||
| 163 | if (sols == NULL) { | ||
| 164 | LOG("solve: return parameter 'sols' is NULL\n"); | ||
| 165 | return -1; | ||
| 166 | } | ||
| 167 | |||
| 168 | if (estimate == NULL) { | 94 | if (estimate == NULL) { |
| 169 | LOG("solve: 'estimate' is NULL\n"); | 95 | LOG("solve: 'estimate' is NULL\n"); |
| 170 | return -1; | 96 | return -1; |
| @@ -230,27 +156,3 @@ solve_simple( | |||
| 230 | &estimate_simple | 156 | &estimate_simple |
| 231 | ); | 157 | ); |
| 232 | } | 158 | } |
| 233 | |||
| 234 | int64_t | ||
| 235 | gendata(const char *solver, const char *options, void *data) | ||
| 236 | { | ||
| 237 | int64_t ret; | ||
| 238 | uint8_t maxdepth, h, i, j; | ||
| 239 | |||
| 240 | if (!strcmp(solver, "H48")) { | ||
| 241 | /* | ||
| 242 | TODO: write a generic parser for options | ||
| 243 | for now it accepts "h;maxdepth" | ||
| 244 | */ | ||
| 245 | for (i = 0; options[i] != ';'; i++) ; | ||
| 246 | for (j = i; options[j]; j++) ; | ||
| 247 | h = atoi(options); | ||
| 248 | maxdepth = atoi(&options[i+1]); | ||
| 249 | ret = gendata_h48(data, h, maxdepth); | ||
| 250 | } else { | ||
| 251 | LOG("gendata: implemented only for H48 solver\n"); | ||
| 252 | ret = -1; | ||
| 253 | } | ||
| 254 | |||
| 255 | return ret; | ||
| 256 | } | ||
diff --git a/test/090_solve_simple/01_U_U3.in b/test/090_solve_simple/01_U_U3.in deleted file mode 100644 index c0f7930..0000000 --- a/test/090_solve_simple/01_U_U3.in +++ /dev/null | |||
| @@ -1,8 +0,0 @@ | |||
| 1 | UR0 UL0 DB0 DF0 UB0 UF0 DL0 DR0 FR0 FL0 BL0 BR0 UBR0 UFL0 DFL0 DBR0 UFR0 UBL0 DFR0 DBL0 | ||
| 2 | simple | ||
| 3 | |||
| 4 | normal | ||
| 5 | 0 | ||
| 6 | 3 | ||
| 7 | 3 | ||
| 8 | -1 | ||
diff --git a/test/090_solve_simple/01_U_U3.out b/test/090_solve_simple/01_U_U3.out deleted file mode 100644 index ca934b4..0000000 --- a/test/090_solve_simple/01_U_U3.out +++ /dev/null | |||
| @@ -1 +0,0 @@ | |||
| 1 | U' | ||
diff --git a/test/090_solve_simple/02_MUMU_alloptimal.in b/test/090_solve_simple/02_MUMU_alloptimal.in deleted file mode 100644 index f97c95f..0000000 --- a/test/090_solve_simple/02_MUMU_alloptimal.in +++ /dev/null | |||
| @@ -1,8 +0,0 @@ | |||
| 1 | UB0 DF0 DB0 UF0 UR0 UL0 DL0 DR0 FR0 FL0 BL0 BR0 UFR0 UBL0 DFL0 DBR0 UFL0 UBR0 DFR0 DBL0 | ||
| 2 | simple | ||
| 3 | |||
| 4 | normal | ||
| 5 | 0 | ||
| 6 | -1 | ||
| 7 | 10 | ||
| 8 | 0 | ||
diff --git a/test/090_solve_simple/02_MUMU_alloptimal.out b/test/090_solve_simple/02_MUMU_alloptimal.out deleted file mode 100644 index 06cd521..0000000 --- a/test/090_solve_simple/02_MUMU_alloptimal.out +++ /dev/null | |||
| @@ -1,4 +0,0 @@ | |||
| 1 | U2 R' L F2 R L' | ||
| 2 | R U2 R' L F2 L' | ||
| 3 | R L' U2 R' L F2 | ||
| 4 | L' U2 R' L F2 R | ||
diff --git a/test/090_solve_simple/solve_simple_tests.c b/test/090_solve_simple/solve_simple_tests.c deleted file mode 100644 index f5e00e2..0000000 --- a/test/090_solve_simple/solve_simple_tests.c +++ /dev/null | |||
| @@ -1,48 +0,0 @@ | |||
| 1 | #include "../test.h" | ||
| 2 | |||
| 3 | int64_t solve(cube_t, char *, char *, char *, int8_t, int8_t, int64_t, int8_t, | ||
| 4 | void *, char *); | ||
| 5 | |||
| 6 | void run(void) { | ||
| 7 | char cubestr[STRLENMAX], solverstr[STRLENMAX], optionsstr[STRLENMAX]; | ||
| 8 | char nisstypestr[STRLENMAX], minmovesstr[STRLENMAX]; | ||
| 9 | char maxmovesstr[STRLENMAX], maxsolsstr[STRLENMAX]; | ||
| 10 | char optimalstr[STRLENMAX], solutionsstr[STRLENMAX]; | ||
| 11 | cube_t cube; | ||
| 12 | int64_t maxsols; | ||
| 13 | int8_t minmoves, maxmoves, optimal; | ||
| 14 | |||
| 15 | fgets(cubestr, STRLENMAX, stdin); | ||
| 16 | fgets(solverstr, STRLENMAX, stdin); | ||
| 17 | fgets(optionsstr, STRLENMAX, stdin); | ||
| 18 | fgets(nisstypestr, STRLENMAX, stdin); | ||
| 19 | fgets(minmovesstr, STRLENMAX, stdin); | ||
| 20 | fgets(maxmovesstr, STRLENMAX, stdin); | ||
| 21 | fgets(maxsolsstr, STRLENMAX, stdin); | ||
| 22 | fgets(optimalstr, STRLENMAX, stdin); | ||
| 23 | |||
| 24 | solverstr[strcspn(solverstr, "\n")] = 0; | ||
| 25 | optionsstr[strcspn(optionsstr, "\n")] = 0; | ||
| 26 | nisstypestr[strcspn(nisstypestr, "\n")] = 0; | ||
| 27 | |||
| 28 | cube = readcube("H48", cubestr); | ||
| 29 | minmoves = atoi(minmovesstr); | ||
| 30 | maxmoves = atoi(maxmovesstr); | ||
| 31 | maxsols = atoi(maxsolsstr); | ||
| 32 | optimal = atoi(optimalstr); | ||
| 33 | |||
| 34 | solve( | ||
| 35 | cube, | ||
| 36 | solverstr, | ||
| 37 | optionsstr, | ||
| 38 | nisstypestr, | ||
| 39 | minmoves, | ||
| 40 | maxmoves, | ||
| 41 | maxsols, | ||
| 42 | optimal, | ||
| 43 | NULL, | ||
| 44 | solutionsstr | ||
| 45 | ); | ||
| 46 | |||
| 47 | printf("%s", solutionsstr); | ||
| 48 | } | ||
