aboutsummaryrefslogtreecommitdiff
path: root/src/nissy.c
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2024-08-25 14:35:45 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2024-08-25 14:35:45 +0200
commitcdf311166da0171c2787fb1745072cd14569ff4f (patch)
tree82db218e948bff91c1dc57a7ac25d8b5d944ec12 /src/nissy.c
parentdd44adceed44bec3dc313b77ec6f69123dc59016 (diff)
downloadnissy-core-cdf311166da0171c2787fb1745072cd14569ff4f.tar.gz
nissy-core-cdf311166da0171c2787fb1745072cd14569ff4f.zip
Refactor table generation
Diffstat (limited to 'src/nissy.c')
-rw-r--r--src/nissy.c63
1 files changed, 49 insertions, 14 deletions
diff --git a/src/nissy.c b/src/nissy.c
index fac7a20..5641dd9 100644
--- a/src/nissy.c
+++ b/src/nissy.c
@@ -10,6 +10,7 @@
10 10
11#include "nissy.h" 11#include "nissy.h"
12 12
13_static int parse_h48_options(const char *, uint8_t *, uint8_t *, uint8_t *);
13_static int64_t write_result(cube_t, char [static 22]); 14_static int64_t write_result(cube_t, char [static 22]);
14 15
15/* TODO: add option to get DR, maybe C-only, E-only, eo... */ 16/* TODO: add option to get DR, maybe C-only, E-only, eo... */
@@ -22,6 +23,36 @@ struct {
22 GETCUBE_OPTIONS(NULL, NULL) 23 GETCUBE_OPTIONS(NULL, NULL)
23}; 24};
24 25
26_static int
27parse_h48_options(const char *buf, uint8_t *h, uint8_t *k, uint8_t *maxdepth)
28{
29 int i;
30
31 /* TODO temporarily, options are in the form "h;k;maxdepth" */
32 if (h != NULL)
33 *h = atoi(buf);
34 for (i = 0; buf[i] != ';'; i++)
35 if (buf[i] == 0)
36 goto parse_h48_options_error;
37 if (k != NULL)
38 *k = atoi(&buf[i+1]);
39 for (i = i+1; buf[i] != ';'; i++)
40 if (buf[i] == 0)
41 goto parse_h48_options_error;
42 if (maxdepth != NULL)
43 *maxdepth = atoi(&buf[i+1]);
44
45 return (*h <= 11 && (*k == 2 || *k == 4) && *maxdepth <= 20) ? 0 : 1;
46
47parse_h48_options_error:
48 *h = 0;
49 *k = 0;
50 *maxdepth = 0;
51 LOG("Error parsing options: must be in \"h;k;maxdepth\" format "
52 " (instead it was \"%s\")\n", buf);
53 return -1;
54}
55
25_static int64_t 56_static int64_t
26write_result(cube_t cube, char result[static 22]) 57write_result(cube_t cube, char result[static 22])
27{ 58{
@@ -163,19 +194,19 @@ nissy_gendata(
163 void *data 194 void *data
164) 195)
165{ 196{
197 int p;
166 int64_t ret; 198 int64_t ret;
167 uint8_t i;
168 gendata_h48_arg_t arg; 199 gendata_h48_arg_t arg;
169 200
170 arg.buf = data; 201 arg.buf = data;
171 if (!strcmp(solver, "h48")) { 202 if (!strcmp(solver, "h48")) {
172 /* options are in the form "h;k;maxdepth" */ 203 p = parse_h48_options(options, &arg.h, &arg.k, &arg.maxdepth);
173 arg.h = atoi(options); 204 if (p != 0) {
174 for (i = 0; options[i] != ';'; i++) ; 205 LOG("gendata: ould not parse options\n");
175 arg.k = atoi(&options[i+1]); 206 ret = -1;
176 for (i = i+1; options[i] != ';'; i++) ; 207 } else {
177 arg.maxdepth = atoi(&options[i+1]); 208 ret = gendata_h48(&arg);
178 ret = gendata_h48(&arg); 209 }
179 } else if (!strcmp(solver, "h48stats")) { 210 } else if (!strcmp(solver, "h48stats")) {
180 arg.h = 0; 211 arg.h = 0;
181 arg.k = 4; 212 arg.k = 4;
@@ -204,8 +235,9 @@ nissy_solve(
204) 235)
205{ 236{
206 cube_t c; 237 cube_t c;
238 int p;
207 int64_t ret; 239 int64_t ret;
208 int h; 240 uint8_t h, k;
209 241
210 c = readcube_B32(cube); 242 c = readcube_B32(cube);
211 243
@@ -241,11 +273,14 @@ nissy_solve(
241 273
242 /* TODO define and use solve_options_t */ 274 /* TODO define and use solve_options_t */
243 if (!strcmp(solver, "h48")) { 275 if (!strcmp(solver, "h48")) {
244 h = atoi(options); /* TODO: better parsing */ 276 p = parse_h48_options(options, &h, &k, NULL);
245 ret = solve_h48( 277 if (p != 0) {
246 c, minmoves, maxmoves, maxsolutions, 278 LOG("gendata: could not parse options\n");
247 (uint8_t)h, data, solutions); 279 ret = -1;
248 ret = -1; 280 } else {
281 ret = solve_h48(c, minmoves, maxmoves, maxsolutions,
282 h, k, data, solutions);
283 }
249 } else if (!strcmp(solver, "h48stats")) { 284 } else if (!strcmp(solver, "h48stats")) {
250 ret = solve_h48stats(c, maxmoves, data, solutions); 285 ret = solve_h48stats(c, maxmoves, data, solutions);
251 } else if (!strcmp(solver, "simple")) { 286 } else if (!strcmp(solver, "simple")) {

Generated with cgit - Back to sebastiano.tronto.net