diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/commands.c | 22 | ||||
| -rw-r--r-- | src/cubetypes.h | 2 | ||||
| -rw-r--r-- | src/solve.c | 9 |
3 files changed, 24 insertions, 9 deletions
diff --git a/src/commands.c b/src/commands.c index 7d30c88..56ff944 100644 --- a/src/commands.c +++ b/src/commands.c | |||
| @@ -147,7 +147,7 @@ solve_parse_args(int c, char **v) | |||
| 147 | a->opts->max_moves = 20; | 147 | a->opts->max_moves = 20; |
| 148 | a->opts->max_solutions = 1; | 148 | a->opts->max_solutions = 1; |
| 149 | a->opts->nthreads = 1; | 149 | a->opts->nthreads = 1; |
| 150 | a->opts->optimal_only = false; | 150 | a->opts->optimal = -1; |
| 151 | a->opts->can_niss = false; | 151 | a->opts->can_niss = false; |
| 152 | a->opts->verbose = false; | 152 | a->opts->verbose = false; |
| 153 | a->opts->all = false; | 153 | a->opts->all = false; |
| @@ -163,7 +163,7 @@ solve_parse_args(int c, char **v) | |||
| 163 | if (val < 0 || val > 100) { | 163 | if (val < 0 || val > 100) { |
| 164 | fprintf(stderr, | 164 | fprintf(stderr, |
| 165 | "Invalid min number of moves" | 165 | "Invalid min number of moves" |
| 166 | "(0 <= m <= 100).\n"); | 166 | "(0 <= N <= 100).\n"); |
| 167 | return a; | 167 | return a; |
| 168 | } | 168 | } |
| 169 | a->opts->min_moves = val; | 169 | a->opts->min_moves = val; |
| @@ -172,7 +172,7 @@ solve_parse_args(int c, char **v) | |||
| 172 | if (val < 0 || val > 100) { | 172 | if (val < 0 || val > 100) { |
| 173 | fprintf(stderr, | 173 | fprintf(stderr, |
| 174 | "Invalid max number of moves" | 174 | "Invalid max number of moves" |
| 175 | "(0 <= M <= 100).\n"); | 175 | "(0 <= N <= 100).\n"); |
| 176 | return a; | 176 | return a; |
| 177 | } | 177 | } |
| 178 | a->opts->max_moves = val; | 178 | a->opts->max_moves = val; |
| @@ -196,7 +196,18 @@ solve_parse_args(int c, char **v) | |||
| 196 | a->opts->max_solutions = val; | 196 | a->opts->max_solutions = val; |
| 197 | fixedmsols = true; | 197 | fixedmsols = true; |
| 198 | } else if (!strcmp(v[i], "-o")) { | 198 | } else if (!strcmp(v[i], "-o")) { |
| 199 | a->opts->optimal_only = true; | 199 | a->opts->optimal = 0; |
| 200 | infinitesols = true; | ||
| 201 | } else if (!strcmp(v[i], "-O") && i+1 < c) { | ||
| 202 | val = strtol(v[++i], NULL, 10); | ||
| 203 | if (val < 0 || val > 100 || | ||
| 204 | (val == 0 && strcmp("0", v[i]))) { | ||
| 205 | fprintf(stderr, | ||
| 206 | "Invalid max number of moves" | ||
| 207 | " (0 <= N <= 100).\n"); | ||
| 208 | return a; | ||
| 209 | } | ||
| 210 | a->opts->optimal = val; | ||
| 200 | infinitesols = true; | 211 | infinitesols = true; |
| 201 | } else if (!strcmp(v[i], "-N")) { | 212 | } else if (!strcmp(v[i], "-N")) { |
| 202 | a->opts->can_niss = true; | 213 | a->opts->can_niss = true; |
| @@ -447,7 +458,8 @@ read_scramble(int c, char **v, CommandArgs *args) | |||
| 447 | for(i = 0; i < c; i++) { | 458 | for(i = 0; i < c; i++) { |
| 448 | aux = new_alg(v[i]); | 459 | aux = new_alg(v[i]); |
| 449 | if (aux->len == 0) { | 460 | if (aux->len == 0) { |
| 450 | fprintf(stderr, "Error: %s unrecognized\n", v[i]); | 461 | fprintf(stderr, "Error: %s or its argument" |
| 462 | "unrecognized\n", v[i]); | ||
| 451 | free(aux); | 463 | free(aux); |
| 452 | return false; | 464 | return false; |
| 453 | } | 465 | } |
diff --git a/src/cubetypes.h b/src/cubetypes.h index 6d8af21..1b679aa 100644 --- a/src/cubetypes.h +++ b/src/cubetypes.h | |||
| @@ -279,7 +279,7 @@ solveoptions | |||
| 279 | int max_moves; | 279 | int max_moves; |
| 280 | int max_solutions; | 280 | int max_solutions; |
| 281 | int nthreads; | 281 | int nthreads; |
| 282 | bool optimal_only; | 282 | int optimal; |
| 283 | bool can_niss; | 283 | bool can_niss; |
| 284 | bool verbose; | 284 | bool verbose; |
| 285 | bool all; | 285 | bool all; |
diff --git a/src/solve.c b/src/solve.c index 931dc02..79e421d 100644 --- a/src/solve.c +++ b/src/solve.c | |||
| @@ -373,7 +373,7 @@ niss_makes_sense(DfsArg *arg) | |||
| 373 | AlgList * | 373 | AlgList * |
| 374 | solve(Cube cube, Step *step, SolveOptions *opts) | 374 | solve(Cube cube, Step *step, SolveOptions *opts) |
| 375 | { | 375 | { |
| 376 | int d; | 376 | int d, op; |
| 377 | AlgList *sols; | 377 | AlgList *sols; |
| 378 | Cube c; | 378 | Cube c; |
| 379 | 379 | ||
| @@ -396,16 +396,19 @@ solve(Cube cube, Step *step, SolveOptions *opts) | |||
| 396 | return sols; | 396 | return sols; |
| 397 | } | 397 | } |
| 398 | 398 | ||
| 399 | op = -1; | ||
| 399 | for (d = opts->min_moves; | 400 | for (d = opts->min_moves; |
| 400 | d <= opts->max_moves && | 401 | d <= opts->max_moves && |
| 401 | !(sols->len && opts->optimal_only) && | 402 | !(opts->optimal != -1 && op != -1 && opts->optimal + op < d) && |
| 402 | sols->len < opts->max_solutions; | 403 | sols->len < opts->max_solutions; |
| 403 | d++) { | 404 | d++) { |
| 404 | if (opts->verbose) | 405 | if (opts->verbose) |
| 405 | fprintf(stderr, | 406 | fprintf(stderr, |
| 406 | "Found %d solutions, searching depth %d...\n", | 407 | "Found %d solutions, searching depth %d...\n", |
| 407 | sols->len, d); | 408 | sols->len, d); |
| 408 | multidfs(c, step, opts, sols, d); | 409 | multidfs(c, step, opts, sols, d); |
| 410 | if (sols->len > 0 && op == -1) | ||
| 411 | op = d; | ||
| 409 | } | 412 | } |
| 410 | 413 | ||
| 411 | return sols; | 414 | return sols; |
