diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2025-04-22 14:17:03 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2025-04-22 14:17:03 +0200 |
| commit | ac652bb6fb45099008e862e3ced650299dc3ebb7 (patch) | |
| tree | 12fb1c902c271fbeac41c4ee416cf1cd76b16fd7 /src/nissy.c | |
| parent | 71e104d84b3538e15f27df79b151e6b49cbad1eb (diff) | |
| parent | e391c4624055138f075c0e5772ccaf8ede094b5a (diff) | |
| download | nissy-core-ac652bb6fb45099008e862e3ced650299dc3ebb7.tar.gz nissy-core-ac652bb6fb45099008e862e3ced650299dc3ebb7.zip | |
Merge branch 'master' into extend_moves
Diffstat (limited to 'src/nissy.c')
| -rw-r--r-- | src/nissy.c | 92 |
1 files changed, 24 insertions, 68 deletions
diff --git a/src/nissy.c b/src/nissy.c index dfa1a90..8aa0334 100644 --- a/src/nissy.c +++ b/src/nissy.c | |||
| @@ -17,7 +17,7 @@ long long parse_h48_solver( | |||
| 17 | STATIC bool checkdata(const unsigned char *, const tableinfo_t [static 1]); | 17 | STATIC bool checkdata(const unsigned char *, const tableinfo_t [static 1]); |
| 18 | STATIC bool distribution_equal(const uint64_t [static INFO_DISTRIBUTION_LEN], | 18 | STATIC bool distribution_equal(const uint64_t [static INFO_DISTRIBUTION_LEN], |
| 19 | const uint64_t [static INFO_DISTRIBUTION_LEN], uint8_t); | 19 | const uint64_t [static INFO_DISTRIBUTION_LEN], uint8_t); |
| 20 | STATIC long long write_result(cube_t, char [static NISSY_SIZE_B32]); | 20 | STATIC long long write_result(cube_t, char [static NISSY_SIZE_CUBE]); |
| 21 | STATIC size_t my_strnlen(const char *, size_t); | 21 | STATIC size_t my_strnlen(const char *, size_t); |
| 22 | STATIC long long nissy_dataid(const char *, char [static NISSY_SIZE_DATAID]); | 22 | STATIC long long nissy_dataid(const char *, char [static NISSY_SIZE_DATAID]); |
| 23 | STATIC long long nissy_gendata_unsafe( | 23 | STATIC long long nissy_gendata_unsafe( |
| @@ -117,9 +117,9 @@ distribution_equal( | |||
| 117 | } | 117 | } |
| 118 | 118 | ||
| 119 | STATIC long long | 119 | STATIC long long |
| 120 | write_result(cube_t cube, char result[static NISSY_SIZE_B32]) | 120 | write_result(cube_t cube, char result[static NISSY_SIZE_CUBE]) |
| 121 | { | 121 | { |
| 122 | writecube("B32", cube, NISSY_SIZE_B32, result); | 122 | writecube(cube, NISSY_SIZE_CUBE, result); |
| 123 | 123 | ||
| 124 | if (!issolvable(cube)) { | 124 | if (!issolvable(cube)) { |
| 125 | LOG("Warning: resulting cube is not solvable\n"); | 125 | LOG("Warning: resulting cube is not solvable\n"); |
| @@ -143,15 +143,15 @@ my_strnlen(const char *str, size_t maxlen) | |||
| 143 | 143 | ||
| 144 | long long | 144 | long long |
| 145 | nissy_compose( | 145 | nissy_compose( |
| 146 | const char cube[static NISSY_SIZE_B32], | 146 | const char cube[static NISSY_SIZE_CUBE], |
| 147 | const char permutation[static NISSY_SIZE_B32], | 147 | const char permutation[static NISSY_SIZE_CUBE], |
| 148 | char result[static NISSY_SIZE_B32] | 148 | char result[static NISSY_SIZE_CUBE] |
| 149 | ) | 149 | ) |
| 150 | { | 150 | { |
| 151 | cube_t c, p, res; | 151 | cube_t c, p, res; |
| 152 | long long err; | 152 | long long err; |
| 153 | 153 | ||
| 154 | c = readcube("B32", cube); | 154 | c = readcube(cube); |
| 155 | 155 | ||
| 156 | if (!isconsistent(c)) { | 156 | if (!isconsistent(c)) { |
| 157 | LOG("[compose] Error: the given cube is invalid\n"); | 157 | LOG("[compose] Error: the given cube is invalid\n"); |
| @@ -159,7 +159,7 @@ nissy_compose( | |||
| 159 | goto nissy_compose_error; | 159 | goto nissy_compose_error; |
| 160 | } | 160 | } |
| 161 | 161 | ||
| 162 | p = readcube("B32", permutation); | 162 | p = readcube(permutation); |
| 163 | 163 | ||
| 164 | if (!isconsistent(p)) { | 164 | if (!isconsistent(p)) { |
| 165 | LOG("[compose] Error: given permutation is invalid\n"); | 165 | LOG("[compose] Error: given permutation is invalid\n"); |
| @@ -178,20 +178,20 @@ nissy_compose( | |||
| 178 | return write_result(res, result); | 178 | return write_result(res, result); |
| 179 | 179 | ||
| 180 | nissy_compose_error: | 180 | nissy_compose_error: |
| 181 | writecube("B32", ZERO_CUBE, NISSY_SIZE_B32, result); | 181 | writecube(ZERO_CUBE, NISSY_SIZE_CUBE, result); |
| 182 | return err; | 182 | return err; |
| 183 | } | 183 | } |
| 184 | 184 | ||
| 185 | long long | 185 | long long |
| 186 | nissy_inverse( | 186 | nissy_inverse( |
| 187 | const char cube[static NISSY_SIZE_B32], | 187 | const char cube[static NISSY_SIZE_CUBE], |
| 188 | char result[static NISSY_SIZE_B32] | 188 | char result[static NISSY_SIZE_CUBE] |
| 189 | ) | 189 | ) |
| 190 | { | 190 | { |
| 191 | cube_t c, res; | 191 | cube_t c, res; |
| 192 | long long err; | 192 | long long err; |
| 193 | 193 | ||
| 194 | c = readcube("B32", cube); | 194 | c = readcube(cube); |
| 195 | 195 | ||
| 196 | if (iserror(c)) { | 196 | if (iserror(c)) { |
| 197 | LOG("[inverse] Error: the given cube is invalid\n"); | 197 | LOG("[inverse] Error: the given cube is invalid\n"); |
| @@ -210,15 +210,15 @@ nissy_inverse( | |||
| 210 | return write_result(res, result); | 210 | return write_result(res, result); |
| 211 | 211 | ||
| 212 | nissy_inverse_error: | 212 | nissy_inverse_error: |
| 213 | writecube("B32", ZERO_CUBE, NISSY_SIZE_B32, result); | 213 | writecube(ZERO_CUBE, NISSY_SIZE_CUBE, result); |
| 214 | return err; | 214 | return err; |
| 215 | } | 215 | } |
| 216 | 216 | ||
| 217 | long long | 217 | long long |
| 218 | nissy_applymoves( | 218 | nissy_applymoves( |
| 219 | const char cube[static NISSY_SIZE_B32], | 219 | const char cube[static NISSY_SIZE_CUBE], |
| 220 | const char *moves, | 220 | const char *moves, |
| 221 | char result[static NISSY_SIZE_B32] | 221 | char result[static NISSY_SIZE_CUBE] |
| 222 | ) | 222 | ) |
| 223 | { | 223 | { |
| 224 | cube_t c, res; | 224 | cube_t c, res; |
| @@ -230,7 +230,7 @@ nissy_applymoves( | |||
| 230 | goto nissy_applymoves_error; | 230 | goto nissy_applymoves_error; |
| 231 | } | 231 | } |
| 232 | 232 | ||
| 233 | c = readcube("B32", cube); | 233 | c = readcube(cube); |
| 234 | 234 | ||
| 235 | if (!isconsistent(c)) { | 235 | if (!isconsistent(c)) { |
| 236 | LOG("[applymoves] Error: given cube is invalid\n"); | 236 | LOG("[applymoves] Error: given cube is invalid\n"); |
| @@ -249,21 +249,21 @@ nissy_applymoves( | |||
| 249 | return write_result(res, result); | 249 | return write_result(res, result); |
| 250 | 250 | ||
| 251 | nissy_applymoves_error: | 251 | nissy_applymoves_error: |
| 252 | writecube("B32", ZERO_CUBE, NISSY_SIZE_B32, result); | 252 | writecube(ZERO_CUBE, NISSY_SIZE_CUBE, result); |
| 253 | return err; | 253 | return err; |
| 254 | } | 254 | } |
| 255 | 255 | ||
| 256 | long long | 256 | long long |
| 257 | nissy_applytrans( | 257 | nissy_applytrans( |
| 258 | const char cube[static NISSY_SIZE_B32], | 258 | const char cube[static NISSY_SIZE_CUBE], |
| 259 | const char transformation[static NISSY_SIZE_TRANSFORMATION], | 259 | const char transformation[static NISSY_SIZE_TRANSFORMATION], |
| 260 | char result[static NISSY_SIZE_B32] | 260 | char result[static NISSY_SIZE_CUBE] |
| 261 | ) | 261 | ) |
| 262 | { | 262 | { |
| 263 | cube_t c, res; | 263 | cube_t c, res; |
| 264 | long long err; | 264 | long long err; |
| 265 | 265 | ||
| 266 | c = readcube("B32", cube); | 266 | c = readcube(cube); |
| 267 | 267 | ||
| 268 | if (!isconsistent(c)) { | 268 | if (!isconsistent(c)) { |
| 269 | LOG("[applytrans] Error: given cube is invalid\n"); | 269 | LOG("[applytrans] Error: given cube is invalid\n"); |
| @@ -282,51 +282,7 @@ nissy_applytrans( | |||
| 282 | return write_result(res, result); | 282 | return write_result(res, result); |
| 283 | 283 | ||
| 284 | nissy_applytrans_error: | 284 | nissy_applytrans_error: |
| 285 | writecube("B32", ZERO_CUBE, NISSY_SIZE_B32, result); | 285 | writecube(ZERO_CUBE, NISSY_SIZE_CUBE, result); |
| 286 | return err; | ||
| 287 | } | ||
| 288 | |||
| 289 | long long | ||
| 290 | nissy_convert( | ||
| 291 | const char *format_in, | ||
| 292 | const char *format_out, | ||
| 293 | const char *cube_string, | ||
| 294 | unsigned result_size, | ||
| 295 | char result[result_size] | ||
| 296 | ) | ||
| 297 | { | ||
| 298 | cube_t c; | ||
| 299 | long long err; | ||
| 300 | |||
| 301 | if (format_in == NULL) { | ||
| 302 | LOG("[convert] Error: 'format_in' argument is NULL\n"); | ||
| 303 | err = NISSY_ERROR_NULL_POINTER; | ||
| 304 | goto nissy_convert_error; | ||
| 305 | } | ||
| 306 | |||
| 307 | if (format_out == NULL) { | ||
| 308 | LOG("[convert] Error: 'format_out' argument is NULL\n"); | ||
| 309 | err = NISSY_ERROR_NULL_POINTER; | ||
| 310 | goto nissy_convert_error; | ||
| 311 | } | ||
| 312 | |||
| 313 | if (cube_string == NULL) { | ||
| 314 | LOG("[convert] Error: 'cube_string' argument is NULL\n"); | ||
| 315 | err = NISSY_ERROR_NULL_POINTER; | ||
| 316 | goto nissy_convert_error; | ||
| 317 | } | ||
| 318 | |||
| 319 | c = readcube(format_in, cube_string); | ||
| 320 | |||
| 321 | if (!isconsistent(c)) { | ||
| 322 | err = NISSY_ERROR_INVALID_CUBE; | ||
| 323 | goto nissy_convert_error; | ||
| 324 | } | ||
| 325 | |||
| 326 | return writecube(format_out, c, result_size, result); | ||
| 327 | |||
| 328 | nissy_convert_error: | ||
| 329 | result[0] = '\0'; | ||
| 330 | return err; | 286 | return err; |
| 331 | } | 287 | } |
| 332 | 288 | ||
| @@ -337,7 +293,7 @@ nissy_getcube( | |||
| 337 | long long cp, | 293 | long long cp, |
| 338 | long long co, | 294 | long long co, |
| 339 | const char *options, | 295 | const char *options, |
| 340 | char result[static NISSY_SIZE_B32] | 296 | char result[static NISSY_SIZE_CUBE] |
| 341 | ) | 297 | ) |
| 342 | { | 298 | { |
| 343 | int i; | 299 | int i; |
| @@ -526,7 +482,7 @@ nissy_checkdata( | |||
| 526 | 482 | ||
| 527 | long long | 483 | long long |
| 528 | nissy_solve( | 484 | nissy_solve( |
| 529 | const char cube[static NISSY_SIZE_B32], | 485 | const char cube[static NISSY_SIZE_CUBE], |
| 530 | const char *solver, | 486 | const char *solver, |
| 531 | unsigned nissflag, | 487 | unsigned nissflag, |
| 532 | unsigned minmoves, | 488 | unsigned minmoves, |
| @@ -551,7 +507,7 @@ nissy_solve( | |||
| 551 | return NISSY_ERROR_NULL_POINTER; | 507 | return NISSY_ERROR_NULL_POINTER; |
| 552 | } | 508 | } |
| 553 | 509 | ||
| 554 | c = readcube_B32(cube); | 510 | c = readcube(cube); |
| 555 | 511 | ||
| 556 | if (!isconsistent(c)) { | 512 | if (!isconsistent(c)) { |
| 557 | LOG("[solve] Error: cube is invalid\n"); | 513 | LOG("[solve] Error: cube is invalid\n"); |
