diff options
Diffstat (limited to 'src/solvers/solutions.h')
| -rw-r--r-- | src/solvers/solutions.h | 24 |
1 files changed, 3 insertions, 21 deletions
diff --git a/src/solvers/solutions.h b/src/solvers/solutions.h index 75d0804..182ae18 100644 --- a/src/solvers/solutions.h +++ b/src/solvers/solutions.h | |||
| @@ -12,8 +12,7 @@ STATIC bool appendnormal( | |||
| 12 | STATIC bool appendinverse( | 12 | STATIC bool appendinverse( |
| 13 | const solution_moves_t [static 1], solution_list_t [static 1]); | 13 | const solution_moves_t [static 1], solution_list_t [static 1]); |
| 14 | STATIC int64_t appendsolution(const solution_moves_t [static 1], | 14 | STATIC int64_t appendsolution(const solution_moves_t [static 1], |
| 15 | const solution_settings_t [static 1], solution_list_t [static 1], bool, | 15 | const solution_settings_t [static 1], solution_list_t [static 1]); |
| 16 | const char *); | ||
| 17 | STATIC bool solutions_done(const solution_list_t [static 1], | 16 | STATIC bool solutions_done(const solution_list_t [static 1], |
| 18 | const solution_settings_t [static 1], int8_t depth); | 17 | const solution_settings_t [static 1], int8_t depth); |
| 19 | 18 | ||
| @@ -53,10 +52,8 @@ solution_moves_reorient(solution_moves_t moves[static 1], uint8_t or) | |||
| 53 | STATIC bool | 52 | STATIC bool |
| 54 | solution_list_init(solution_list_t sols[static 1], size_t n, char buf[n]) | 53 | solution_list_init(solution_list_t sols[static 1], size_t n, char buf[n]) |
| 55 | { | 54 | { |
| 56 | if (n == 0) { | 55 | if (n == 0) |
| 57 | LOG("Error: cannot use solution buffer with size 0\n"); | ||
| 58 | return false; | 56 | return false; |
| 59 | } | ||
| 60 | 57 | ||
| 61 | sols->nsols = 0; | 58 | sols->nsols = 0; |
| 62 | sols->shortest_sol = MAXLEN + 1; | 59 | sols->shortest_sol = MAXLEN + 1; |
| @@ -158,16 +155,13 @@ STATIC int64_t | |||
| 158 | appendsolution( | 155 | appendsolution( |
| 159 | const solution_moves_t moves[static 1], | 156 | const solution_moves_t moves[static 1], |
| 160 | const solution_settings_t settings[static 1], | 157 | const solution_settings_t settings[static 1], |
| 161 | solution_list_t list[static 1], | 158 | solution_list_t list[static 1] |
| 162 | bool log, | ||
| 163 | const char *solver_name | ||
| 164 | ) | 159 | ) |
| 165 | { | 160 | { |
| 166 | int64_t r; | 161 | int64_t r; |
| 167 | int i; | 162 | int i; |
| 168 | uint8_t t; | 163 | uint8_t t; |
| 169 | solution_moves_t tsol[NTRANS]; | 164 | solution_moves_t tsol[NTRANS]; |
| 170 | char *last_start; | ||
| 171 | 165 | ||
| 172 | if (moves->nmoves + moves->npremoves > MAXLEN) | 166 | if (moves->nmoves + moves->npremoves > MAXLEN) |
| 173 | goto appendsolution_error_solution_length; | 167 | goto appendsolution_error_solution_length; |
| @@ -210,8 +204,6 @@ appendsolution( | |||
| 210 | if (solution_moves_is_duplicate(r, tsol)) | 204 | if (solution_moves_is_duplicate(r, tsol)) |
| 211 | continue; | 205 | continue; |
| 212 | 206 | ||
| 213 | last_start = list->buf + list->used; | ||
| 214 | |||
| 215 | /* Append first the moves on the side that has more */ | 207 | /* Append first the moves on the side that has more */ |
| 216 | /* E.g. write (U L F) B instead of B (U L F) */ | 208 | /* E.g. write (U L F) B instead of B (U L F) */ |
| 217 | if (tsol[r].nmoves >= tsol[r].npremoves) { | 209 | if (tsol[r].nmoves >= tsol[r].npremoves) { |
| @@ -244,26 +236,16 @@ appendsolution( | |||
| 244 | list->shortest_sol, tsol[r].nmoves + tsol[r].npremoves); | 236 | list->shortest_sol, tsol[r].nmoves + tsol[r].npremoves); |
| 245 | r++; | 237 | r++; |
| 246 | 238 | ||
| 247 | if (log) { | ||
| 248 | list->buf[list->used-1] = '\0'; | ||
| 249 | LOG("[%s solve] Found solution #%" PRIu64 ": %s\n", | ||
| 250 | solver_name, list->nsols, last_start); | ||
| 251 | list->buf[list->used-1] = '\n'; | ||
| 252 | } | ||
| 253 | } | 239 | } |
| 254 | 240 | ||
| 255 | list->buf[list->used] = '\0'; | 241 | list->buf[list->used] = '\0'; |
| 256 | return r; | 242 | return r; |
| 257 | 243 | ||
| 258 | appendsolution_error_buffer: | 244 | appendsolution_error_buffer: |
| 259 | LOG("[%s solve] Error: buffer too small\n", solver_name); | ||
| 260 | list->buf[0] = '\0'; | 245 | list->buf[0] = '\0'; |
| 261 | return NISSY_ERROR_BUFFER_SIZE; | 246 | return NISSY_ERROR_BUFFER_SIZE; |
| 262 | 247 | ||
| 263 | appendsolution_error_solution_length: | 248 | appendsolution_error_solution_length: |
| 264 | LOG("[%s solve] Error: solution is too long (%" PRIu8 ").\n" | ||
| 265 | "This is a bug, please report it.\n", | ||
| 266 | solver_name, moves->nmoves + moves->npremoves); | ||
| 267 | list->buf[0] = '\0'; | 249 | list->buf[0] = '\0'; |
| 268 | return NISSY_ERROR_UNKNOWN; | 250 | return NISSY_ERROR_UNKNOWN; |
| 269 | } | 251 | } |
