nissy-core

The "engine" of nissy, including the H48 optimal solver.
git clone https://git.tronto.net/nissy-core
Download | Log | Files | Refs | README | LICENSE

commit 9c209afd81e4c51e4fc2717c0eeff4a5d116bcb0
parent 039267a278bb9e0580e8aebd85ef5f3ed774688f
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date:   Wed, 23 Apr 2025 15:42:11 +0200

Added orientation to getcube

Diffstat:
MMakefile | 5+----
Mcpp/nissy.cpp | 13+++++++------
Mcpp/nissy.h | 8++++----
Mpython/nissy_module.c | 10++++++----
Mshell/shell.c | 2+-
Msrc/core/cube.h | 12++++++++++--
Msrc/nissy.c | 19+++++++++++--------
Msrc/nissy.h | 10++++++----
8 files changed, 46 insertions(+), 33 deletions(-)

diff --git a/Makefile b/Makefile @@ -42,9 +42,6 @@ debugshell: debugnissy.o mkdir -p tables ${CC} ${MACROS} ${DBGFLAGS} -o debugrun debugnissy.o shell/shell.c -shelltest: debugshell - ./shell/test.sh - python: nissy.o ${CC} ${CFLAGS} -shared ${PYTHON3_INCLUDES} -o nissy_python_module.so \ nissy.o python/nissy_module.c @@ -55,4 +52,4 @@ qt: nissy.o cd qt/build && make cp qt/build/appnissyqt ./nissyqt -.PHONY: all clean test tool debugtool shell debugshell shelltest python qt +.PHONY: all clean test tool debugtool shell debugshell python qt diff --git a/cpp/nissy.cpp b/cpp/nissy.cpp @@ -13,7 +13,7 @@ extern "C" { long long nissy_applymoves(const char *, const char *, char *); long long nissy_applytrans(const char *, const char *, char *); long long nissy_getcube(long long, long long, long long, long long, - const char *, char *); + long long, const char *, char *); long long nissy_solverinfo(const char *, char *); long long nissy_gendata(const char *, unsigned long long, unsigned char *); @@ -103,19 +103,20 @@ namespace nissy { } std::variant<cube, error> - cube::get(long long ep, long long eo, long long cp, long long co) + cube::get(long long ep, long long eo, + long long cp, long long co, long long orien) { - return get(ep, eo, cp, co, "fix"); + return get(ep, eo, cp, co, orien, "fix"); } std::variant<cube, error> cube::get(long long ep, long long eo, long long cp, long long co, - const std::string& options) + long long orient, const std::string& options) { char result[size::CUBE]; cube c; - auto err = nissy_getcube( - ep, eo, cp, co, options.c_str(), result); + auto err = nissy_getcube(ep, eo, cp, co, orient, + options.c_str(), result); if (err < 0) return error{err}; c.m_str = result; diff --git a/cpp/nissy.h b/cpp/nissy.h @@ -56,10 +56,10 @@ namespace nissy { static std::variant<cube, error> from_string( const std::string&); - static std::variant<cube, error> get( - long long ep, long long eo, long long cp, long long co); - static std::variant<cube, error> get( - long long ep, long long eo, long long cp, long long co, + static std::variant<cube, error> get(long long ep, + long long eo, long long cp, long long co, long long orien); + static std::variant<cube, error> get(long long ep, + long long eo, long long cp, long long co, long long orien, const std::string& options); private: diff --git a/python/nissy_module.c b/python/nissy_module.c @@ -138,7 +138,7 @@ applytrans(PyObject *self, PyObject *args) } PyDoc_STRVAR(getcube_doc, -"getcube(ep, eo, cp, co, options)\n" +"getcube(ep, eo, cp, co, orientation, options)\n" "--\n\n" "Constructs the cube from the given coordinates and options\n" "\n" @@ -147,6 +147,7 @@ PyDoc_STRVAR(getcube_doc, " - eo: the edge orientation coordinate\n" " - cp: the corner permutation coordinate\n" " - co: the corner orientation coordinate\n" +" - orientation: the orientation of the cube\n" " - options: a string, for example \"fix\"\n" "\n" "Returns: the cube constructed from the given coordinates\n" @@ -154,14 +155,15 @@ PyDoc_STRVAR(getcube_doc, static PyObject * getcube(PyObject *self, PyObject *args) { - long long ep, eo, cp, co, err; + long long ep, eo, cp, co, or, err; const char *options; char result[NISSY_SIZE_CUBE]; - if (!PyArg_ParseTuple(args, "LLLLs", &ep, &eo, &cp, &co, &options)) + if (!PyArg_ParseTuple( + args, "LLLLLs", &ep, &eo, &cp, &co, &or, &options)) return NULL; - err = nissy_getcube(ep, eo, cp, co, options, result); + err = nissy_getcube(ep, eo, cp, co, or, options, result); return string_result(err, result); } diff --git a/shell/shell.c b/shell/shell.c @@ -268,7 +268,7 @@ randomcube_exec(args_t *args) eo = rand64(); cp = rand64(); co = rand64(); - ret = nissy_getcube(ep, eo, cp, co, "fix", result); + ret = nissy_getcube(ep, eo, cp, co, 0, "fix", result); if (ret == NISSY_OK || ret == NISSY_WARNING_UNSOLVABLE) printf("%s\n", result); diff --git 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 @@ -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 @@ -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] );