aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2024-08-26 15:35:09 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2024-08-26 15:35:09 +0200
commitf2907e471b3caddc5844bc6994e1cbd249019747 (patch)
tree36669614893b38a7b10535720841cac74094838e
parent25c16cc4350a659ede2a2503c4c5be36264e853d (diff)
downloadnissy-core-f2907e471b3caddc5844bc6994e1cbd249019747.tar.gz
nissy-core-f2907e471b3caddc5844bc6994e1cbd249019747.zip
Fixed bug in run solve
Diffstat (limited to '')
-rw-r--r--shell.c6
-rw-r--r--src/nissy.c12
2 files changed, 13 insertions, 5 deletions
diff --git a/shell.c b/shell.c
index c1efcbd..66b1444 100644
--- a/shell.c
+++ b/shell.c
@@ -183,21 +183,21 @@ struct {
183 ), 183 ),
184 COMMAND( 184 COMMAND(
185 "datasize", 185 "datasize",
186 "datasize" _flag_solver " SOLVER " _flag_options " OPTIONS", 186 "datasize " _flag_solver " SOLVER " _flag_options " OPTIONS",
187 "Return the size in bytes of the data table used by " 187 "Return the size in bytes of the data table used by "
188 "SOLVER when called with the given OPTIONS.", 188 "SOLVER when called with the given OPTIONS.",
189 datasize_exec 189 datasize_exec
190 ), 190 ),
191 COMMAND( 191 COMMAND(
192 "gendata", 192 "gendata",
193 "gendata" _flag_solver " SOLVER " _flag_options " OPTIONS", 193 "gendata " _flag_solver " SOLVER " _flag_options " OPTIONS",
194 "Generate the data table used by " 194 "Generate the data table used by "
195 "SOLVER when called with the given OPTIONS.", 195 "SOLVER when called with the given OPTIONS.",
196 gendata_exec 196 gendata_exec
197 ), 197 ),
198 COMMAND( 198 COMMAND(
199 "solve", 199 "solve",
200 "solve" _flag_solver " SOLVER " _flag_options " OPTIONS " 200 "solve " _flag_solver " SOLVER " _flag_options " OPTIONS "
201 "[" _flag_minmoves " n] [" _flag_maxmoves " N] " 201 "[" _flag_minmoves " n] [" _flag_maxmoves " N] "
202 _flag_cube " CUBE", 202 _flag_cube " CUBE",
203 "Solve the given CUBE using SOLVER with the given OPTIONS, " 203 "Solve the given CUBE using SOLVER with the given OPTIONS, "
diff --git a/src/nissy.c b/src/nissy.c
index 5641dd9..f8c1f4d 100644
--- a/src/nissy.c
+++ b/src/nissy.c
@@ -26,23 +26,31 @@ struct {
26_static int 26_static int
27parse_h48_options(const char *buf, uint8_t *h, uint8_t *k, uint8_t *maxdepth) 27parse_h48_options(const char *buf, uint8_t *h, uint8_t *k, uint8_t *maxdepth)
28{ 28{
29 bool h_valid, k_valid, maxdepth_valid;
29 int i; 30 int i;
30 31
31 /* TODO temporarily, options are in the form "h;k;maxdepth" */ 32 /* TODO temporarily, options are in the form "h;k;maxdepth" */
32 if (h != NULL) 33 if (h != NULL)
33 *h = atoi(buf); 34 *h = atoi(buf);
35 h_valid = h == NULL || *h <= 11;
36
34 for (i = 0; buf[i] != ';'; i++) 37 for (i = 0; buf[i] != ';'; i++)
35 if (buf[i] == 0) 38 if (buf[i] == 0)
36 goto parse_h48_options_error; 39 goto parse_h48_options_error;
40
37 if (k != NULL) 41 if (k != NULL)
38 *k = atoi(&buf[i+1]); 42 *k = atoi(&buf[i+1]);
43 k_valid = k == NULL || (*k == 2 || *k == 4);
44
39 for (i = i+1; buf[i] != ';'; i++) 45 for (i = i+1; buf[i] != ';'; i++)
40 if (buf[i] == 0) 46 if (buf[i] == 0)
41 goto parse_h48_options_error; 47 goto parse_h48_options_error;
48
42 if (maxdepth != NULL) 49 if (maxdepth != NULL)
43 *maxdepth = atoi(&buf[i+1]); 50 *maxdepth = atoi(&buf[i+1]);
51 maxdepth_valid = maxdepth == NULL || *maxdepth <= 20;
44 52
45 return (*h <= 11 && (*k == 2 || *k == 4) && *maxdepth <= 20) ? 0 : 1; 53 return h_valid && k_valid && maxdepth_valid ? 0 : 1;
46 54
47parse_h48_options_error: 55parse_h48_options_error:
48 *h = 0; 56 *h = 0;
@@ -202,7 +210,7 @@ nissy_gendata(
202 if (!strcmp(solver, "h48")) { 210 if (!strcmp(solver, "h48")) {
203 p = parse_h48_options(options, &arg.h, &arg.k, &arg.maxdepth); 211 p = parse_h48_options(options, &arg.h, &arg.k, &arg.maxdepth);
204 if (p != 0) { 212 if (p != 0) {
205 LOG("gendata: ould not parse options\n"); 213 LOG("gendata: could not parse options\n");
206 ret = -1; 214 ret = -1;
207 } else { 215 } else {
208 ret = gendata_h48(&arg); 216 ret = gendata_h48(&arg);

Generated with cgit - Back to sebastiano.tronto.net