diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2025-04-17 10:50:57 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2025-04-17 14:36:27 +0200 |
| commit | 0ece4b72db22139db51e8f5f37c25f24c84f3e43 (patch) | |
| tree | fa9d0f5ec4124b2e51194ec6dc888e037b9da7e2 | |
| parent | 785f2859e336db49095a8443be8d204ba0989925 (diff) | |
| download | nissy-core-0ece4b72db22139db51e8f5f37c25f24c84f3e43.tar.gz nissy-core-0ece4b72db22139db51e8f5f37c25f24c84f3e43.zip | |
Small rework of optimal vs maxsols
I wanted to make the "optimal" and "maxsolutions" options mutually
exclusive, but in the end I decided there is value in keeping both
(e.g. for specifying a limit to the number of solutions when asking
for "all" optimal").
Now optimal cannot be negative anymore, for the same reason of maxsolutions.
The interface user (shell, UI) will have to take care of handling this
in a way that makes sense for the user. Usually this means setting
the maximum number of solutions to UINT_MAX (or a similar very high
number) when the user wants "all optimal".
| -rw-r--r-- | cpp/examples/solve_h48h3k2.cpp | 2 | ||||
| -rw-r--r-- | cpp/nissy.cpp | 16 | ||||
| -rw-r--r-- | cpp/nissy.h | 4 | ||||
| -rw-r--r-- | python/examples/solve.py | 2 | ||||
| -rw-r--r-- | python/nissy_module.c | 5 | ||||
| -rw-r--r-- | shell/shell.c | 8 | ||||
| -rw-r--r-- | src/nissy.c | 12 | ||||
| -rw-r--r-- | src/nissy.h | 7 | ||||
| -rw-r--r-- | src/solvers/coord/solve.h | 13 | ||||
| -rw-r--r-- | src/solvers/h48/solve.h | 22 | ||||
| -rw-r--r-- | src/solvers/solutions.h | 15 | ||||
| -rw-r--r-- | src/solvers/solutions_types_macros.h | 2 |
12 files changed, 55 insertions, 53 deletions
diff --git a/cpp/examples/solve_h48h3k2.cpp b/cpp/examples/solve_h48h3k2.cpp index 7f06376..f7ba235 100644 --- a/cpp/examples/solve_h48h3k2.cpp +++ b/cpp/examples/solve_h48h3k2.cpp | |||
| @@ -68,7 +68,7 @@ int main() { | |||
| 68 | 68 | ||
| 69 | // Solve | 69 | // Solve |
| 70 | auto solve_result = h48h3k2.solve(c, nissy::nissflag::NORMAL, | 70 | auto solve_result = h48h3k2.solve(c, nissy::nissflag::NORMAL, |
| 71 | 0, maxmoves, 1, -1, 8); | 71 | 0, maxmoves, 1, 20, 8); |
| 72 | 72 | ||
| 73 | // Write the result | 73 | // Write the result |
| 74 | if (!solve_result.err.ok()) { | 74 | if (!solve_result.err.ok()) { |
diff --git a/cpp/nissy.cpp b/cpp/nissy.cpp index 944944b..92b10bd 100644 --- a/cpp/nissy.cpp +++ b/cpp/nissy.cpp | |||
| @@ -21,8 +21,8 @@ extern "C" { | |||
| 21 | long long nissy_gendata(const char *, unsigned long long, char *); | 21 | long long nissy_gendata(const char *, unsigned long long, char *); |
| 22 | long long nissy_checkdata(unsigned long long, const char *); | 22 | long long nissy_checkdata(unsigned long long, const char *); |
| 23 | long long nissy_solve(const char *, const char *, unsigned, unsigned, | 23 | long long nissy_solve(const char *, const char *, unsigned, unsigned, |
| 24 | unsigned, unsigned, int, int, unsigned long long, const char *, | 24 | unsigned, unsigned, unsigned, unsigned, unsigned long long, |
| 25 | unsigned, char *, long long *); | 25 | const char *, unsigned, char *, long long *); |
| 26 | long long nissy_countmoves(const char *); | 26 | long long nissy_countmoves(const char *); |
| 27 | long long nissy_setlogger(void (*)(const char *, void *), void *); | 27 | long long nissy_setlogger(void (*)(const char *, void *), void *); |
| 28 | } | 28 | } |
| @@ -182,11 +182,19 @@ namespace nissy { | |||
| 182 | 182 | ||
| 183 | solver::solve_result | 183 | solver::solve_result |
| 184 | solver::solve(const cube& cube, nissflag niss, unsigned minmoves, | 184 | solver::solve(const cube& cube, nissflag niss, unsigned minmoves, |
| 185 | unsigned maxmoves, unsigned maxsols, int optimal, int threads) | 185 | unsigned maxmoves, unsigned maxsols, unsigned optimal, |
| 186 | unsigned threads) | ||
| 186 | { | 187 | { |
| 188 | solver::solve_result result; | ||
| 189 | |||
| 190 | if (maxsols == 0) { | ||
| 191 | result.solutions = {}; | ||
| 192 | result.err = error::OK; | ||
| 193 | return result; | ||
| 194 | } | ||
| 195 | |||
| 187 | const size_t len = 3 * (maxmoves+1) * maxsols; | 196 | const size_t len = 3 * (maxmoves+1) * maxsols; |
| 188 | std::vector<char> csols(len); | 197 | std::vector<char> csols(len); |
| 189 | solver::solve_result result; | ||
| 190 | 198 | ||
| 191 | auto err = nissy_solve(cube.to_string().c_str(), | 199 | auto err = nissy_solve(cube.to_string().c_str(), |
| 192 | name.c_str(), niss.value, minmoves, maxmoves, maxsols, | 200 | name.c_str(), niss.value, minmoves, maxmoves, maxsols, |
diff --git a/cpp/nissy.h b/cpp/nissy.h index db8ba5f..4b9c1c9 100644 --- a/cpp/nissy.h +++ b/cpp/nissy.h | |||
| @@ -91,8 +91,8 @@ namespace nissy { | |||
| 91 | error check_data(); | 91 | error check_data(); |
| 92 | void unload_data(); | 92 | void unload_data(); |
| 93 | solve_result solve(const cube&, nissflag, unsigned minmoves, | 93 | solve_result solve(const cube&, nissflag, unsigned minmoves, |
| 94 | unsigned maxmoves, unsigned maxsols, int optimal, | 94 | unsigned maxmoves, unsigned maxsols, unsigned optimal, |
| 95 | int threads); | 95 | unsigned threads); |
| 96 | 96 | ||
| 97 | static std::variant<solver, error> get(const std::string&); | 97 | static std::variant<solver, error> get(const std::string&); |
| 98 | private: | 98 | private: |
diff --git a/python/examples/solve.py b/python/examples/solve.py index b939183..a60c432 100644 --- a/python/examples/solve.py +++ b/python/examples/solve.py | |||
| @@ -23,7 +23,7 @@ data = bytearray(open("tables/" + solver, "rb").read()) | |||
| 23 | cube = nissy.applymoves(nissy.solved_cube, "U F R2"); | 23 | cube = nissy.applymoves(nissy.solved_cube, "U F R2"); |
| 24 | 24 | ||
| 25 | # Solve! | 25 | # Solve! |
| 26 | solutions = nissy.solve(cube, solver, nissy.nissflag_normal, 0, 9, 3, -1, 4, data) | 26 | solutions = nissy.solve(cube, solver, nissy.nissflag_normal, 0, 9, 3, 20, 4, data) |
| 27 | 27 | ||
| 28 | # Print the solutions, one per line | 28 | # Print the solutions, one per line |
| 29 | print("Found ", len(solutions), " solutions:") | 29 | print("Found ", len(solutions), " solutions:") |
diff --git a/python/nissy_module.c b/python/nissy_module.c index e92cfd9..46570dc 100644 --- a/python/nissy_module.c +++ b/python/nissy_module.c | |||
| @@ -324,8 +324,7 @@ PyDoc_STRVAR(solve_doc, | |||
| 324 | " - minmoves: the minimum number of moves to use\n" | 324 | " - minmoves: the minimum number of moves to use\n" |
| 325 | " - maxmoves: the maximum number of moves to use\n" | 325 | " - maxmoves: the maximum number of moves to use\n" |
| 326 | " - maxsolution: the maximum number of solutions to return\n" | 326 | " - maxsolution: the maximum number of solutions to return\n" |
| 327 | " - optimal: the largest number of moves from the shortest solution" | 327 | " - optimal: the largest number of moves from the shortest solution\n" |
| 328 | "(set to -1 to ignore)\n" | ||
| 329 | " - threads: the number of threads to use (0 for default)\n" | 328 | " - threads: the number of threads to use (0 for default)\n" |
| 330 | " - data: a bytearray containing the data for the solver\n" | 329 | " - data: a bytearray containing the data for the solver\n" |
| 331 | "\n" | 330 | "\n" |
| @@ -343,7 +342,7 @@ solve(PyObject *self, PyObject *args) | |||
| 343 | PyByteArrayObject *data; | 342 | PyByteArrayObject *data; |
| 344 | PyObject *list, *item; | 343 | PyObject *list, *item; |
| 345 | 344 | ||
| 346 | if (!PyArg_ParseTuple(args, "ssIIIIiiY", &cube, &solver, &nissflag, | 345 | if (!PyArg_ParseTuple(args, "ssIIIIIIY", &cube, &solver, &nissflag, |
| 347 | &minmoves, &maxmoves, &maxsolutions, &optimal, &threads, &data)) | 346 | &minmoves, &maxmoves, &maxsolutions, &optimal, &threads, &data)) |
| 348 | return NULL; | 347 | return NULL; |
| 349 | 348 | ||
diff --git a/shell/shell.c b/shell/shell.c index 1ef1a39..2a2720f 100644 --- a/shell/shell.c +++ b/shell/shell.c | |||
| @@ -1,4 +1,5 @@ | |||
| 1 | #include <inttypes.h> | 1 | #include <inttypes.h> |
| 2 | #include <limits.h> | ||
| 2 | #include <errno.h> | 3 | #include <errno.h> |
| 3 | #include <stdarg.h> | 4 | #include <stdarg.h> |
| 4 | #include <stdbool.h> | 5 | #include <stdbool.h> |
| @@ -482,6 +483,9 @@ solve_exec(args_t *args) | |||
| 482 | return -1; | 483 | return -1; |
| 483 | } | 484 | } |
| 484 | 485 | ||
| 486 | if (args->maxsolutions == 0) | ||
| 487 | args->maxsolutions = args->optimal >= 0 ? UINT_MAX : 1; | ||
| 488 | |||
| 485 | buf = malloc(size); | 489 | buf = malloc(size); |
| 486 | read = fread(buf, size, 1, file); | 490 | read = fread(buf, size, 1, file); |
| 487 | fclose(file); | 491 | fclose(file); |
| @@ -578,8 +582,8 @@ parse_args(int argc, char **argv, args_t *args) | |||
| 578 | .str_nisstype = "", | 582 | .str_nisstype = "", |
| 579 | .minmoves = 0, | 583 | .minmoves = 0, |
| 580 | .maxmoves = 20, | 584 | .maxmoves = 20, |
| 581 | .optimal = -1, | 585 | .optimal = 20, |
| 582 | .maxsolutions = 1, | 586 | .maxsolutions = 0, |
| 583 | .threads = 0, | 587 | .threads = 0, |
| 584 | }; | 588 | }; |
| 585 | 589 | ||
diff --git a/src/nissy.c b/src/nissy.c index a7f8432..ba43e5d 100644 --- a/src/nissy.c +++ b/src/nissy.c | |||
| @@ -534,8 +534,8 @@ nissy_solve( | |||
| 534 | unsigned minmoves, | 534 | unsigned minmoves, |
| 535 | unsigned maxmoves, | 535 | unsigned maxmoves, |
| 536 | unsigned maxsols, | 536 | unsigned maxsols, |
| 537 | int optimal, | 537 | unsigned optimal, |
| 538 | int threads, | 538 | unsigned threads, |
| 539 | unsigned long long data_size, | 539 | unsigned long long data_size, |
| 540 | const char data[data_size], | 540 | const char data[data_size], |
| 541 | unsigned sols_size, | 541 | unsigned sols_size, |
| @@ -546,7 +546,7 @@ nissy_solve( | |||
| 546 | cube_t c; | 546 | cube_t c; |
| 547 | long long parse_ret; | 547 | long long parse_ret; |
| 548 | uint8_t h, k; | 548 | uint8_t h, k; |
| 549 | int t, opt; | 549 | int t; |
| 550 | 550 | ||
| 551 | if (solver == NULL) { | 551 | if (solver == NULL) { |
| 552 | LOG("Error: 'solver' argument is NULL\n"); | 552 | LOG("Error: 'solver' argument is NULL\n"); |
| @@ -573,8 +573,6 @@ nissy_solve( | |||
| 573 | return 0; | 573 | return 0; |
| 574 | } | 574 | } |
| 575 | 575 | ||
| 576 | opt = optimal < 0 ? MAXLEN : optimal; | ||
| 577 | |||
| 578 | t = threads == 0 ? THREADS : threads; | 576 | t = threads == 0 ? THREADS : threads; |
| 579 | if (t < 0) { | 577 | if (t < 0) { |
| 580 | LOG("solve: 'threads' is negative. Please provide a " | 578 | LOG("solve: 'threads' is negative. Please provide a " |
| @@ -597,10 +595,10 @@ nissy_solve( | |||
| 597 | if (parse_ret != NISSY_OK) | 595 | if (parse_ret != NISSY_OK) |
| 598 | return parse_ret; | 596 | return parse_ret; |
| 599 | return solve_h48(c, minmoves, maxmoves, maxsols, | 597 | return solve_h48(c, minmoves, maxmoves, maxsols, |
| 600 | opt, t, data_size, data, sols_size, sols, stats); | 598 | optimal, t, data_size, data, sols_size, sols, stats); |
| 601 | } else if (!strncmp(solver, "coord_", 6)) { | 599 | } else if (!strncmp(solver, "coord_", 6)) { |
| 602 | return solve_coord_dispatch(c, solver + 6, nissflag, | 600 | return solve_coord_dispatch(c, solver + 6, nissflag, |
| 603 | minmoves, maxmoves, maxsols, opt, t, data_size, data, | 601 | minmoves, maxmoves, maxsols, optimal, t, data_size, data, |
| 604 | sols_size, sols); | 602 | sols_size, sols); |
| 605 | } else { | 603 | } else { |
| 606 | LOG("solve: unknown solver '%s'\n", solver); | 604 | LOG("solve: unknown solver '%s'\n", solver); |
diff --git a/src/nissy.h b/src/nissy.h index b13f417..c23f338 100644 --- a/src/nissy.h +++ b/src/nissy.h | |||
| @@ -360,8 +360,7 @@ Parameters: | |||
| 360 | minmoves - The minimum number of moves for a solution. | 360 | minmoves - The minimum number of moves for a solution. |
| 361 | maxmoves - The maximum number of moves for a solution. | 361 | maxmoves - The maximum number of moves for a solution. |
| 362 | maxsols - The maximum number of solutions. | 362 | maxsols - The maximum number of solutions. |
| 363 | optimal - If set to a non-negative value, the maximum number of moves | 363 | optimal - The maximum number of moves above the optimal solution length. |
| 364 | above the optimal solution length. | ||
| 365 | threads - The number of threads to use. Must be less than or equalt to | 364 | threads - The number of threads to use. Must be less than or equalt to |
| 366 | the value of the compile-time constant THREADS. If set to 0, | 365 | the value of the compile-time constant THREADS. If set to 0, |
| 367 | the default value THREADS will be used. | 366 | the default value THREADS will be used. |
| @@ -393,8 +392,8 @@ nissy_solve( | |||
| 393 | unsigned minmoves, | 392 | unsigned minmoves, |
| 394 | unsigned maxmoves, | 393 | unsigned maxmoves, |
| 395 | unsigned maxsolutions, | 394 | unsigned maxsolutions, |
| 396 | int optimal, | 395 | unsigned optimal, |
| 397 | int threads, | 396 | unsigned threads, |
| 398 | unsigned long long data_size, | 397 | unsigned long long data_size, |
| 399 | const char data[data_size], | 398 | const char data[data_size], |
| 400 | unsigned sols_size, | 399 | unsigned sols_size, |
diff --git a/src/solvers/coord/solve.h b/src/solvers/coord/solve.h index 464f7bd..b289e3f 100644 --- a/src/solvers/coord/solve.h +++ b/src/solvers/coord/solve.h | |||
| @@ -13,10 +13,11 @@ typedef struct { | |||
| 13 | } dfsarg_solve_coord_t; | 13 | } dfsarg_solve_coord_t; |
| 14 | 14 | ||
| 15 | STATIC int64_t solve_coord(cube_t, coord_t [static 1], uint8_t, uint8_t, | 15 | STATIC int64_t solve_coord(cube_t, coord_t [static 1], uint8_t, uint8_t, |
| 16 | uint8_t, uint8_t, uint64_t, int8_t, int, uint64_t, const void *, | 16 | uint8_t, uint8_t, uint64_t, uint8_t, uint8_t, uint64_t, const void *, |
| 17 | size_t n, char [n]); | 17 | size_t n, char [n]); |
| 18 | STATIC int64_t solve_coord_dispatch(cube_t, const char *, uint8_t, uint8_t, | 18 | STATIC int64_t solve_coord_dispatch(cube_t, const char *, uint8_t, uint8_t, |
| 19 | uint8_t, uint64_t, int8_t, int, uint64_t, const void *, size_t n, char [n]); | 19 | uint8_t, uint64_t, uint8_t, uint8_t, uint64_t, const void *, size_t n, |
| 20 | char [n]); | ||
| 20 | STATIC bool coord_solution_admissible(const dfsarg_solve_coord_t [static 1]); | 21 | STATIC bool coord_solution_admissible(const dfsarg_solve_coord_t [static 1]); |
| 21 | STATIC bool solve_coord_dfs_stop(const dfsarg_solve_coord_t [static 1]); | 22 | STATIC bool solve_coord_dfs_stop(const dfsarg_solve_coord_t [static 1]); |
| 22 | STATIC bool coord_continue_onnormal(const dfsarg_solve_coord_t [static 1]); | 23 | STATIC bool coord_continue_onnormal(const dfsarg_solve_coord_t [static 1]); |
| @@ -204,8 +205,8 @@ solve_coord_dispatch( | |||
| 204 | uint8_t minmoves, | 205 | uint8_t minmoves, |
| 205 | uint8_t maxmoves, | 206 | uint8_t maxmoves, |
| 206 | uint64_t maxsolutions, | 207 | uint64_t maxsolutions, |
| 207 | int8_t optimal, | 208 | uint8_t optimal, |
| 208 | int threads, | 209 | uint8_t threads, |
| 209 | uint64_t data_size, | 210 | uint64_t data_size, |
| 210 | const void *data, | 211 | const void *data, |
| 211 | size_t solutions_size, | 212 | size_t solutions_size, |
| @@ -242,8 +243,8 @@ solve_coord( | |||
| 242 | uint8_t minmoves, | 243 | uint8_t minmoves, |
| 243 | uint8_t maxmoves, | 244 | uint8_t maxmoves, |
| 244 | uint64_t maxsolutions, | 245 | uint64_t maxsolutions, |
| 245 | int8_t optimal, | 246 | uint8_t optimal, |
| 246 | int threads, | 247 | uint8_t threads, |
| 247 | uint64_t data_size, | 248 | uint64_t data_size, |
| 248 | const void *data, | 249 | const void *data, |
| 249 | size_t solutions_size, | 250 | size_t solutions_size, |
diff --git a/src/solvers/h48/solve.h b/src/solvers/h48/solve.h index f076f11..78b4c97 100644 --- a/src/solvers/h48/solve.h +++ b/src/solvers/h48/solve.h | |||
| @@ -52,7 +52,7 @@ STATIC int64_t solve_h48_maketasks( | |||
| 52 | solve_h48_task_t [static STARTING_CUBES], int [static 1]); | 52 | solve_h48_task_t [static STARTING_CUBES], int [static 1]); |
| 53 | STATIC void *solve_h48_runthread(void *); | 53 | STATIC void *solve_h48_runthread(void *); |
| 54 | STATIC int64_t solve_h48_dfs(dfsarg_solve_h48_t [static 1]); | 54 | STATIC int64_t solve_h48_dfs(dfsarg_solve_h48_t [static 1]); |
| 55 | STATIC int64_t solve_h48(cube_t, int8_t, int8_t, uint64_t, int8_t, int8_t, | 55 | STATIC int64_t solve_h48(cube_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, |
| 56 | uint64_t, const void *, size_t n, char [n], | 56 | uint64_t, const void *, size_t n, char [n], |
| 57 | long long [static NISSY_SIZE_SOLVE_STATS]); | 57 | long long [static NISSY_SIZE_SOLVE_STATS]); |
| 58 | 58 | ||
| @@ -67,7 +67,9 @@ solve_h48_stop(dfsarg_solve_h48_t arg[static 1]) | |||
| 67 | n = arg->solution_moves->nmoves + arg->solution_moves->npremoves; | 67 | n = arg->solution_moves->nmoves + arg->solution_moves->npremoves; |
| 68 | target = arg->target_depth - n; | 68 | target = arg->target_depth - n; |
| 69 | if (target <= 0 || | 69 | if (target <= 0 || |
| 70 | arg->solution_list->nsols == arg->solution_settings->maxsolutions) | 70 | arg->solution_list->nsols >= arg->solution_settings->maxsolutions || |
| 71 | n > arg->solution_list->shortest_sol + | ||
| 72 | arg->solution_settings->optimal) | ||
| 71 | return true; | 73 | return true; |
| 72 | 74 | ||
| 73 | arg->movemask_normal = arg->movemask_inverse = MM_ALLMOVES; | 75 | arg->movemask_normal = arg->movemask_inverse = MM_ALLMOVES; |
| @@ -283,8 +285,8 @@ solve_h48_maketasks( | |||
| 283 | if (issolved(maketasks_arg->cube)) { | 285 | if (issolved(maketasks_arg->cube)) { |
| 284 | if (maketasks_arg->nmoves > maketasks_arg->maxmoves || | 286 | if (maketasks_arg->nmoves > maketasks_arg->maxmoves || |
| 285 | maketasks_arg->nmoves < maketasks_arg->minmoves || | 287 | maketasks_arg->nmoves < maketasks_arg->minmoves || |
| 286 | solve_arg->solution_list->nsols >= | 288 | solutions_done(solve_arg->solution_list, |
| 287 | solve_arg->solution_settings->maxsolutions) | 289 | solve_arg->solution_settings, maketasks_arg->nmoves)) |
| 288 | return NISSY_OK; | 290 | return NISSY_OK; |
| 289 | 291 | ||
| 290 | solution_moves_reset(&moves); | 292 | solution_moves_reset(&moves); |
| @@ -341,11 +343,11 @@ solve_h48_maketasks( | |||
| 341 | STATIC int64_t | 343 | STATIC int64_t |
| 342 | solve_h48( | 344 | solve_h48( |
| 343 | cube_t cube, | 345 | cube_t cube, |
| 344 | int8_t minmoves, | 346 | uint8_t minmoves, |
| 345 | int8_t maxmoves, | 347 | uint8_t maxmoves, |
| 346 | uint64_t maxsolutions, | 348 | uint8_t maxsolutions, |
| 347 | int8_t optimal, | 349 | uint8_t optimal, |
| 348 | int8_t threads, | 350 | uint8_t threads, |
| 349 | uint64_t data_size, | 351 | uint64_t data_size, |
| 350 | const void *data, | 352 | const void *data, |
| 351 | size_t solutions_size, | 353 | size_t solutions_size, |
| @@ -448,7 +450,7 @@ solve_h48( | |||
| 448 | solve_h48_maketasks(&arg[0], &maketasks_arg, tasks, &ntasks); | 450 | solve_h48_maketasks(&arg[0], &maketasks_arg, tasks, &ntasks); |
| 449 | if (ntasks < 0) | 451 | if (ntasks < 0) |
| 450 | goto solve_h48_error_solutions_buffer; | 452 | goto solve_h48_error_solutions_buffer; |
| 451 | if (sollist.nsols >= maxsolutions) | 453 | if (solutions_done(&sollist, &settings, MAX(minmoves, STARTING_MOVES))) |
| 452 | goto solve_h48_done; | 454 | goto solve_h48_done; |
| 453 | 455 | ||
| 454 | for (i = 0; i < threads; i++) { | 456 | for (i = 0; i < threads; i++) { |
diff --git a/src/solvers/solutions.h b/src/solvers/solutions.h index e65f299..95c1d1a 100644 --- a/src/solvers/solutions.h +++ b/src/solvers/solutions.h | |||
| @@ -43,8 +43,6 @@ solution_list_init(solution_list_t sols[static 1], size_t n, char buf[n]) | |||
| 43 | sols->size = n; | 43 | sols->size = n; |
| 44 | sols->used = 0; | 44 | sols->used = 0; |
| 45 | sols->buf = buf; | 45 | sols->buf = buf; |
| 46 | |||
| 47 | /* Ensure string buffer is NULL-terminated */ | ||
| 48 | sols->buf[0] = '\0'; | 46 | sols->buf[0] = '\0'; |
| 49 | 47 | ||
| 50 | return true; | 48 | return true; |
| @@ -215,15 +213,8 @@ solutions_done( | |||
| 215 | int8_t depth | 213 | int8_t depth |
| 216 | ) | 214 | ) |
| 217 | { | 215 | { |
| 218 | if (list->nsols >= settings->maxsolutions) | ||
| 219 | return true; | ||
| 220 | |||
| 221 | if (depth > settings->maxmoves) | ||
| 222 | return true; | ||
| 223 | 216 | ||
| 224 | if (list->nsols > 0 && settings->optimal >= 0 && | 217 | return depth > settings->maxmoves || |
| 225 | depth > list->shortest_sol + settings->optimal) | 218 | depth > list->shortest_sol + settings->optimal || |
| 226 | return true; | 219 | list->nsols >= settings->maxsolutions; |
| 227 | |||
| 228 | return false; | ||
| 229 | } | 220 | } |
diff --git a/src/solvers/solutions_types_macros.h b/src/solvers/solutions_types_macros.h index 06e099b..9b1431f 100644 --- a/src/solvers/solutions_types_macros.h +++ b/src/solvers/solutions_types_macros.h | |||
| @@ -12,7 +12,7 @@ typedef struct { | |||
| 12 | bool unniss; | 12 | bool unniss; |
| 13 | uint8_t maxmoves; | 13 | uint8_t maxmoves; |
| 14 | uint64_t maxsolutions; | 14 | uint64_t maxsolutions; |
| 15 | int8_t optimal; | 15 | uint8_t optimal; |
| 16 | } solution_settings_t; | 16 | } solution_settings_t; |
| 17 | 17 | ||
| 18 | typedef struct { | 18 | typedef struct { |
