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 | |
| parent | 039267a278bb9e0580e8aebd85ef5f3ed774688f (diff) | |
| download | nissy-core-9c209afd81e4c51e4fc2717c0eeff4a5d116bcb0.tar.gz nissy-core-9c209afd81e4c51e4fc2717c0eeff4a5d116bcb0.zip | |
Added orientation to getcube
Diffstat (limited to '')
| -rw-r--r-- | Makefile | 5 | ||||
| -rw-r--r-- | cpp/nissy.cpp | 13 | ||||
| -rw-r--r-- | cpp/nissy.h | 8 | ||||
| -rw-r--r-- | python/nissy_module.c | 10 | ||||
| -rw-r--r-- | shell/shell.c | 2 | ||||
| -rw-r--r-- | src/core/cube.h | 12 | ||||
| -rw-r--r-- | src/nissy.c | 19 | ||||
| -rw-r--r-- | src/nissy.h | 10 |
8 files changed, 46 insertions, 33 deletions
| @@ -42,9 +42,6 @@ debugshell: debugnissy.o | |||
| 42 | mkdir -p tables | 42 | mkdir -p tables |
| 43 | ${CC} ${MACROS} ${DBGFLAGS} -o debugrun debugnissy.o shell/shell.c | 43 | ${CC} ${MACROS} ${DBGFLAGS} -o debugrun debugnissy.o shell/shell.c |
| 44 | 44 | ||
| 45 | shelltest: debugshell | ||
| 46 | ./shell/test.sh | ||
| 47 | |||
| 48 | python: nissy.o | 45 | python: nissy.o |
| 49 | ${CC} ${CFLAGS} -shared ${PYTHON3_INCLUDES} -o nissy_python_module.so \ | 46 | ${CC} ${CFLAGS} -shared ${PYTHON3_INCLUDES} -o nissy_python_module.so \ |
| 50 | nissy.o python/nissy_module.c | 47 | nissy.o python/nissy_module.c |
| @@ -55,4 +52,4 @@ qt: nissy.o | |||
| 55 | cd qt/build && make | 52 | cd qt/build && make |
| 56 | cp qt/build/appnissyqt ./nissyqt | 53 | cp qt/build/appnissyqt ./nissyqt |
| 57 | 54 | ||
| 58 | .PHONY: all clean test tool debugtool shell debugshell shelltest python qt | 55 | .PHONY: all clean test tool debugtool shell debugshell python qt |
diff --git a/cpp/nissy.cpp b/cpp/nissy.cpp index a077c50..3c41733 100644 --- a/cpp/nissy.cpp +++ b/cpp/nissy.cpp | |||
| @@ -13,7 +13,7 @@ extern "C" { | |||
| 13 | long long nissy_applymoves(const char *, const char *, char *); | 13 | long long nissy_applymoves(const char *, const char *, char *); |
| 14 | long long nissy_applytrans(const char *, const char *, char *); | 14 | long long nissy_applytrans(const char *, const char *, char *); |
| 15 | long long nissy_getcube(long long, long long, long long, long long, | 15 | long long nissy_getcube(long long, long long, long long, long long, |
| 16 | const char *, char *); | 16 | long long, const char *, char *); |
| 17 | long long nissy_solverinfo(const char *, char *); | 17 | long long nissy_solverinfo(const char *, char *); |
| 18 | long long nissy_gendata(const char *, unsigned long long, | 18 | long long nissy_gendata(const char *, unsigned long long, |
| 19 | unsigned char *); | 19 | unsigned char *); |
| @@ -103,19 +103,20 @@ namespace nissy { | |||
| 103 | } | 103 | } |
| 104 | 104 | ||
| 105 | std::variant<cube, error> | 105 | std::variant<cube, error> |
| 106 | cube::get(long long ep, long long eo, long long cp, long long co) | 106 | cube::get(long long ep, long long eo, |
| 107 | long long cp, long long co, long long orien) | ||
| 107 | { | 108 | { |
| 108 | return get(ep, eo, cp, co, "fix"); | 109 | return get(ep, eo, cp, co, orien, "fix"); |
| 109 | } | 110 | } |
| 110 | 111 | ||
| 111 | std::variant<cube, error> | 112 | std::variant<cube, error> |
| 112 | cube::get(long long ep, long long eo, long long cp, long long co, | 113 | cube::get(long long ep, long long eo, long long cp, long long co, |
| 113 | const std::string& options) | 114 | long long orient, const std::string& options) |
| 114 | { | 115 | { |
| 115 | char result[size::CUBE]; | 116 | char result[size::CUBE]; |
| 116 | cube c; | 117 | cube c; |
| 117 | auto err = nissy_getcube( | 118 | auto err = nissy_getcube(ep, eo, cp, co, orient, |
| 118 | ep, eo, cp, co, options.c_str(), result); | 119 | options.c_str(), result); |
| 119 | if (err < 0) | 120 | if (err < 0) |
| 120 | return error{err}; | 121 | return error{err}; |
| 121 | c.m_str = result; | 122 | c.m_str = result; |
diff --git a/cpp/nissy.h b/cpp/nissy.h index 8fd0aff..4fa98ad 100644 --- a/cpp/nissy.h +++ b/cpp/nissy.h | |||
| @@ -56,10 +56,10 @@ namespace nissy { | |||
| 56 | 56 | ||
| 57 | static std::variant<cube, error> from_string( | 57 | static std::variant<cube, error> from_string( |
| 58 | const std::string&); | 58 | const std::string&); |
| 59 | static std::variant<cube, error> get( | 59 | static std::variant<cube, error> get(long long ep, |
| 60 | long long ep, long long eo, long long cp, long long co); | 60 | long long eo, long long cp, long long co, long long orien); |
| 61 | static std::variant<cube, error> get( | 61 | static std::variant<cube, error> get(long long ep, |
| 62 | long long ep, long long eo, long long cp, long long co, | 62 | long long eo, long long cp, long long co, long long orien, |
| 63 | const std::string& options); | 63 | const std::string& options); |
| 64 | 64 | ||
| 65 | private: | 65 | private: |
diff --git a/python/nissy_module.c b/python/nissy_module.c index 5378c72..bf5a71a 100644 --- a/python/nissy_module.c +++ b/python/nissy_module.c | |||
| @@ -138,7 +138,7 @@ applytrans(PyObject *self, PyObject *args) | |||
| 138 | } | 138 | } |
| 139 | 139 | ||
| 140 | PyDoc_STRVAR(getcube_doc, | 140 | PyDoc_STRVAR(getcube_doc, |
| 141 | "getcube(ep, eo, cp, co, options)\n" | 141 | "getcube(ep, eo, cp, co, orientation, options)\n" |
| 142 | "--\n\n" | 142 | "--\n\n" |
| 143 | "Constructs the cube from the given coordinates and options\n" | 143 | "Constructs the cube from the given coordinates and options\n" |
| 144 | "\n" | 144 | "\n" |
| @@ -147,6 +147,7 @@ PyDoc_STRVAR(getcube_doc, | |||
| 147 | " - eo: the edge orientation coordinate\n" | 147 | " - eo: the edge orientation coordinate\n" |
| 148 | " - cp: the corner permutation coordinate\n" | 148 | " - cp: the corner permutation coordinate\n" |
| 149 | " - co: the corner orientation coordinate\n" | 149 | " - co: the corner orientation coordinate\n" |
| 150 | " - orientation: the orientation of the cube\n" | ||
| 150 | " - options: a string, for example \"fix\"\n" | 151 | " - options: a string, for example \"fix\"\n" |
| 151 | "\n" | 152 | "\n" |
| 152 | "Returns: the cube constructed from the given coordinates\n" | 153 | "Returns: the cube constructed from the given coordinates\n" |
| @@ -154,14 +155,15 @@ PyDoc_STRVAR(getcube_doc, | |||
| 154 | static PyObject * | 155 | static PyObject * |
| 155 | getcube(PyObject *self, PyObject *args) | 156 | getcube(PyObject *self, PyObject *args) |
| 156 | { | 157 | { |
| 157 | long long ep, eo, cp, co, err; | 158 | long long ep, eo, cp, co, or, err; |
| 158 | const char *options; | 159 | const char *options; |
| 159 | char result[NISSY_SIZE_CUBE]; | 160 | char result[NISSY_SIZE_CUBE]; |
| 160 | 161 | ||
| 161 | if (!PyArg_ParseTuple(args, "LLLLs", &ep, &eo, &cp, &co, &options)) | 162 | if (!PyArg_ParseTuple( |
| 163 | args, "LLLLLs", &ep, &eo, &cp, &co, &or, &options)) | ||
| 162 | return NULL; | 164 | return NULL; |
| 163 | 165 | ||
| 164 | err = nissy_getcube(ep, eo, cp, co, options, result); | 166 | err = nissy_getcube(ep, eo, cp, co, or, options, result); |
| 165 | return string_result(err, result); | 167 | return string_result(err, result); |
| 166 | } | 168 | } |
| 167 | 169 | ||
diff --git a/shell/shell.c b/shell/shell.c index 40a5748..3ee69c4 100644 --- a/shell/shell.c +++ b/shell/shell.c | |||
| @@ -268,7 +268,7 @@ randomcube_exec(args_t *args) | |||
| 268 | eo = rand64(); | 268 | eo = rand64(); |
| 269 | cp = rand64(); | 269 | cp = rand64(); |
| 270 | co = rand64(); | 270 | co = rand64(); |
| 271 | ret = nissy_getcube(ep, eo, cp, co, "fix", result); | 271 | ret = nissy_getcube(ep, eo, cp, co, 0, "fix", result); |
| 272 | if (ret == NISSY_OK || ret == NISSY_WARNING_UNSOLVABLE) | 272 | if (ret == NISSY_OK || ret == NISSY_WARNING_UNSOLVABLE) |
| 273 | printf("%s\n", result); | 273 | printf("%s\n", result); |
| 274 | 274 | ||
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 | ); |
