diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2025-04-22 14:17:03 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2025-04-22 14:17:03 +0200 |
| commit | ac652bb6fb45099008e862e3ced650299dc3ebb7 (patch) | |
| tree | 12fb1c902c271fbeac41c4ee416cf1cd76b16fd7 /python/nissy_module.c | |
| parent | 71e104d84b3538e15f27df79b151e6b49cbad1eb (diff) | |
| parent | e391c4624055138f075c0e5772ccaf8ede094b5a (diff) | |
| download | nissy-core-ac652bb6fb45099008e862e3ced650299dc3ebb7.tar.gz nissy-core-ac652bb6fb45099008e862e3ced650299dc3ebb7.zip | |
Merge branch 'master' into extend_moves
Diffstat (limited to 'python/nissy_module.c')
| -rw-r--r-- | python/nissy_module.c | 59 |
1 files changed, 15 insertions, 44 deletions
diff --git a/python/nissy_module.c b/python/nissy_module.c index b389297..58a5b67 100644 --- a/python/nissy_module.c +++ b/python/nissy_module.c | |||
| @@ -4,7 +4,6 @@ | |||
| 4 | 4 | ||
| 5 | #include "../src/nissy.h" | 5 | #include "../src/nissy.h" |
| 6 | 6 | ||
| 7 | #define MAX_CUBE_STR_LEN 1024 /* Update when adding formats */ | ||
| 8 | #define MAX_SOLUTIONS_SIZE 250000 | 7 | #define MAX_SOLUTIONS_SIZE 250000 |
| 9 | 8 | ||
| 10 | static bool | 9 | static bool |
| @@ -24,7 +23,6 @@ check_error(long long err) | |||
| 24 | case NISSY_ERROR_UNSOLVABLE_CUBE: /* Fallthrough */ | 23 | case NISSY_ERROR_UNSOLVABLE_CUBE: /* Fallthrough */ |
| 25 | case NISSY_ERROR_INVALID_MOVES: | 24 | case NISSY_ERROR_INVALID_MOVES: |
| 26 | case NISSY_ERROR_INVALID_TRANS: | 25 | case NISSY_ERROR_INVALID_TRANS: |
| 27 | case NISSY_ERROR_INVALID_FORMAT: | ||
| 28 | case NISSY_ERROR_INVALID_SOLVER: | 26 | case NISSY_ERROR_INVALID_SOLVER: |
| 29 | case NISSY_ERROR_NULL_POINTER: | 27 | case NISSY_ERROR_NULL_POINTER: |
| 30 | case NISSY_ERROR_BUFFER_SIZE: | 28 | case NISSY_ERROR_BUFFER_SIZE: |
| @@ -70,17 +68,17 @@ PyDoc_STRVAR(compose_doc, | |||
| 70 | "Apply 'permutation' on 'cube'.\n" | 68 | "Apply 'permutation' on 'cube'.\n" |
| 71 | "\n" | 69 | "\n" |
| 72 | "Parameters:\n" | 70 | "Parameters:\n" |
| 73 | " - cube: a cube in B32 format\n" | 71 | " - cube: a cube\n" |
| 74 | " - permutation: another cube in B32 format\n" | 72 | " - permutation: another cube\n" |
| 75 | "\n" | 73 | "\n" |
| 76 | "Returns: the resulting cube string in B32 format\n" | 74 | "Returns: the resulting cube string\n" |
| 77 | ); | 75 | ); |
| 78 | static PyObject * | 76 | static PyObject * |
| 79 | compose(PyObject *self, PyObject *args) | 77 | compose(PyObject *self, PyObject *args) |
| 80 | { | 78 | { |
| 81 | long long err; | 79 | long long err; |
| 82 | const char *cube, *permutation; | 80 | const char *cube, *permutation; |
| 83 | char result[NISSY_SIZE_B32]; | 81 | char result[NISSY_SIZE_CUBE]; |
| 84 | 82 | ||
| 85 | if (!PyArg_ParseTuple(args, "ss", &cube, &permutation)) | 83 | if (!PyArg_ParseTuple(args, "ss", &cube, &permutation)) |
| 86 | return NULL; | 84 | return NULL; |
| @@ -95,16 +93,16 @@ PyDoc_STRVAR(inverse_doc, | |||
| 95 | "Invert 'cube'.\n" | 93 | "Invert 'cube'.\n" |
| 96 | "\n" | 94 | "\n" |
| 97 | "Parameters:\n" | 95 | "Parameters:\n" |
| 98 | " - cube: a cube in B32 format\n" | 96 | " - cube: a cube in\n" |
| 99 | "\n" | 97 | "\n" |
| 100 | "Returns: the inverse cube in B32 format\n" | 98 | "Returns: the inverse cube\n" |
| 101 | ); | 99 | ); |
| 102 | static PyObject * | 100 | static PyObject * |
| 103 | inverse(PyObject *self, PyObject *args) | 101 | inverse(PyObject *self, PyObject *args) |
| 104 | { | 102 | { |
| 105 | long long err; | 103 | long long err; |
| 106 | const char *cube; | 104 | const char *cube; |
| 107 | char result[NISSY_SIZE_B32]; | 105 | char result[NISSY_SIZE_CUBE]; |
| 108 | 106 | ||
| 109 | if (!PyArg_ParseTuple(args, "s", &cube)) | 107 | if (!PyArg_ParseTuple(args, "s", &cube)) |
| 110 | return NULL; | 108 | return NULL; |
| @@ -119,17 +117,17 @@ PyDoc_STRVAR(applymoves_doc, | |||
| 119 | "Apply 'moves' to 'cube'.\n" | 117 | "Apply 'moves' to 'cube'.\n" |
| 120 | "\n" | 118 | "\n" |
| 121 | "Parameters:\n" | 119 | "Parameters:\n" |
| 122 | " - cube: a cube in B32 format\n" | 120 | " - cube: a cube in\n" |
| 123 | " - moves: the moves to apply on the cube\n" | 121 | " - moves: the moves to apply on the cube\n" |
| 124 | "\n" | 122 | "\n" |
| 125 | "Returns: the resulting cube in B32 format\n" | 123 | "Returns: the resulting cube\n" |
| 126 | ); | 124 | ); |
| 127 | static PyObject * | 125 | static PyObject * |
| 128 | applymoves(PyObject *self, PyObject *args) | 126 | applymoves(PyObject *self, PyObject *args) |
| 129 | { | 127 | { |
| 130 | long long err; | 128 | long long err; |
| 131 | const char *cube, *moves; | 129 | const char *cube, *moves; |
| 132 | char result[NISSY_SIZE_B32]; | 130 | char result[NISSY_SIZE_CUBE]; |
| 133 | 131 | ||
| 134 | if (!PyArg_ParseTuple(args, "ss", &cube, &moves)) | 132 | if (!PyArg_ParseTuple(args, "ss", &cube, &moves)) |
| 135 | return NULL; | 133 | return NULL; |
| @@ -144,19 +142,19 @@ PyDoc_STRVAR(applytrans_doc, | |||
| 144 | "Apply 'transformation' to 'cube'.\n" | 142 | "Apply 'transformation' to 'cube'.\n" |
| 145 | "\n" | 143 | "\n" |
| 146 | "Parameters:\n" | 144 | "Parameters:\n" |
| 147 | " - cube: a cube in B32 format\n" | 145 | " - cube: a cube\n" |
| 148 | " - transformation: the transformation to apply on the cube, formatted as\n" | 146 | " - transformation: the transformation to apply on the cube, formatted as\n" |
| 149 | " (rotation|mirrored) (2 letters)\n" | 147 | " (rotation|mirrored) (2 letters)\n" |
| 150 | " for example 'mirrored ur' or 'rotation lf'\n" | 148 | " for example 'mirrored ur' or 'rotation lf'\n" |
| 151 | "\n" | 149 | "\n" |
| 152 | "Returns: the resulting cube in B32 format\n" | 150 | "Returns: the resulting cube\n" |
| 153 | ); | 151 | ); |
| 154 | static PyObject * | 152 | static PyObject * |
| 155 | applytrans(PyObject *self, PyObject *args) | 153 | applytrans(PyObject *self, PyObject *args) |
| 156 | { | 154 | { |
| 157 | long long err; | 155 | long long err; |
| 158 | const char *cube, *trans; | 156 | const char *cube, *trans; |
| 159 | char result[NISSY_SIZE_B32]; | 157 | char result[NISSY_SIZE_CUBE]; |
| 160 | 158 | ||
| 161 | if (!PyArg_ParseTuple(args, "ss", &cube, &trans)) | 159 | if (!PyArg_ParseTuple(args, "ss", &cube, &trans)) |
| 162 | return NULL; | 160 | return NULL; |
| @@ -165,32 +163,6 @@ applytrans(PyObject *self, PyObject *args) | |||
| 165 | return string_result(err, result); | 163 | return string_result(err, result); |
| 166 | } | 164 | } |
| 167 | 165 | ||
| 168 | PyDoc_STRVAR(convert_doc, | ||
| 169 | "convert(fin, fout, cube)\n" | ||
| 170 | "--\n\n" | ||
| 171 | "Convert 'cube' from format 'fin' to format 'fout'.\n" | ||
| 172 | "\n" | ||
| 173 | "Parameters:\n" | ||
| 174 | " - fin: the format in which 'cube' is given\n" | ||
| 175 | " - fout: the format to which 'cube' has to be converted\n" | ||
| 176 | " - cube: a cube in B32 format\n" | ||
| 177 | "\n" | ||
| 178 | "Returns: 'cube' in 'fout' format\n" | ||
| 179 | ); | ||
| 180 | static PyObject * | ||
| 181 | convert(PyObject *self, PyObject *args) | ||
| 182 | { | ||
| 183 | long long err; | ||
| 184 | const char *fin, *fout, *cube; | ||
| 185 | char result[MAX_CUBE_STR_LEN]; | ||
| 186 | |||
| 187 | if (!PyArg_ParseTuple(args, "sss", &fin, &fout, &cube)) | ||
| 188 | return NULL; | ||
| 189 | |||
| 190 | err = nissy_convert(fin, fout, cube, MAX_CUBE_STR_LEN, result); | ||
| 191 | return string_result(err, result); | ||
| 192 | } | ||
| 193 | |||
| 194 | PyDoc_STRVAR(getcube_doc, | 166 | PyDoc_STRVAR(getcube_doc, |
| 195 | "getcube(ep, eo, cp, co, options)\n" | 167 | "getcube(ep, eo, cp, co, options)\n" |
| 196 | "--\n\n" | 168 | "--\n\n" |
| @@ -210,7 +182,7 @@ getcube(PyObject *self, PyObject *args) | |||
| 210 | { | 182 | { |
| 211 | long long ep, eo, cp, co, err; | 183 | long long ep, eo, cp, co, err; |
| 212 | const char *options; | 184 | const char *options; |
| 213 | char result[NISSY_SIZE_B32]; | 185 | char result[NISSY_SIZE_CUBE]; |
| 214 | 186 | ||
| 215 | if (!PyArg_ParseTuple(args, "LLLLs", &ep, &eo, &cp, &co, &options)) | 187 | if (!PyArg_ParseTuple(args, "LLLLs", &ep, &eo, &cp, &co, &options)) |
| 216 | return NULL; | 188 | return NULL; |
| @@ -321,7 +293,7 @@ PyDoc_STRVAR(solve_doc, | |||
| 321 | "See the documentation for libnissy (in nissy.h) for details.\n" | 293 | "See the documentation for libnissy (in nissy.h) for details.\n" |
| 322 | "\n" | 294 | "\n" |
| 323 | "Parameters:\n" | 295 | "Parameters:\n" |
| 324 | " - cube: a cube in B32 format\n" | 296 | " - cube: a cube\n" |
| 325 | " - solver: the solver to use\n" | 297 | " - solver: the solver to use\n" |
| 326 | " - minmoves: the minimum number of moves to use\n" | 298 | " - minmoves: the minimum number of moves to use\n" |
| 327 | " - maxmoves: the maximum number of moves to use\n" | 299 | " - maxmoves: the maximum number of moves to use\n" |
| @@ -400,7 +372,6 @@ static PyMethodDef nissy_methods[] = { | |||
| 400 | { "inverse", inverse, METH_VARARGS, inverse_doc }, | 372 | { "inverse", inverse, METH_VARARGS, inverse_doc }, |
| 401 | { "applymoves", applymoves, METH_VARARGS, applymoves_doc }, | 373 | { "applymoves", applymoves, METH_VARARGS, applymoves_doc }, |
| 402 | { "applytrans", applytrans, METH_VARARGS, applytrans_doc }, | 374 | { "applytrans", applytrans, METH_VARARGS, applytrans_doc }, |
| 403 | { "convert", convert, METH_VARARGS, convert_doc }, | ||
| 404 | { "getcube", getcube, METH_VARARGS, getcube_doc }, | 375 | { "getcube", getcube, METH_VARARGS, getcube_doc }, |
| 405 | { "solverinfo", solverinfo, METH_VARARGS, solverinfo_doc }, | 376 | { "solverinfo", solverinfo, METH_VARARGS, solverinfo_doc }, |
| 406 | { "gendata", gendata, METH_VARARGS, gendata_doc }, | 377 | { "gendata", gendata, METH_VARARGS, gendata_doc }, |
