aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2025-04-23 15:42:11 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2025-04-23 15:42:11 +0200
commit9c209afd81e4c51e4fc2717c0eeff4a5d116bcb0 (patch)
treee590922e2bd34cb802cef96c1c8d8ba935da4f75 /src
parent039267a278bb9e0580e8aebd85ef5f3ed774688f (diff)
downloadnissy-core-9c209afd81e4c51e4fc2717c0eeff4a5d116bcb0.tar.gz
nissy-core-9c209afd81e4c51e4fc2717c0eeff4a5d116bcb0.zip
Added orientation to getcube
Diffstat (limited to 'src')
-rw-r--r--src/core/cube.h12
-rw-r--r--src/nissy.c19
-rw-r--r--src/nissy.h10
3 files changed, 27 insertions, 14 deletions
diff --git a/src/core/cube.h b/src/core/cube.h
index 91bb284..88e1ca9 100644
--- a/src/core/cube.h
+++ b/src/core/cube.h
@@ -4,7 +4,8 @@ STATIC bool isconsistent(oriented_cube_t);
4STATIC bool issolvable(oriented_cube_t); 4STATIC bool issolvable(oriented_cube_t);
5STATIC bool issolved(oriented_cube_t); 5STATIC bool issolved(oriented_cube_t);
6STATIC bool iserror(oriented_cube_t); 6STATIC bool iserror(oriented_cube_t);
7STATIC void getcube_fix(long long *, long long *, long long *, long long *); 7STATIC void getcube_fix(long long *, long long *,
8 long long *, long long *, long long *);
8STATIC cube_t getcube(int64_t, int64_t, int64_t, int64_t); 9STATIC cube_t getcube(int64_t, int64_t, int64_t, int64_t);
9 10
10STATIC oriented_cube_t readcube(const char *); 11STATIC oriented_cube_t readcube(const char *);
@@ -148,7 +149,13 @@ iserror(oriented_cube_t cube)
148} 149}
149 150
150STATIC void 151STATIC void
151getcube_fix(long long *ep, long long *eo, long long *cp, long long *co) 152getcube_fix(
153 long long *ep,
154 long long *eo,
155 long long *cp,
156 long long *co,
157 long long *orien
158)
152{ 159{
153 uint8_t e[12], c[8], coarr[8]; 160 uint8_t e[12], c[8], coarr[8];
154 161
@@ -156,6 +163,7 @@ getcube_fix(long long *ep, long long *eo, long long *cp, long long *co)
156 *eo = (*eo % POW_2_11 + POW_2_11) % POW_2_11; 163 *eo = (*eo % POW_2_11 + POW_2_11) % POW_2_11;
157 *cp = (*cp % FACT_8 + FACT_8) % FACT_8; 164 *cp = (*cp % FACT_8 + FACT_8) % FACT_8;
158 *co = (*cp % POW_3_7 + POW_3_7) % POW_3_7; 165 *co = (*cp % POW_3_7 + POW_3_7) % POW_3_7;
166 *orien = (*orien % 24 + 24) % 24;
159 167
160 indextoperm(*ep, 12, e); 168 indextoperm(*ep, 12, e);
161 indextoperm(*cp, 8, c); 169 indextoperm(*cp, 8, c);
diff --git a/src/nissy.c b/src/nissy.c
index f1d4cd1..2dd5a41 100644
--- a/src/nissy.c
+++ b/src/nissy.c
@@ -26,7 +26,8 @@ STATIC long long nissy_gendata_unsafe(
26#define GETCUBE_OPTIONS(S, F) { .option = S, .fix = F } 26#define GETCUBE_OPTIONS(S, F) { .option = S, .fix = F }
27struct { 27struct {
28 char *option; 28 char *option;
29 void (*fix)(long long *, long long *, long long *, long long *); 29 void (*fix)(long long *, long long *,
30 long long *, long long *, long long *);
30} getcube_options[] = { 31} getcube_options[] = {
31 GETCUBE_OPTIONS("fix", getcube_fix), 32 GETCUBE_OPTIONS("fix", getcube_fix),
32 GETCUBE_OPTIONS(NULL, NULL) 33 GETCUBE_OPTIONS(NULL, NULL)
@@ -254,12 +255,13 @@ nissy_getcube(
254 long long eo, 255 long long eo,
255 long long cp, 256 long long cp,
256 long long co, 257 long long co,
258 long long orient,
257 const char *options, 259 const char *options,
258 char result[static NISSY_SIZE_CUBE] 260 char result[static NISSY_SIZE_CUBE]
259) 261)
260{ 262{
261 int i; 263 int i;
262 cube_t c; 264 oriented_cube_t oc;
263 265
264 if (options == NULL) { 266 if (options == NULL) {
265 LOG("[getcube] Error: 'options' argument is NULL\n"); 267 LOG("[getcube] Error: 'options' argument is NULL\n");
@@ -268,18 +270,19 @@ nissy_getcube(
268 270
269 for (i = 0; getcube_options[i].option != NULL; i++) 271 for (i = 0; getcube_options[i].option != NULL; i++)
270 if (!strcmp(options, getcube_options[i].option)) 272 if (!strcmp(options, getcube_options[i].option))
271 getcube_options[i].fix(&ep, &eo, &cp, &co); 273 getcube_options[i].fix(&ep, &eo, &cp, &co, &orient);
272 274
273 c = getcube(ep, eo, cp, co); 275 oc.cube = getcube(ep, eo, cp, co);
276 oc.orientation = orient;
274 277
275 if (!isconsistent((oriented_cube_t){ .cube = c, .orientation = 0 })) { 278 if (!isconsistent(oc)) {
276 LOG("[getcube] Error: could not get cube with ep=%lld, " 279 LOG("[getcube] Error: could not get cube with ep=%lld, "
277 "eo=%lld, cp=%lld, co=%lld.\n", ep, eo, cp, co); 280 "eo=%lld, cp=%lld, co=%lld, orient=%lld.\n",
281 ep, eo, cp, co, orient);
278 return NISSY_ERROR_OPTIONS; 282 return NISSY_ERROR_OPTIONS;
279 } 283 }
280 284
281/* TODO: should support orientation */ 285 return write_result(oc, result);
282 return write_result((oriented_cube_t){.cube = c, .orientation = 0}, result);
283} 286}
284 287
285long long 288long long
diff --git a/src/nissy.h b/src/nissy.h
index 734487d..c827275 100644
--- a/src/nissy.h
+++ b/src/nissy.h
@@ -200,10 +200,11 @@ range will be adjusted before using it. The option "fix" also fixes parity and
200orientation issues, resulting always in a solvable cube. 200orientation issues, resulting always in a solvable cube.
201 201
202Parameters: 202Parameters:
203 ep - The edge permutation, 0 <= ep <= 479001600 (12!) 203 ep - The edge permutation, 0 <= ep < 479001600 (12!)
204 eo - The edge orientation, 0 <= eo <= 2047 (2^11) 204 eo - The edge orientation, 0 <= eo < 2047 (2^11)
205 cp - The corner permutation, 0 <= cp <= 40320 (8!) 205 cp - The corner permutation, 0 <= cp < 40320 (8!)
206 co - The corner orientation, 0 <= co <= 2187 (3^7) 206 co - The corner orientation, 0 <= co < 2187 (3^7)
207 orient - The orientation of the cube, 0 <= orient < 24
207 options - Other options. 208 options - Other options.
208 result - The return parameter for the resulting cube. 209 result - The return parameter for the resulting cube.
209 210
@@ -218,6 +219,7 @@ nissy_getcube(
218 long long eo, 219 long long eo,
219 long long cp, 220 long long cp,
220 long long co, 221 long long co,
222 long long orient,
221 const char *options, 223 const char *options,
222 char result[static NISSY_SIZE_CUBE] 224 char result[static NISSY_SIZE_CUBE]
223); 225);

Generated with cgit - Back to sebastiano.tronto.net