From 9c209afd81e4c51e4fc2717c0eeff4a5d116bcb0 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Wed, 23 Apr 2025 15:42:11 +0200 Subject: Added orientation to getcube --- src/core/cube.h | 12 ++++++++++-- src/nissy.c | 19 +++++++++++-------- src/nissy.h | 10 ++++++---- 3 files changed, 27 insertions(+), 14 deletions(-) (limited to 'src') 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); STATIC bool issolvable(oriented_cube_t); STATIC bool issolved(oriented_cube_t); STATIC bool iserror(oriented_cube_t); -STATIC void getcube_fix(long long *, long long *, long long *, long long *); +STATIC void getcube_fix(long long *, long long *, + long long *, long long *, long long *); STATIC cube_t getcube(int64_t, int64_t, int64_t, int64_t); STATIC oriented_cube_t readcube(const char *); @@ -148,7 +149,13 @@ iserror(oriented_cube_t cube) } STATIC void -getcube_fix(long long *ep, long long *eo, long long *cp, long long *co) +getcube_fix( + long long *ep, + long long *eo, + long long *cp, + long long *co, + long long *orien +) { uint8_t e[12], c[8], coarr[8]; @@ -156,6 +163,7 @@ getcube_fix(long long *ep, long long *eo, long long *cp, long long *co) *eo = (*eo % POW_2_11 + POW_2_11) % POW_2_11; *cp = (*cp % FACT_8 + FACT_8) % FACT_8; *co = (*cp % POW_3_7 + POW_3_7) % POW_3_7; + *orien = (*orien % 24 + 24) % 24; indextoperm(*ep, 12, e); 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( #define GETCUBE_OPTIONS(S, F) { .option = S, .fix = F } struct { char *option; - void (*fix)(long long *, long long *, long long *, long long *); + void (*fix)(long long *, long long *, + long long *, long long *, long long *); } getcube_options[] = { GETCUBE_OPTIONS("fix", getcube_fix), GETCUBE_OPTIONS(NULL, NULL) @@ -254,12 +255,13 @@ nissy_getcube( long long eo, long long cp, long long co, + long long orient, const char *options, char result[static NISSY_SIZE_CUBE] ) { int i; - cube_t c; + oriented_cube_t oc; if (options == NULL) { LOG("[getcube] Error: 'options' argument is NULL\n"); @@ -268,18 +270,19 @@ nissy_getcube( for (i = 0; getcube_options[i].option != NULL; i++) if (!strcmp(options, getcube_options[i].option)) - getcube_options[i].fix(&ep, &eo, &cp, &co); + getcube_options[i].fix(&ep, &eo, &cp, &co, &orient); - c = getcube(ep, eo, cp, co); + oc.cube = getcube(ep, eo, cp, co); + oc.orientation = orient; - if (!isconsistent((oriented_cube_t){ .cube = c, .orientation = 0 })) { + if (!isconsistent(oc)) { LOG("[getcube] Error: could not get cube with ep=%lld, " - "eo=%lld, cp=%lld, co=%lld.\n", ep, eo, cp, co); + "eo=%lld, cp=%lld, co=%lld, orient=%lld.\n", + ep, eo, cp, co, orient); return NISSY_ERROR_OPTIONS; } -/* TODO: should support orientation */ - return write_result((oriented_cube_t){.cube = c, .orientation = 0}, result); + return write_result(oc, result); } long 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 orientation issues, resulting always in a solvable cube. Parameters: - ep - The edge permutation, 0 <= ep <= 479001600 (12!) - eo - The edge orientation, 0 <= eo <= 2047 (2^11) - cp - The corner permutation, 0 <= cp <= 40320 (8!) - co - The corner orientation, 0 <= co <= 2187 (3^7) + ep - The edge permutation, 0 <= ep < 479001600 (12!) + eo - The edge orientation, 0 <= eo < 2047 (2^11) + cp - The corner permutation, 0 <= cp < 40320 (8!) + co - The corner orientation, 0 <= co < 2187 (3^7) + orient - The orientation of the cube, 0 <= orient < 24 options - Other options. result - The return parameter for the resulting cube. @@ -218,6 +219,7 @@ nissy_getcube( long long eo, long long cp, long long co, + long long orient, const char *options, char result[static NISSY_SIZE_CUBE] ); -- cgit v1.3