aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cube.h14
-rw-r--r--src/cube_public.h91
-rw-r--r--src/solve_generic.h98
3 files changed, 64 insertions, 139 deletions
diff --git a/src/cube.h b/src/cube.h
index 30016fd..b5eb615 100644
--- a/src/cube.h
+++ b/src/cube.h
@@ -34,19 +34,7 @@ int64_t nissy_frommoves(
34 char result[static 22] 34 char result[static 22]
35); 35);
36 36
37int64_t nissy_readcube( 37int64_t nissy_convert(
38 const char *format,
39 const char *cube_string,
40 char result[static 22]
41);
42
43int64_t nissy_writecube(
44 const char *format,
45 const char cube[static 22],
46 char *result
47);
48
49int64_t nissy_convertcube(
50 const char *format_in, 38 const char *format_in,
51 const char *format_out, 39 const char *format_out,
52 const char *cube_string, 40 const char *cube_string,
diff --git a/src/cube_public.h b/src/cube_public.h
index 69809d7..ea1d28d 100644
--- a/src/cube_public.h
+++ b/src/cube_public.h
@@ -89,20 +89,6 @@ nissy_frommoves(
89} 89}
90 90
91int64_t 91int64_t
92nissy_readcube(
93 const char *format,
94 const char *cube_string,
95 char result[static 22]
96)
97{
98 cube_t res;
99
100 res = readcube(format, cube_string);
101
102 return write_result(res, result);
103}
104
105int64_t
106nissy_convertcube( 92nissy_convertcube(
107 const char *format_in, 93 const char *format_in,
108 const char *format_out, 94 const char *format_out,
@@ -119,16 +105,6 @@ nissy_convertcube(
119} 105}
120 106
121int64_t 107int64_t
122nissy_writecube(
123 const char *format,
124 const char cube[static 22],
125 char *result
126)
127{
128 return nissy_convertcube("B32", format, cube, result);
129}
130
131int64_t
132nissy_datasize( 108nissy_datasize(
133 const char *solver, 109 const char *solver,
134 const char *options 110 const char *options
@@ -145,8 +121,22 @@ nissy_gendata(
145 void *data 121 void *data
146) 122)
147{ 123{
148 /* TODO: move gendata here? */ 124 int64_t ret;
149 return gendata(solver, options, data); 125 uint8_t maxdepth, h, i, j;
126
127 if (!strcmp(solver, "H48")) {
128 /* options are in the form "h;maxdepth" */
129 for (i = 0; options[i] != ';'; i++) ;
130 for (j = i; options[j]; j++) ;
131 h = atoi(options);
132 maxdepth = atoi(&options[i+1]);
133 ret = gendata_h48(data, h, maxdepth);
134 } else {
135 LOG("gendata: implemented only for H48 solver\n");
136 ret = -1;
137 }
138
139 return ret;
150} 140}
151 141
152int64_t 142int64_t
@@ -163,8 +153,53 @@ nissy_solve(
163 char *solutions 153 char *solutions
164) 154)
165{ 155{
166 /* TODO: move solve_generic here? */ 156 cube_t c;
167 return -1; 157 int64_t ret;
158
159 c = readcube_B32(cube);
160
161 if (!issolvable(c)) {
162 LOG("solve: cube is not solvable\n");
163 return -1;
164 }
165
166 if (minmoves < 0) {
167 LOG("solve: 'minmoves' is negative, setting it to 0\n");
168 minmoves = 0;
169 }
170
171 if (maxmoves < 0) {
172 LOG("solve: 'maxmoves' is negative, setting it to 20\n");
173 maxmoves = 20;
174 }
175
176 if (maxsolutions < 0) {
177 LOG("solve: 'maxsols' is negative, stopping\n");
178 return -1;
179 }
180
181 if (maxsolutions == 0) {
182 LOG("solve: 'maxsols' is 0, returning no solution\n");
183 return 0;
184 }
185
186 if (solutions == NULL) {
187 LOG("solve: return parameter 'solutions' is NULL, stopping\n");
188 return -1;
189 }
190
191 if (!strcmp(solver, "h48")) {
192 LOG("h48 solver not implemented yet\n");
193 ret = -1;
194 } else if (!strcmp(solver, "simple")) {
195 ret = solve_simple(
196 c, minmoves, maxmoves, maxsolutions, optimal, solutions);
197 } else {
198 LOG("solve: unknown solver '%s'\n", solver);
199 ret = -1;
200 }
201
202 return ret;
168} 203}
169 204
170void 205void
diff --git a/src/solve_generic.h b/src/solve_generic.h
index 6a1dcf3..d1d1469 100644
--- a/src/solve_generic.h
+++ b/src/solve_generic.h
@@ -16,47 +16,6 @@ _static int64_t solve_generic(cube_t, const char *, int8_t, int8_t, int64_t,
16_static uint8_t estimate_simple(cube_t); 16_static uint8_t estimate_simple(cube_t);
17_static int64_t solve_simple(cube_t, int8_t, int8_t, int64_t, int8_t, char *); 17_static int64_t solve_simple(cube_t, int8_t, int8_t, int64_t, int8_t, char *);
18 18
19int64_t
20solve(
21 cube_t cube,
22 const char *solver,
23 const char *options,
24 const char *nisstype,
25 int8_t minmoves,
26 int8_t maxmoves,
27 int64_t maxsols,
28 int8_t optimal,
29 const void *data,
30 char *solutions
31)
32{
33 DBG_WARN(!strcmp(options, ""),
34 "solve: 'options' not implemented yet, ignoring\n");
35
36 DBG_WARN(!strcmp(nisstype, ""),
37 "solve: NISS not implemented yet, ignoring 'nisstype'\n");
38
39 DBG_WARN(data == NULL,
40 "solve: 'data' not implemented yet, ignoring\n");
41
42 if (!strcmp(solver, "optimal") || !strcmp(solver, "simple")) {
43 return solve_simple(
44 cube,
45 minmoves,
46 maxmoves,
47 maxsols,
48 optimal,
49 solutions
50 );
51 } else {
52 LOG("solve: unknown solver '%s'\n", solver);
53 return -1;
54 }
55
56 LOG("solve: error\n");
57 return -1;
58}
59
60_static void 19_static void
61solve_generic_appendsolution(dfsarg_generic_t *arg) 20solve_generic_appendsolution(dfsarg_generic_t *arg)
62{ 21{
@@ -125,11 +84,6 @@ solve_generic(
125 dfsarg_generic_t arg; 84 dfsarg_generic_t arg;
126 int64_t ret, tmp, first; 85 int64_t ret, tmp, first;
127 86
128 if (!issolvable(cube)) {
129 LOG("solve: cube is not solvable\n");
130 return -1;
131 }
132
133 if (issolved(cube)) { 87 if (issolved(cube)) {
134 LOG("solve: cube is already solved\n"); 88 LOG("solve: cube is already solved\n");
135 sols[0] = '\n'; 89 sols[0] = '\n';
@@ -137,34 +91,6 @@ solve_generic(
137 return 1; 91 return 1;
138 } 92 }
139 93
140 DBG_WARN(!strcmp(nisstype, ""),
141 "solve: NISS not implemented yet, 'nisstype' ignored\n");
142
143 if (minmoves < 0) {
144 LOG("solve: 'minmoves' is negative, setting to 0\n");
145 minmoves = 0;
146 }
147
148 if (maxmoves < 0) {
149 LOG("solve: invalid 'maxmoves', setting to 20\n");
150 maxmoves = 20;
151 }
152
153 if (maxsols < 0) {
154 LOG("solve: 'maxsols' is negative\n");
155 return -1;
156 }
157
158 if (maxsols == 0) {
159 LOG("solve: 'maxsols' is 0\n");
160 return 0;
161 }
162
163 if (sols == NULL) {
164 LOG("solve: return parameter 'sols' is NULL\n");
165 return -1;
166 }
167
168 if (estimate == NULL) { 94 if (estimate == NULL) {
169 LOG("solve: 'estimate' is NULL\n"); 95 LOG("solve: 'estimate' is NULL\n");
170 return -1; 96 return -1;
@@ -230,27 +156,3 @@ solve_simple(
230 &estimate_simple 156 &estimate_simple
231 ); 157 );
232} 158}
233
234int64_t
235gendata(const char *solver, const char *options, void *data)
236{
237 int64_t ret;
238 uint8_t maxdepth, h, i, j;
239
240 if (!strcmp(solver, "H48")) {
241 /*
242 TODO: write a generic parser for options
243 for now it accepts "h;maxdepth"
244 */
245 for (i = 0; options[i] != ';'; i++) ;
246 for (j = i; options[j]; j++) ;
247 h = atoi(options);
248 maxdepth = atoi(&options[i+1]);
249 ret = gendata_h48(data, h, maxdepth);
250 } else {
251 LOG("gendata: implemented only for H48 solver\n");
252 ret = -1;
253 }
254
255 return ret;
256}

Generated with cgit - Back to sebastiano.tronto.net