nissy-fmc

A Rubik's cube FMC assistant
git clone https://git.tronto.net/nissy-fmc
Download | Log | Files | Refs | README | LICENSE

commit ce4d6f93c8d00a56b9356d0c0d8489c28e1459df
parent 0f81a5a70be20a82ee8495f050366a28d0be21c7
Author: Sebastiano Tronto <sebastiano.tronto@gmail.com>
Date:   Sat, 25 Dec 2021 20:57:45 +0100

Added -O option for solve (specify number of moves within optimal)

Diffstat:
MTODO.md | 5++---
Mdoc/nissy.1 | 8++++++++
Mnissy | 0
Mnissy.exe | 0
Msrc/commands.c | 22+++++++++++++++++-----
Msrc/cubetypes.h | 2+-
Msrc/solve.c | 9++++++---
7 files changed, 34 insertions(+), 12 deletions(-)

diff --git a/TODO.md b/TODO.md @@ -26,11 +26,9 @@ including e.g. solutions that were not shown because -c) * solve should try up to a small bound without loading the large pruning table * **drfin for HTR scrambles should try all 3 axis and pick the best solutions; in general every step that automatically detects orientation should do this** -* **solve -O N find solutions within N moves from optimal - (-o is the same as -O 0)** ### New features -* **cleanup: translate an alg to the standard HTM moveset + reorient at the end** +* cleanup: translate an alg to the standard HTM moveset + reorient at the end * configurability: add an `alias` command, run config file at startup * configure max ram to be used (via config file and/or command line option) * transform alg, rufify etc... @@ -43,6 +41,7 @@ including e.g. solutions that were not shown because -c) * webapp (cgi) * **Re-upload tables** * **fix README.md** +* **fix examples in manpage** ## Technical stuff diff --git a/doc/nissy.1 b/doc/nissy.1 @@ -127,6 +127,14 @@ Allow use of NISS. .It Fl o Only find solutions that require the minimum number of moves. . +.It Fl O Ar N +Only find solutions that require at most +.Ar N +moves more than the optimal solution. If +.Ar N +is 0, this is equivalent to +.It Fl o +. .It Fl p Plain style: do not print the number of moves. . diff --git a/nissy b/nissy Binary files differ. diff --git a/nissy.exe b/nissy.exe Binary files differ. diff --git a/src/commands.c b/src/commands.c @@ -147,7 +147,7 @@ solve_parse_args(int c, char **v) a->opts->max_moves = 20; a->opts->max_solutions = 1; a->opts->nthreads = 1; - a->opts->optimal_only = false; + a->opts->optimal = -1; a->opts->can_niss = false; a->opts->verbose = false; a->opts->all = false; @@ -163,7 +163,7 @@ solve_parse_args(int c, char **v) if (val < 0 || val > 100) { fprintf(stderr, "Invalid min number of moves" - "(0 <= m <= 100).\n"); + "(0 <= N <= 100).\n"); return a; } a->opts->min_moves = val; @@ -172,7 +172,7 @@ solve_parse_args(int c, char **v) if (val < 0 || val > 100) { fprintf(stderr, "Invalid max number of moves" - "(0 <= M <= 100).\n"); + "(0 <= N <= 100).\n"); return a; } a->opts->max_moves = val; @@ -196,7 +196,18 @@ solve_parse_args(int c, char **v) a->opts->max_solutions = val; fixedmsols = true; } else if (!strcmp(v[i], "-o")) { - a->opts->optimal_only = true; + a->opts->optimal = 0; + infinitesols = true; + } else if (!strcmp(v[i], "-O") && i+1 < c) { + val = strtol(v[++i], NULL, 10); + if (val < 0 || val > 100 || + (val == 0 && strcmp("0", v[i]))) { + fprintf(stderr, + "Invalid max number of moves" + " (0 <= N <= 100).\n"); + return a; + } + a->opts->optimal = val; infinitesols = true; } else if (!strcmp(v[i], "-N")) { a->opts->can_niss = true; @@ -447,7 +458,8 @@ read_scramble(int c, char **v, CommandArgs *args) for(i = 0; i < c; i++) { aux = new_alg(v[i]); if (aux->len == 0) { - fprintf(stderr, "Error: %s unrecognized\n", v[i]); + fprintf(stderr, "Error: %s or its argument" + "unrecognized\n", v[i]); free(aux); return false; } diff --git a/src/cubetypes.h b/src/cubetypes.h @@ -279,7 +279,7 @@ solveoptions int max_moves; int max_solutions; int nthreads; - bool optimal_only; + int optimal; bool can_niss; bool verbose; bool all; diff --git a/src/solve.c b/src/solve.c @@ -373,7 +373,7 @@ niss_makes_sense(DfsArg *arg) AlgList * solve(Cube cube, Step *step, SolveOptions *opts) { - int d; + int d, op; AlgList *sols; Cube c; @@ -396,16 +396,19 @@ solve(Cube cube, Step *step, SolveOptions *opts) return sols; } + op = -1; for (d = opts->min_moves; d <= opts->max_moves && - !(sols->len && opts->optimal_only) && - sols->len < opts->max_solutions; + !(opts->optimal != -1 && op != -1 && opts->optimal + op < d) && + sols->len < opts->max_solutions; d++) { if (opts->verbose) fprintf(stderr, "Found %d solutions, searching depth %d...\n", sols->len, d); multidfs(c, step, opts, sols, d); + if (sols->len > 0 && op == -1) + op = d; } return sols;