diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2025-04-23 15:42:11 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2025-04-23 15:42:11 +0200 |
| commit | 9c209afd81e4c51e4fc2717c0eeff4a5d116bcb0 (patch) | |
| tree | e590922e2bd34cb802cef96c1c8d8ba935da4f75 /src | |
| parent | 039267a278bb9e0580e8aebd85ef5f3ed774688f (diff) | |
| download | nissy-core-9c209afd81e4c51e4fc2717c0eeff4a5d116bcb0.tar.gz nissy-core-9c209afd81e4c51e4fc2717c0eeff4a5d116bcb0.zip | |
Added orientation to getcube
Diffstat (limited to '')
| -rw-r--r-- | src/core/cube.h | 12 | ||||
| -rw-r--r-- | src/nissy.c | 19 | ||||
| -rw-r--r-- | src/nissy.h | 10 |
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); | |||
| 4 | STATIC bool issolvable(oriented_cube_t); | 4 | STATIC bool issolvable(oriented_cube_t); |
| 5 | STATIC bool issolved(oriented_cube_t); | 5 | STATIC bool issolved(oriented_cube_t); |
| 6 | STATIC bool iserror(oriented_cube_t); | 6 | STATIC bool iserror(oriented_cube_t); |
| 7 | STATIC void getcube_fix(long long *, long long *, long long *, long long *); | 7 | STATIC void getcube_fix(long long *, long long *, |
| 8 | long long *, long long *, long long *); | ||
| 8 | STATIC cube_t getcube(int64_t, int64_t, int64_t, int64_t); | 9 | STATIC cube_t getcube(int64_t, int64_t, int64_t, int64_t); |
| 9 | 10 | ||
| 10 | STATIC oriented_cube_t readcube(const char *); | 11 | STATIC oriented_cube_t readcube(const char *); |
| @@ -148,7 +149,13 @@ iserror(oriented_cube_t cube) | |||
| 148 | } | 149 | } |
| 149 | 150 | ||
| 150 | STATIC void | 151 | STATIC void |
| 151 | getcube_fix(long long *ep, long long *eo, long long *cp, long long *co) | 152 | getcube_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 } |
| 27 | struct { | 27 | struct { |
| 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 | ||
| 285 | long long | 288 | 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 | |||
| 200 | orientation issues, resulting always in a solvable cube. | 200 | orientation issues, resulting always in a solvable cube. |
| 201 | 201 | ||
| 202 | Parameters: | 202 | Parameters: |
| 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 | ); |
