diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2024-08-18 14:26:45 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2024-08-18 14:26:45 +0200 |
| commit | 18c9a8b8905304cf5f8fc15825769046a3144866 (patch) | |
| tree | a7807bb32b0a5d9ded7d3cedccc598f64a9b00fe /src/cube_public.h | |
| parent | f25a10e19eca294c4e6a99e4f80ce5cfd11a0e5f (diff) | |
| download | nissy-core-18c9a8b8905304cf5f8fc15825769046a3144866.tar.gz nissy-core-18c9a8b8905304cf5f8fc15825769046a3144866.zip | |
Reorganized folder structure
Diffstat (limited to 'src/cube_public.h')
| -rw-r--r-- | src/cube_public.h | 255 |
1 files changed, 0 insertions, 255 deletions
diff --git a/src/cube_public.h b/src/cube_public.h deleted file mode 100644 index e080f40..0000000 --- a/src/cube_public.h +++ /dev/null | |||
| @@ -1,255 +0,0 @@ | |||
| 1 | #include "cube.h" | ||
| 2 | |||
| 3 | _static int64_t write_result(cube_t, char [static 22]); | ||
| 4 | |||
| 5 | /* TODO: add option to get DR, maybe C-only, E-only, eo... */ | ||
| 6 | #define GETCUBE_OPTIONS(S, F) { .option = S, .fix = F } | ||
| 7 | struct { | ||
| 8 | char *option; | ||
| 9 | void (*fix)(int64_t *, int64_t *, int64_t *, int64_t *); | ||
| 10 | } getcube_options[] = { | ||
| 11 | GETCUBE_OPTIONS("fix", getcube_fix), | ||
| 12 | GETCUBE_OPTIONS(NULL, NULL) | ||
| 13 | }; | ||
| 14 | |||
| 15 | _static int64_t | ||
| 16 | write_result(cube_t cube, char result[static 22]) | ||
| 17 | { | ||
| 18 | if (!isconsistent(cube)) { | ||
| 19 | writecube("B32", zero, result); | ||
| 20 | return 2; | ||
| 21 | } | ||
| 22 | |||
| 23 | writecube("B32", cube, result); | ||
| 24 | |||
| 25 | return issolvable(cube) ? 0 : 1; | ||
| 26 | } | ||
| 27 | |||
| 28 | int64_t | ||
| 29 | nissy_compose( | ||
| 30 | const char cube[static 22], | ||
| 31 | const char permutation[static 22], | ||
| 32 | char result[static 22] | ||
| 33 | ) | ||
| 34 | { | ||
| 35 | cube_t c, p, res; | ||
| 36 | |||
| 37 | c = readcube("B32", cube); | ||
| 38 | p = readcube("B32", permutation); | ||
| 39 | res = compose(c, p); | ||
| 40 | |||
| 41 | return write_result(res, result); | ||
| 42 | } | ||
| 43 | |||
| 44 | int64_t | ||
| 45 | nissy_inverse( | ||
| 46 | const char cube[static 22], | ||
| 47 | char result[static 22] | ||
| 48 | ) | ||
| 49 | { | ||
| 50 | cube_t c, res; | ||
| 51 | |||
| 52 | c = readcube("B32", cube); | ||
| 53 | res = inverse(c); | ||
| 54 | |||
| 55 | return write_result(res, result); | ||
| 56 | } | ||
| 57 | |||
| 58 | int64_t | ||
| 59 | nissy_applymoves( | ||
| 60 | const char cube[static 22], | ||
| 61 | const char *moves, | ||
| 62 | char result[static 22] | ||
| 63 | ) | ||
| 64 | { | ||
| 65 | cube_t c, res; | ||
| 66 | |||
| 67 | c = readcube("B32", cube); | ||
| 68 | res = applymoves(c, moves); | ||
| 69 | |||
| 70 | return write_result(res, result); | ||
| 71 | } | ||
| 72 | |||
| 73 | int64_t | ||
| 74 | nissy_applytrans( | ||
| 75 | const char cube[static 22], | ||
| 76 | const char *transformation, | ||
| 77 | char result[static 22] | ||
| 78 | ) | ||
| 79 | { | ||
| 80 | cube_t c, res; | ||
| 81 | |||
| 82 | c = readcube("B32", cube); | ||
| 83 | res = applytrans(c, transformation); | ||
| 84 | |||
| 85 | return write_result(res, result); | ||
| 86 | } | ||
| 87 | |||
| 88 | int64_t | ||
| 89 | nissy_frommoves( | ||
| 90 | const char *moves, | ||
| 91 | char result[static 22] | ||
| 92 | ) | ||
| 93 | { | ||
| 94 | cube_t res; | ||
| 95 | |||
| 96 | res = applymoves(solved, moves); | ||
| 97 | |||
| 98 | return write_result(res, result); | ||
| 99 | } | ||
| 100 | |||
| 101 | int64_t | ||
| 102 | nissy_convert( | ||
| 103 | const char *format_in, | ||
| 104 | const char *format_out, | ||
| 105 | const char *cube_string, | ||
| 106 | char *result | ||
| 107 | ) | ||
| 108 | { | ||
| 109 | cube_t c; | ||
| 110 | |||
| 111 | c = readcube(format_in, cube_string); | ||
| 112 | writecube(format_out, c, result); | ||
| 113 | |||
| 114 | return isconsistent(c) ? 0 : 2; | ||
| 115 | } | ||
| 116 | |||
| 117 | int64_t | ||
| 118 | nissy_getcube( | ||
| 119 | int64_t ep, | ||
| 120 | int64_t eo, | ||
| 121 | int64_t cp, | ||
| 122 | int64_t co, | ||
| 123 | const char *options, | ||
| 124 | char result[static 22] | ||
| 125 | ) | ||
| 126 | { | ||
| 127 | int i; | ||
| 128 | cube_t c; | ||
| 129 | |||
| 130 | for (i = 0; getcube_options[i].option != NULL; i++) | ||
| 131 | if (!strcmp(options, getcube_options[i].option)) | ||
| 132 | getcube_options[i].fix(&ep, &eo, &cp, &co); | ||
| 133 | |||
| 134 | c = getcube(ep, eo, cp, co); | ||
| 135 | |||
| 136 | return write_result(c, result); | ||
| 137 | } | ||
| 138 | |||
| 139 | int64_t | ||
| 140 | nissy_datasize( | ||
| 141 | const char *solver, | ||
| 142 | const char *options | ||
| 143 | ) | ||
| 144 | { | ||
| 145 | /* gendata() handles a NULL *data as a "dryrun" request */ | ||
| 146 | return nissy_gendata(solver, options, NULL); | ||
| 147 | } | ||
| 148 | |||
| 149 | int64_t | ||
| 150 | nissy_gendata( | ||
| 151 | const char *solver, | ||
| 152 | const char *options, | ||
| 153 | void *data | ||
| 154 | ) | ||
| 155 | { | ||
| 156 | int64_t ret; | ||
| 157 | uint8_t maxdepth, h, i, j; | ||
| 158 | |||
| 159 | if (!strcmp(solver, "h48")) { | ||
| 160 | /* options are in the form "h;maxdepth" */ | ||
| 161 | for (i = 0; options[i] != ';'; i++) ; | ||
| 162 | for (j = i; options[j]; j++) ; | ||
| 163 | h = atoi(options); | ||
| 164 | if (h != 0) { | ||
| 165 | LOG("Temporarily only h=0 is supported\n"); | ||
| 166 | ret = -1; | ||
| 167 | } else { | ||
| 168 | maxdepth = atoi(&options[i+1]); | ||
| 169 | ret = gendata_h48h0k4(data, maxdepth); | ||
| 170 | } | ||
| 171 | } else if (!strcmp(solver, "h48stats")) { | ||
| 172 | ret = gendata_h48h0k4(data, 20); | ||
| 173 | } else { | ||
| 174 | LOG("gendata: implemented only for h48 solver\n"); | ||
| 175 | ret = -1; | ||
| 176 | } | ||
| 177 | |||
| 178 | return ret; | ||
| 179 | } | ||
| 180 | |||
| 181 | int64_t | ||
| 182 | nissy_solve( | ||
| 183 | const char cube[static 22], | ||
| 184 | const char *solver, | ||
| 185 | const char *options, | ||
| 186 | const char *nisstype, | ||
| 187 | int8_t minmoves, | ||
| 188 | int8_t maxmoves, | ||
| 189 | int64_t maxsolutions, | ||
| 190 | int8_t optimal, | ||
| 191 | const void *data, | ||
| 192 | char *solutions | ||
| 193 | ) | ||
| 194 | { | ||
| 195 | cube_t c; | ||
| 196 | int64_t ret; | ||
| 197 | int h; | ||
| 198 | |||
| 199 | c = readcube_B32(cube); | ||
| 200 | |||
| 201 | if (!issolvable(c)) { | ||
| 202 | LOG("solve: cube is not solvable\n"); | ||
| 203 | return -1; | ||
| 204 | } | ||
| 205 | |||
| 206 | if (minmoves < 0) { | ||
| 207 | LOG("solve: 'minmoves' is negative, setting it to 0\n"); | ||
| 208 | minmoves = 0; | ||
| 209 | } | ||
| 210 | |||
| 211 | if (maxmoves < 0) { | ||
| 212 | LOG("solve: 'maxmoves' is negative, setting it to 20\n"); | ||
| 213 | maxmoves = 20; | ||
| 214 | } | ||
| 215 | |||
| 216 | if (maxsolutions < 0) { | ||
| 217 | LOG("solve: 'maxsols' is negative, stopping\n"); | ||
| 218 | return -1; | ||
| 219 | } | ||
| 220 | |||
| 221 | if (maxsolutions == 0) { | ||
| 222 | LOG("solve: 'maxsols' is 0, returning no solution\n"); | ||
| 223 | return 0; | ||
| 224 | } | ||
| 225 | |||
| 226 | if (solutions == NULL) { | ||
| 227 | LOG("solve: return parameter 'solutions' is NULL, stopping\n"); | ||
| 228 | return -1; | ||
| 229 | } | ||
| 230 | |||
| 231 | /* TODO define and use solve_options_t */ | ||
| 232 | if (!strcmp(solver, "h48")) { | ||
| 233 | h = atoi(options); /* TODO: better parsing */ | ||
| 234 | ret = solve_h48( | ||
| 235 | c, minmoves, maxmoves, maxsolutions, | ||
| 236 | (uint8_t)h, data, solutions); | ||
| 237 | ret = -1; | ||
| 238 | } else if (!strcmp(solver, "h48stats")) { | ||
| 239 | ret = solve_h48stats(c, maxmoves, data, solutions); | ||
| 240 | } else if (!strcmp(solver, "simple")) { | ||
| 241 | ret = solve_simple( | ||
| 242 | c, minmoves, maxmoves, maxsolutions, optimal, solutions); | ||
| 243 | } else { | ||
| 244 | LOG("solve: unknown solver '%s'\n", solver); | ||
| 245 | ret = -1; | ||
| 246 | } | ||
| 247 | |||
| 248 | return ret; | ||
| 249 | } | ||
| 250 | |||
| 251 | void | ||
| 252 | nissy_setlogger(void (*log)(const char *, ...)) | ||
| 253 | { | ||
| 254 | nissy_log = log; | ||
| 255 | } | ||
