aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2025-03-12 16:40:07 +0100
committerSebastiano Tronto <sebastiano@tronto.net>2025-03-12 16:40:07 +0100
commitbfb7b1ab9d2c85a256c42c006060ffe7c2652638 (patch)
tree08cada9caf1aa3c7d913c81f2f4d7f7a89c84a95
parent45eddc73d44f59d82fcf93e2213bb972c6b7c86a (diff)
downloadnissy-core-bfb7b1ab9d2c85a256c42c006060ffe7c2652638.tar.gz
nissy-core-bfb7b1ab9d2c85a256c42c006060ffe7c2652638.zip
Revert API change
Diffstat (limited to '')
-rw-r--r--TODO_COORDINATES6
-rw-r--r--python/nissy_module.c14
-rw-r--r--shell/shell.c20
-rw-r--r--src/nissy.c4
-rw-r--r--src/nissy.h4
-rw-r--r--src/solvers/coord/common.h17
-rw-r--r--src/solvers/coord/gendata.h2
-rw-r--r--src/solvers/coord/solve.h16
8 files changed, 40 insertions, 43 deletions
diff --git a/TODO_COORDINATES b/TODO_COORDINATES
index 1c50db3..78ed704 100644
--- a/TODO_COORDINATES
+++ b/TODO_COORDINATES
@@ -1,14 +1,18 @@
1- coord solver 1- coord solver
2 - return to fully qualified solver name
3 x undo chnages to API
4 - add a parameter to gendata to get a shortname (filename) for the table
2 - there is an error (try R B2 as scramble, EO on RL) 5 - there is an error (try R B2 as scramble, EO on RL)
3 - debug 6 - debug
4 - fix 7 - fix
5 - h48 solve dispatch: move "h7k2" part to "options"? 8 - h48 solve dispatch: move "h7k2" part to "options"?
6 - it makes sense, but breaks the rule "solver == table" 9 - it makes sense, but breaks the rule "solver == table"
10 - if so, adjust tools that use nissy_solve()
7 - add new parameter to solve(): options (char *) 11 - add new parameter to solve(): options (char *)
8 - fix all usages 12 - fix all usages
9 x tests 13 x tests
10 x shell 14 x shell
11 - tools (after deciding if refactoring h48 solve dispatch) 15 x tools
12 x python bindings 16 x python bindings
13 - document what to do when changing interface? 17 - document what to do when changing interface?
14 - where do I document which solvers take which parameters? 18 - where do I document which solvers take which parameters?
diff --git a/python/nissy_module.c b/python/nissy_module.c
index 6511382..29facc4 100644
--- a/python/nissy_module.c
+++ b/python/nissy_module.c
@@ -315,7 +315,6 @@ PyDoc_STRVAR(solve_doc,
315"Parameters:\n" 315"Parameters:\n"
316" - cube: a cube in B32 format\n" 316" - cube: a cube in B32 format\n"
317" - solver: the solver to use\n" 317" - solver: the solver to use\n"
318" - options: extra options for the chosen solver\n"
319" - minmoves: the minimum number of moves to use\n" 318" - minmoves: the minimum number of moves to use\n"
320" - maxmoves: the maximum number of moves to use\n" 319" - maxmoves: the maximum number of moves to use\n"
321" - maxsolution: the maximum number of solutions to return\n" 320" - maxsolution: the maximum number of solutions to return\n"
@@ -332,21 +331,20 @@ solve(PyObject *self, PyObject *args)
332 long long result; 331 long long result;
333 unsigned nissflag, minmoves, maxmoves, maxsolutions; 332 unsigned nissflag, minmoves, maxmoves, maxsolutions;
334 int optimal, i, j, k, threads; 333 int optimal, i, j, k, threads;
335 const char *cube, *solver, *options; 334 const char *cube, *solver;
336 char solutions[MAX_SOLUTIONS_SIZE]; 335 char solutions[MAX_SOLUTIONS_SIZE];
337 long long stats[NISSY_SIZE_SOLVE_STATS]; 336 long long stats[NISSY_SIZE_SOLVE_STATS];
338 PyByteArrayObject *data; 337 PyByteArrayObject *data;
339 PyObject *list, *item; 338 PyObject *list, *item;
340 339
341 if (!PyArg_ParseTuple(args, "sssIIIIiiY", &cube, &solver, &options, 340 if (!PyArg_ParseTuple(args, "ssIIIIiiY", &cube, &solver, &nissflag,
342 &nissflag, &minmoves, &maxmoves, &maxsolutions, &optimal, 341 &minmoves, &maxmoves, &maxsolutions, &optimal, &threads, &data))
343 &threads, &data))
344 return NULL; 342 return NULL;
345 343
346 Py_BEGIN_ALLOW_THREADS 344 Py_BEGIN_ALLOW_THREADS
347 result = nissy_solve(cube, solver, options, nissflag, minmoves, 345 result = nissy_solve(cube, solver, nissflag, minmoves, maxmoves,
348 maxmoves, maxsolutions, optimal, threads, data->ob_alloc, 346 maxsolutions, optimal, threads, data->ob_alloc, data->ob_bytes,
349 data->ob_bytes, MAX_SOLUTIONS_SIZE, solutions, stats); 347 MAX_SOLUTIONS_SIZE, solutions, stats);
350 Py_END_ALLOW_THREADS 348 Py_END_ALLOW_THREADS
351 349
352 if(!check_error(result)) { 350 if(!check_error(result)) {
diff --git a/shell/shell.c b/shell/shell.c
index 2853350..2a1a8cd 100644
--- a/shell/shell.c
+++ b/shell/shell.c
@@ -17,7 +17,6 @@
17#define FLAG_PERM "-perm" 17#define FLAG_PERM "-perm"
18#define FLAG_COMMAND "-command" 18#define FLAG_COMMAND "-command"
19#define FLAG_STR_CUBE "-cubestr" 19#define FLAG_STR_CUBE "-cubestr"
20#define FLAG_SOLVE_OPTS "-options"
21#define FLAG_FORMAT "-format" 20#define FLAG_FORMAT "-format"
22#define FLAG_FORMAT_IN "-fin" 21#define FLAG_FORMAT_IN "-fin"
23#define FLAG_FORMAT_OUT "-fout" 22#define FLAG_FORMAT_OUT "-fout"
@@ -45,7 +44,6 @@ typedef struct {
45 char cube_perm[22]; 44 char cube_perm[22];
46 char *str_command; 45 char *str_command;
47 char *str_cube; 46 char *str_cube;
48 char *str_options;
49 char *str_format; 47 char *str_format;
50 char *str_format_in; 48 char *str_format_in;
51 char *str_format_out; 49 char *str_format_out;
@@ -81,7 +79,6 @@ static bool set_cube(int, char **, args_t *);
81static bool set_cube_perm(int, char **, args_t *); 79static bool set_cube_perm(int, char **, args_t *);
82static bool set_str_command(int, char **, args_t *); 80static bool set_str_command(int, char **, args_t *);
83static bool set_str_cube(int, char **, args_t *); 81static bool set_str_cube(int, char **, args_t *);
84static bool set_str_options(int, char **, args_t *);
85static bool set_str_format(int, char **, args_t *); 82static bool set_str_format(int, char **, args_t *);
86static bool set_str_format_in(int, char **, args_t *); 83static bool set_str_format_in(int, char **, args_t *);
87static bool set_str_format_out(int, char **, args_t *); 84static bool set_str_format_out(int, char **, args_t *);
@@ -108,7 +105,6 @@ struct {
108 OPTION(FLAG_PERM, 1, set_cube_perm), 105 OPTION(FLAG_PERM, 1, set_cube_perm),
109 OPTION(FLAG_COMMAND, 1, set_str_command), 106 OPTION(FLAG_COMMAND, 1, set_str_command),
110 OPTION(FLAG_STR_CUBE, 1, set_str_cube), 107 OPTION(FLAG_STR_CUBE, 1, set_str_cube),
111 OPTION(FLAG_SOLVE_OPTS, 1, set_str_options),
112 OPTION(FLAG_FORMAT, 1, set_str_format), 108 OPTION(FLAG_FORMAT, 1, set_str_format),
113 OPTION(FLAG_FORMAT_IN, 1, set_str_format_in), 109 OPTION(FLAG_FORMAT_IN, 1, set_str_format_in),
114 OPTION(FLAG_FORMAT_OUT, 1, set_str_format_out), 110 OPTION(FLAG_FORMAT_OUT, 1, set_str_format_out),
@@ -201,7 +197,6 @@ struct {
201 "solve", 197 "solve",
202 "solve " FLAG_SOLVER " SOLVER" 198 "solve " FLAG_SOLVER " SOLVER"
203 "[" FLAG_MINMOVES " n] [" FLAG_MAXMOVES " N] " 199 "[" FLAG_MINMOVES " n] [" FLAG_MAXMOVES " N] "
204 "[" FLAG_SOLVE_OPTS " options] "
205 FLAG_CUBE " CUBE" 200 FLAG_CUBE " CUBE"
206 FLAG_THREADS " T", 201 FLAG_THREADS " T",
207 "Solve the given CUBE using SOLVER, " 202 "Solve the given CUBE using SOLVER, "
@@ -213,7 +208,6 @@ struct {
213 "solve_scramble", 208 "solve_scramble",
214 "solve_scramble " FLAG_SOLVER " SOLVER" 209 "solve_scramble " FLAG_SOLVER " SOLVER"
215 "[" FLAG_MINMOVES " n] [" FLAG_MAXMOVES " N] " 210 "[" FLAG_MINMOVES " n] [" FLAG_MAXMOVES " N] "
216 "[" FLAG_SOLVE_OPTS " options] "
217 FLAG_MOVES " MOVES", 211 FLAG_MOVES " MOVES",
218 "Solve the given SCRAMBLE using SOLVER, " 212 "Solve the given SCRAMBLE using SOLVER, "
219 "using at least n and at most N moves. " 213 "using at least n and at most N moves. "
@@ -485,9 +479,9 @@ solve_exec(args_t *args)
485 } 479 }
486 480
487 ret = nissy_solve( 481 ret = nissy_solve(
488 args->cube, args->str_solver, args->str_options, nissflag, 482 args->cube, args->str_solver, nissflag, args->minmoves,
489 args->minmoves, args->maxmoves, args->maxsolutions, args->optimal, 483 args->maxmoves, args->maxsolutions, args->optimal, args->threads,
490 args->threads, size, buf, SOLUTIONS_BUFFER_SIZE, solutions, stats); 484 size, buf, SOLUTIONS_BUFFER_SIZE, solutions, stats);
491 485
492 free(buf); 486 free(buf);
493 487
@@ -665,14 +659,6 @@ set_str_cube(int argc, char **argv, args_t *args)
665} 659}
666 660
667static bool 661static bool
668set_str_options(int argc, char **argv, args_t *args)
669{
670 args->str_options = argv[0];
671
672 return true;
673}
674
675static bool
676set_str_format(int argc, char **argv, args_t *args) 662set_str_format(int argc, char **argv, args_t *args)
677{ 663{
678 args->str_format = argv[0]; 664 args->str_format = argv[0];
diff --git a/src/nissy.c b/src/nissy.c
index ed1d3f4..eb483a0 100644
--- a/src/nissy.c
+++ b/src/nissy.c
@@ -503,7 +503,6 @@ long long
503nissy_solve( 503nissy_solve(
504 const char cube[static NISSY_SIZE_B32], 504 const char cube[static NISSY_SIZE_B32],
505 const char *solver, 505 const char *solver,
506 const char *options,
507 unsigned nissflag, 506 unsigned nissflag,
508 unsigned minmoves, 507 unsigned minmoves,
509 unsigned maxmoves, 508 unsigned maxmoves,
@@ -569,11 +568,10 @@ nissy_solve(
569 parse_ret = parse_h48_solver(solver, &h, &k); 568 parse_ret = parse_h48_solver(solver, &h, &k);
570 if (parse_ret != NISSY_OK) 569 if (parse_ret != NISSY_OK)
571 return parse_ret; 570 return parse_ret;
572/* TODO give warning if options is not NULL or empty? */
573 return solve_h48(c, minmoves, maxmoves, maxsols, 571 return solve_h48(c, minmoves, maxmoves, maxsols,
574 opt, t, data_size, data, sols_size, sols, stats); 572 opt, t, data_size, data, sols_size, sols, stats);
575 } else if (!strncmp(solver, "coord_", 6)) { 573 } else if (!strncmp(solver, "coord_", 6)) {
576 return solve_coord_dispatch(c, solver + 6, options, nissflag, 574 return solve_coord_dispatch(c, solver + 6, nissflag,
577 minmoves, maxmoves, maxsols, opt, t, data_size, data, 575 minmoves, maxmoves, maxsols, opt, t, data_size, data,
578 sols_size, sols); 576 sols_size, sols);
579 } else { 577 } else {
diff --git a/src/nissy.h b/src/nissy.h
index 9c26292..6c5a3e6 100644
--- a/src/nissy.h
+++ b/src/nissy.h
@@ -257,9 +257,6 @@ Solve the given cube using the given solver and options.
257Parameters: 257Parameters:
258 cube - The cube to solver, in B32 format. 258 cube - The cube to solver, in B32 format.
259 solver - The name of the solver. 259 solver - The name of the solver.
260 options - Extra options for the solver. Some solver require additional
261 parameters, some do not. For example, a coordinate solver
262 may require an "axis" (UD, FB, RL) as a parameter.
263 nissflag - The flags for NISS (linear, inverse, mixed, or combinations). 260 nissflag - The flags for NISS (linear, inverse, mixed, or combinations).
264 minmoves - The minimum number of moves for a solution. 261 minmoves - The minimum number of moves for a solution.
265 maxmoves - The maximum number of moves for a solution. 262 maxmoves - The maximum number of moves for a solution.
@@ -293,7 +290,6 @@ long long
293nissy_solve( 290nissy_solve(
294 const char cube[static NISSY_SIZE_B32], 291 const char cube[static NISSY_SIZE_B32],
295 const char *solver, 292 const char *solver,
296 const char *options,
297 unsigned nissflag, 293 unsigned nissflag,
298 unsigned minmoves, 294 unsigned minmoves,
299 unsigned maxmoves, 295 unsigned maxmoves,
diff --git a/src/solvers/coord/common.h b/src/solvers/coord/common.h
index d827665..f21a903 100644
--- a/src/solvers/coord/common.h
+++ b/src/solvers/coord/common.h
@@ -6,6 +6,7 @@ coord_t *all_coordinates[] = {
6STATIC void append_coord_name(const coord_t *, char *); 6STATIC void append_coord_name(const coord_t *, char *);
7STATIC coord_t *parse_coord(const char *, int); 7STATIC coord_t *parse_coord(const char *, int);
8STATIC uint8_t parse_axis(const char *, int); 8STATIC uint8_t parse_axis(const char *, int);
9STATIC void parse_coord_and_axis(const char *, int, coord_t **, uint8_t *);
9 10
10STATIC void 11STATIC void
11append_coord_name(const coord_t *coord, char *str) 12append_coord_name(const coord_t *coord, char *str)
@@ -44,3 +45,19 @@ parse_axis(const char *axis, int n)
44 45
45 return UINT8_ERROR; 46 return UINT8_ERROR;
46} 47}
48
49STATIC void
50parse_coord_and_axis(const char *str, int n, coord_t **coord, uint8_t *axis)
51{
52 int i;
53
54 for (i = 0; i < n; i++)
55 if (str[i] == '_')
56 break;
57
58 if (coord != NULL)
59 *coord = parse_coord(str, i);
60
61 if (axis != NULL)
62 *axis = i == n ? UINT8_ERROR : parse_axis(str+i+1, n-i-1);
63}
diff --git a/src/solvers/coord/gendata.h b/src/solvers/coord/gendata.h
index d366466..9512b93 100644
--- a/src/solvers/coord/gendata.h
+++ b/src/solvers/coord/gendata.h
@@ -9,7 +9,7 @@ gendata_coord_dispatch(const char *coordstr, void *buf)
9{ 9{
10 coord_t *coord; 10 coord_t *coord;
11 11
12 coord = parse_coord(coordstr, strlen(coordstr)); 12 parse_coord_and_axis(coordstr, strlen(coordstr), &coord, NULL);
13 13
14 if (coord == NULL) { 14 if (coord == NULL) {
15 LOG("Could not parse coordinate '%s'\n", coord); 15 LOG("Could not parse coordinate '%s'\n", coord);
diff --git a/src/solvers/coord/solve.h b/src/solvers/coord/solve.h
index 190ac1f..75c6a4e 100644
--- a/src/solvers/coord/solve.h
+++ b/src/solvers/coord/solve.h
@@ -20,9 +20,8 @@ typedef struct {
20 20
21STATIC int64_t solve_coord(cube_t, coord_t *, uint8_t, uint8_t, uint8_t, 21STATIC int64_t solve_coord(cube_t, coord_t *, uint8_t, uint8_t, uint8_t,
22 uint8_t, uint64_t, int, int, uint64_t, const void *, uint64_t, char *); 22 uint8_t, uint64_t, int, int, uint64_t, const void *, uint64_t, char *);
23STATIC int64_t solve_coord_dispatch(cube_t, const char *, const char *, 23STATIC int64_t solve_coord_dispatch(cube_t, const char *, uint8_t, uint8_t,
24 uint8_t, uint8_t, uint8_t, uint64_t, int, int, uint64_t, const void *, 24 uint8_t, uint64_t, int, int, uint64_t, const void *, uint64_t, char *);
25 uint64_t, char *);
26STATIC bool solve_coord_appendchar(char *, uint64_t, uint64_t *, char); 25STATIC bool solve_coord_appendchar(char *, uint64_t, uint64_t *, char);
27STATIC int64_t solve_coord_appendsolution(dfsarg_solve_coord_t *); 26STATIC int64_t solve_coord_appendsolution(dfsarg_solve_coord_t *);
28STATIC int64_t solve_coord_dfs(dfsarg_solve_coord_t *); 27STATIC int64_t solve_coord_dfs(dfsarg_solve_coord_t *);
@@ -123,8 +122,7 @@ solve_coord_dfs(dfsarg_solve_coord_t *arg)
123STATIC int64_t 122STATIC int64_t
124solve_coord_dispatch( 123solve_coord_dispatch(
125 cube_t cube, 124 cube_t cube,
126 const char *coordstr, 125 const char *coord_and_axis,
127 const char *options,
128 uint8_t nissflag, 126 uint8_t nissflag,
129 uint8_t minmoves, 127 uint8_t minmoves,
130 uint8_t maxmoves, 128 uint8_t maxmoves,
@@ -140,16 +138,16 @@ solve_coord_dispatch(
140 coord_t *coord; 138 coord_t *coord;
141 uint8_t axis; 139 uint8_t axis;
142 140
143 coord = parse_coord(coordstr, strlen(coordstr)); 141 parse_coord_and_axis(
144 axis = parse_axis(options, strlen(options)); 142 coord_and_axis, strlen(coord_and_axis), &coord, &axis);
145 143
146 if (coord == NULL) { 144 if (coord == NULL) {
147 LOG("Could not parse coordinate '%s'\n", coordstr); 145 LOG("Could not parse coordinate from '%s'\n", coord_and_axis);
148 return NISSY_ERROR_INVALID_SOLVER; 146 return NISSY_ERROR_INVALID_SOLVER;
149 } 147 }
150 148
151 if (axis == UINT8_ERROR) { 149 if (axis == UINT8_ERROR) {
152 LOG("Could not parse axis from options '%s'\n", options); 150 LOG("Could not parse axis from '%s'\n", coord_and_axis);
153 return NISSY_ERROR_INVALID_SOLVER; 151 return NISSY_ERROR_INVALID_SOLVER;
154 } 152 }
155 153

Generated with cgit - Back to sebastiano.tronto.net