diff options
| -rw-r--r-- | src/nissy.c | 8 | ||||
| -rw-r--r-- | src/solvers/coord/gendata.h | 17 | ||||
| -rw-r--r-- | src/solvers/dispatch.h | 8 | ||||
| -rw-r--r-- | src/solvers/solutions_types_macros.h | 2 | ||||
| -rw-r--r-- | src/solvers/solvers.h | 1 | ||||
| -rw-r--r-- | src/solvers/twostep/twostep.h | 117 | ||||
| -rw-r--r-- | test/140_appendsolution/07_unniss_cancel_nosol.out | 2 | ||||
| -rw-r--r-- | test/140_appendsolution/08_unniss_cancel_nosol_v2.out | 2 |
8 files changed, 146 insertions, 11 deletions
diff --git a/src/nissy.c b/src/nissy.c index 0811861..5423d8d 100644 --- a/src/nissy.c +++ b/src/nissy.c | |||
| @@ -328,10 +328,10 @@ nissy_solve( | |||
| 328 | return NISSY_ERROR_INVALID_CUBE; | 328 | return NISSY_ERROR_INVALID_CUBE; |
| 329 | } | 329 | } |
| 330 | 330 | ||
| 331 | if (maxmoves > 20) { | 331 | if (maxmoves > SOLUTION_MAXLEN) { |
| 332 | LOG("[solve] 'maxmoves' larger than 20 not supported yet, " | 332 | LOG("[solve] 'maxmoves' larger than %d not supported yet, " |
| 333 | "setting it to 20\n"); | 333 | "setting it to %d\n", SOLUTION_MAXLEN, SOLUTION_MAXLEN); |
| 334 | maxmoves = 20; | 334 | maxmoves = SOLUTION_MAXLEN; |
| 335 | } | 335 | } |
| 336 | 336 | ||
| 337 | if (minmoves > maxmoves) { | 337 | if (minmoves > maxmoves) { |
diff --git a/src/solvers/coord/gendata.h b/src/solvers/coord/gendata.h index 0acf9c0..a48263c 100644 --- a/src/solvers/coord/gendata.h +++ b/src/solvers/coord/gendata.h | |||
| @@ -27,16 +27,25 @@ gendata_coord_dispatch( | |||
| 27 | unsigned char *buf | 27 | unsigned char *buf |
| 28 | ) | 28 | ) |
| 29 | { | 29 | { |
| 30 | size_t r; | ||
| 30 | coord_t *coord; | 31 | coord_t *coord; |
| 31 | multicoord_t *mcoord; | 32 | multicoord_t *mcoord; |
| 32 | 33 | ||
| 33 | parse_coord_and_trans(coordstr, &coord, &mcoord, NULL); | 34 | parse_coord_and_trans(coordstr, &coord, &mcoord, NULL); |
| 34 | 35 | ||
| 35 | if (coord != NULL) | 36 | if (coord != NULL) { |
| 36 | return gendata_coord(coord, buf); | 37 | if (bufsize < gendata_coord(coord, NULL)) |
| 38 | return NISSY_ERROR_BUFFER_SIZE; | ||
| 39 | r = gendata_coord(coord, buf); | ||
| 40 | return r == 0 ? NISSY_ERROR_UNKNOWN : (long long)r; | ||
| 41 | } | ||
| 37 | 42 | ||
| 38 | if (mcoord != NULL) | 43 | if (mcoord != NULL) { |
| 39 | return gendata_multicoord(mcoord, buf); | 44 | if (bufsize < gendata_multicoord(mcoord, NULL)) |
| 45 | return NISSY_ERROR_BUFFER_SIZE; | ||
| 46 | r = gendata_multicoord(mcoord, buf); | ||
| 47 | return r == 0 ? NISSY_ERROR_UNKNOWN : (long long)r; | ||
| 48 | } | ||
| 40 | 49 | ||
| 41 | LOG("Error: could not parse coordinate '%s'\n", coordstr); | 50 | LOG("Error: could not parse coordinate '%s'\n", coordstr); |
| 42 | return NISSY_ERROR_INVALID_SOLVER; | 51 | return NISSY_ERROR_INVALID_SOLVER; |
diff --git a/src/solvers/dispatch.h b/src/solvers/dispatch.h index d484736..89a0771 100644 --- a/src/solvers/dispatch.h +++ b/src/solvers/dispatch.h | |||
| @@ -41,6 +41,13 @@ solver_dispatch_t solver_dispatchers[] = { | |||
| 41 | .solve = solve_multicoord_dispatch, | 41 | .solve = solve_multicoord_dispatch, |
| 42 | }, | 42 | }, |
| 43 | { | 43 | { |
| 44 | .prefix = "twostep", | ||
| 45 | .dataid = dataid_twostep, | ||
| 46 | .gendata = gendata_twostep, | ||
| 47 | .checkdata = checkdata_twostep, | ||
| 48 | .solve = solve_twostep, | ||
| 49 | }, | ||
| 50 | { | ||
| 44 | .prefix = NULL | 51 | .prefix = NULL |
| 45 | } | 52 | } |
| 46 | }; | 53 | }; |
| @@ -70,6 +77,7 @@ const char *solver_aliases[][2] = { | |||
| 70 | { "htr-drfb", "coord_HTR_BU" }, | 77 | { "htr-drfb", "coord_HTR_BU" }, |
| 71 | { "corners", "coord_CORNERS_UF" }, | 78 | { "corners", "coord_CORNERS_UF" }, |
| 72 | { "cornersx", "coord_CORNERSX_UF" }, | 79 | { "cornersx", "coord_CORNERSX_UF" }, |
| 80 | { "quick", "twostep" }, | ||
| 73 | { NULL, NULL } | 81 | { NULL, NULL } |
| 74 | }; | 82 | }; |
| 75 | 83 | ||
diff --git a/src/solvers/solutions_types_macros.h b/src/solvers/solutions_types_macros.h index 8454a21..6cde681 100644 --- a/src/solvers/solutions_types_macros.h +++ b/src/solvers/solutions_types_macros.h | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | #ifndef SOLVERS_SOLUTIONS_TYPES_MACROS_H | 1 | #ifndef SOLVERS_SOLUTIONS_TYPES_MACROS_H |
| 2 | #define SOLVERS_SOLUTIONS_TYPES_MACROS_H | 2 | #define SOLVERS_SOLUTIONS_TYPES_MACROS_H |
| 3 | 3 | ||
| 4 | #define SOLUTION_MAXLEN 20 | 4 | #define SOLUTION_MAXLEN 25 |
| 5 | 5 | ||
| 6 | typedef struct { | 6 | typedef struct { |
| 7 | uint8_t nmoves; | 7 | uint8_t nmoves; |
diff --git a/src/solvers/solvers.h b/src/solvers/solvers.h index 78180aa..fab6e27 100644 --- a/src/solvers/solvers.h +++ b/src/solvers/solvers.h | |||
| @@ -7,6 +7,7 @@ | |||
| 7 | #include "tables.h" | 7 | #include "tables.h" |
| 8 | #include "distribution.h" | 8 | #include "distribution.h" |
| 9 | #include "coord/coord.h" | 9 | #include "coord/coord.h" |
| 10 | #include "twostep/twostep.h" | ||
| 10 | #include "h48/h48.h" | 11 | #include "h48/h48.h" |
| 11 | #include "dispatch.h" | 12 | #include "dispatch.h" |
| 12 | 13 | ||
diff --git a/src/solvers/twostep/twostep.h b/src/solvers/twostep/twostep.h new file mode 100644 index 0000000..e5b00f6 --- /dev/null +++ b/src/solvers/twostep/twostep.h | |||
| @@ -0,0 +1,117 @@ | |||
| 1 | #ifndef SRC_SOLVERS_TWOSTEP_TWOSTEP_H | ||
| 2 | #define SRC_SOLVERS_TWOSTEP_TWOSTEP_H | ||
| 3 | |||
| 4 | #include "../coord/coord.h" | ||
| 5 | |||
| 6 | STATIC size_t twostep_size_1(void); | ||
| 7 | STATIC size_t twostep_size_2(void); | ||
| 8 | STATIC long long dataid_twostep(const char *, char [SIZE(NISSY_SIZE_DATAID)]); | ||
| 9 | STATIC long long gendata_twostep( | ||
| 10 | const char *, unsigned long long, unsigned char *); | ||
| 11 | STATIC long long checkdata_twostep( | ||
| 12 | const char *, unsigned long long, const unsigned char *); | ||
| 13 | STATIC long long solve_twostep(oriented_cube_t, const char *, unsigned, | ||
| 14 | unsigned, unsigned, unsigned, unsigned, unsigned, unsigned long long, | ||
| 15 | const unsigned char *, unsigned, char *, | ||
| 16 | long long [SIZE(NISSY_SIZE_SOLVE_STATS)], int (*)(void *), void *); | ||
| 17 | |||
| 18 | STATIC size_t | ||
| 19 | twostep_size_1(void) | ||
| 20 | { | ||
| 21 | size_t s; | ||
| 22 | |||
| 23 | s = gendata_coord(&coordinate_dr, NULL); | ||
| 24 | s = (size_t)8 * DIV_ROUND_UP(s, 8); /* Preserve 8-byte alignment */ | ||
| 25 | |||
| 26 | return s; | ||
| 27 | } | ||
| 28 | |||
| 29 | STATIC size_t | ||
| 30 | twostep_size_2(void) | ||
| 31 | { | ||
| 32 | return gendata_multicoord(&multicoordinate_drfin, NULL); | ||
| 33 | } | ||
| 34 | |||
| 35 | STATIC long long | ||
| 36 | dataid_twostep(const char *s, char dataid[SIZE(NISSY_SIZE_DATAID)]) | ||
| 37 | { | ||
| 38 | strcpy(dataid, "DR_DRFIN"); | ||
| 39 | return NISSY_OK; | ||
| 40 | } | ||
| 41 | |||
| 42 | STATIC long long | ||
| 43 | gendata_twostep( | ||
| 44 | const char *s, | ||
| 45 | unsigned long long bufsize, | ||
| 46 | unsigned char *buf | ||
| 47 | ) | ||
| 48 | { | ||
| 49 | size_t r, s1, s2; | ||
| 50 | |||
| 51 | s1 = twostep_size_1(); | ||
| 52 | s2 = twostep_size_2(); | ||
| 53 | |||
| 54 | if (buf == NULL) | ||
| 55 | goto gendata_twostep_return_size; | ||
| 56 | |||
| 57 | if (bufsize < s1 + s2) | ||
| 58 | return NISSY_ERROR_BUFFER_SIZE; | ||
| 59 | |||
| 60 | r = gendata_coord(&coordinate_dr, buf); | ||
| 61 | if (r == 0) | ||
| 62 | return NISSY_ERROR_UNKNOWN; | ||
| 63 | |||
| 64 | r = gendata_multicoord(&multicoordinate_drfin, buf + s1); | ||
| 65 | if (r == 0) | ||
| 66 | return NISSY_ERROR_UNKNOWN; | ||
| 67 | |||
| 68 | gendata_twostep_return_size: | ||
| 69 | return s1 + s2; | ||
| 70 | } | ||
| 71 | |||
| 72 | STATIC long long | ||
| 73 | checkdata_twostep( | ||
| 74 | const char *s, | ||
| 75 | unsigned long long bufsize, | ||
| 76 | const unsigned char *buf | ||
| 77 | ) | ||
| 78 | { | ||
| 79 | long long r; | ||
| 80 | |||
| 81 | LOG("[checkdata] Checking double table for two step solver\n"); | ||
| 82 | |||
| 83 | r = checkdata_coord(&coordinate_dr, bufsize, buf); | ||
| 84 | if (r != NISSY_OK) | ||
| 85 | return r; | ||
| 86 | |||
| 87 | r = checkdata_multicoord( | ||
| 88 | &multicoordinate_drfin, bufsize, buf + twostep_size_1()); | ||
| 89 | if (r != NISSY_OK) | ||
| 90 | return r; | ||
| 91 | |||
| 92 | return NISSY_OK; | ||
| 93 | } | ||
| 94 | |||
| 95 | STATIC long long | ||
| 96 | solve_twostep( | ||
| 97 | oriented_cube_t oc, | ||
| 98 | const char *coord_and_trans, | ||
| 99 | unsigned nissflag, | ||
| 100 | unsigned minmoves, | ||
| 101 | unsigned maxmoves, | ||
| 102 | unsigned maxsolutions, | ||
| 103 | unsigned optimal, | ||
| 104 | unsigned threads, | ||
| 105 | unsigned long long data_size, | ||
| 106 | const unsigned char *data, | ||
| 107 | unsigned solutions_size, | ||
| 108 | char *sols, | ||
| 109 | long long stats[SIZE(NISSY_SIZE_SOLVE_STATS)], | ||
| 110 | int (*poll_status)(void *), | ||
| 111 | void *poll_status_data | ||
| 112 | ) | ||
| 113 | { | ||
| 114 | //TODO | ||
| 115 | } | ||
| 116 | |||
| 117 | #endif /* SRC_SOLVERS_TWOSTEP_TWOSTEP_H */ | ||
diff --git a/test/140_appendsolution/07_unniss_cancel_nosol.out b/test/140_appendsolution/07_unniss_cancel_nosol.out index ed5ea65..cd355c7 100644 --- a/test/140_appendsolution/07_unniss_cancel_nosol.out +++ b/test/140_appendsolution/07_unniss_cancel_nosol.out | |||
| @@ -1,3 +1,3 @@ | |||
| 1 | Number of solutions: 0 | 1 | Number of solutions: 0 |
| 2 | Shortest solution length: 21 | 2 | Shortest solution length: 26 |
| 3 | Used bytes: 0 | 3 | Used bytes: 0 |
diff --git a/test/140_appendsolution/08_unniss_cancel_nosol_v2.out b/test/140_appendsolution/08_unniss_cancel_nosol_v2.out index ed5ea65..cd355c7 100644 --- a/test/140_appendsolution/08_unniss_cancel_nosol_v2.out +++ b/test/140_appendsolution/08_unniss_cancel_nosol_v2.out | |||
| @@ -1,3 +1,3 @@ | |||
| 1 | Number of solutions: 0 | 1 | Number of solutions: 0 |
| 2 | Shortest solution length: 21 | 2 | Shortest solution length: 26 |
| 3 | Used bytes: 0 | 3 | Used bytes: 0 |
