aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--cpp/examples/move.cpp17
-rw-r--r--cpp/examples/move_convert.cpp24
-rw-r--r--cpp/nissy.cpp66
-rw-r--r--cpp/nissy.h7
-rw-r--r--python/nissy_module.c59
-rw-r--r--shell/shell.c97
-rw-r--r--src/core/core.h1
-rw-r--r--src/core/cube.h190
-rw-r--r--src/nissy.c80
-rw-r--r--src/nissy.h98
-rw-r--r--tools/300_solve_small/solve_small.c2
-rw-r--r--tools/301_solve_file/solve_file.c2
-rw-r--r--tools/302_solve_multisol/solve_multisol.c2
-rw-r--r--tools/400_solvetest/solve_test.c2
-rw-r--r--utils/convert.c (renamed from src/core/io_formats.h)6
-rwxr-xr-xutils/genmovecode.sh15
-rwxr-xr-xutils/genmoveswitch.sh8
-rwxr-xr-xutils/gentranscode.sh25
-rwxr-xr-xutils/gentransswitch.sh14
-rwxr-xr-xutils/gentranstests.sh35
-rw-r--r--utils/h48_to_lst.c22
-rw-r--r--utils/invert.c19
-rwxr-xr-xutils/mirror.sh3
23 files changed, 317 insertions, 477 deletions
diff --git a/cpp/examples/move.cpp b/cpp/examples/move.cpp
new file mode 100644
index 0000000..970a65d
--- /dev/null
+++ b/cpp/examples/move.cpp
@@ -0,0 +1,17 @@
1/* A simple example showing how to move a cube and print it in H48 format. */
2
3#include "../nissy.h"
4#include <iostream>
5
6int main() {
7 nissy::cube c;
8 if (!c.move("R' U' F").ok()) {
9 std::cout << "Error moving the cube!" << std::endl;
10 return 1;
11 }
12
13 auto str = c.to_string();
14 std::cout << "Cube after R' U' F:" << std::endl << str << std::endl;
15
16 return 0;
17}
diff --git a/cpp/examples/move_convert.cpp b/cpp/examples/move_convert.cpp
deleted file mode 100644
index 11398df..0000000
--- a/cpp/examples/move_convert.cpp
+++ /dev/null
@@ -1,24 +0,0 @@
1/* A simple example showing how to move a cube and print it in H48 format. */
2
3#include "../nissy.h"
4#include <iostream>
5
6int main() {
7 nissy::cube c;
8 if (!c.move("R' U' F").ok()) {
9 std::cout << "Error moving the cube!" << std::endl;
10 return 1;
11 }
12
13 auto string_or_error = c.to_string("H48");
14 if (std::holds_alternative<nissy::error>(string_or_error)) {
15 std::cout << "Error converting cube!" << std::endl;
16 return 1;
17 }
18
19 auto str = std::get<std::string>(string_or_error);
20 std::cout << "Cube in H48 format after R' U' F:" << std::endl
21 << str << std::endl;
22
23 return 0;
24}
diff --git a/cpp/nissy.cpp b/cpp/nissy.cpp
index 88df0f2..3535553 100644
--- a/cpp/nissy.cpp
+++ b/cpp/nissy.cpp
@@ -13,8 +13,6 @@ extern "C" {
13 long long nissy_inverse(const char *, char *); 13 long long nissy_inverse(const char *, char *);
14 long long nissy_applymoves(const char *, const char *, char *); 14 long long nissy_applymoves(const char *, const char *, char *);
15 long long nissy_applytrans(const char *, const char *, char *); 15 long long nissy_applytrans(const char *, const char *, char *);
16 long long nissy_convert(const char *, const char *, const char *,
17 unsigned, char *);
18 long long nissy_getcube(long long, long long, long long, long long, 16 long long nissy_getcube(long long, long long, long long, long long,
19 const char *, char *); 17 const char *, char *);
20 long long nissy_solverinfo(const char *, char *); 18 long long nissy_solverinfo(const char *, char *);
@@ -43,7 +41,6 @@ namespace nissy {
43 const error error::UNSOLVABLE_CUBE{-11}; 41 const error error::UNSOLVABLE_CUBE{-11};
44 const error error::INVALID_MOVES{-20}; 42 const error error::INVALID_MOVES{-20};
45 const error error::INVALID_TRANS{-30}; 43 const error error::INVALID_TRANS{-30};
46 const error error::INVALID_FORMAT{-40};
47 const error error::INVALID_SOLVER{-50}; 44 const error error::INVALID_SOLVER{-50};
48 const error error::NULL_POINTER{-60}; 45 const error error::NULL_POINTER{-60};
49 const error error::BUFFER_SIZE{-61}; 46 const error error::BUFFER_SIZE{-61};
@@ -52,9 +49,7 @@ namespace nissy {
52 const error error::UNKNOWN{-999}; 49 const error error::UNKNOWN{-999};
53 50
54 namespace size { 51 namespace size {
55 constexpr size_t B32 = 22; 52 constexpr size_t CUBE = 22;
56 constexpr size_t H48 = 88;
57 constexpr size_t CUBE_MAX = H48;
58 constexpr size_t TRANSFORMATION = 12; 53 constexpr size_t TRANSFORMATION = 12;
59 constexpr size_t DATAID = 255; 54 constexpr size_t DATAID = 255;
60 } 55 }
@@ -65,71 +60,54 @@ namespace nissy {
65 60
66 error cube::move(const std::string& moves) 61 error cube::move(const std::string& moves)
67 { 62 {
68 char result[size::B32]; 63 char result[size::CUBE];
69 long long err = nissy_applymoves( 64 long long err = nissy_applymoves(
70 m_b32.c_str(), moves.c_str(), result); 65 m_str.c_str(), moves.c_str(), result);
71 if (err < 0) 66 if (err < 0)
72 return error{err}; 67 return error{err};
73 m_b32 = result; 68 m_str = result;
74 return error::OK; 69 return error::OK;
75 } 70 }
76 71
77 error cube::transform(const std::string& trans) 72 error cube::transform(const std::string& trans)
78 { 73 {
79 char result[size::B32]; 74 char result[size::CUBE];
80 long long err = nissy_applytrans( 75 long long err = nissy_applytrans(
81 m_b32.c_str(), trans.c_str(), result); 76 m_str.c_str(), trans.c_str(), result);
82 if (err < 0) 77 if (err < 0)
83 return error{err}; 78 return error{err};
84 m_b32 = result; 79 m_str = result;
85 return error::OK; 80 return error::OK;
86 } 81 }
87 82
88 void cube::invert() 83 void cube::invert()
89 { 84 {
90 char result[size::B32]; 85 char result[size::CUBE];
91 nissy_inverse(m_b32.c_str(), result); 86 nissy_inverse(m_str.c_str(), result);
92 m_b32 = result; 87 m_str = result;
93 } 88 }
94 89
95 void cube::compose(const cube& other) 90 void cube::compose(const cube& other)
96 { 91 {
97 char result[size::B32]; 92 char result[size::CUBE];
98 nissy_compose( 93 nissy_compose(
99 m_b32.c_str(), other.to_string().c_str(), result); 94 m_str.c_str(), other.to_string().c_str(), result);
100 m_b32 = result; 95 m_str = result;
101 } 96 }
102 97
103 std::string cube::to_string() const { return m_b32; } 98 std::string cube::to_string() const { return m_str; }
104
105 std::variant<std::string, error>
106 cube::to_string(const std::string& format) const
107 {
108 char result[size::CUBE_MAX];
109 auto err = nissy_convert("B32", format.c_str(),
110 m_b32.c_str(), size::CUBE_MAX, result);
111 if (err < 0)
112 return error{err};
113 else
114 return result;
115 }
116 99
117 std::variant<cube, error> 100 std::variant<cube, error>
118 cube::from_string(const std::string& str) 101 cube::from_string(const std::string& str)
119 { 102 {
120 return from_string(str, "B32"); 103 /* Check that the cube is valid by making a single move */
121 } 104 char result[size::CUBE];
122 105 auto err = nissy_applymoves(str.c_str(), "U", result);
123 std::variant<cube, error>
124 cube::from_string(const std::string& str, const std::string& format)
125 {
126 char result[size::B32];
127 cube c;
128 auto err = nissy_convert(format.c_str(),
129 "B32", c.m_b32.c_str(), size::B32, result);
130 if (err < 0) 106 if (err < 0)
131 return error{err}; 107 return error{err};
132 c.m_b32 = result; 108
109 cube c;
110 c.m_str = str;
133 return c; 111 return c;
134 } 112 }
135 113
@@ -143,13 +121,13 @@ namespace nissy {
143 cube::get(long long ep, long long eo, long long cp, long long co, 121 cube::get(long long ep, long long eo, long long cp, long long co,
144 const std::string& options) 122 const std::string& options)
145 { 123 {
146 char result[size::B32]; 124 char result[size::CUBE];
147 cube c; 125 cube c;
148 auto err = nissy_getcube( 126 auto err = nissy_getcube(
149 ep, eo, cp, co, options.c_str(), result); 127 ep, eo, cp, co, options.c_str(), result);
150 if (err < 0) 128 if (err < 0)
151 return error{err}; 129 return error{err};
152 c.m_b32 = result; 130 c.m_str = result;
153 return c; 131 return c;
154 } 132 }
155 133
diff --git a/cpp/nissy.h b/cpp/nissy.h
index 4b9c1c9..2eb0f42 100644
--- a/cpp/nissy.h
+++ b/cpp/nissy.h
@@ -38,7 +38,6 @@ namespace nissy {
38 static const error UNSOLVABLE_CUBE; 38 static const error UNSOLVABLE_CUBE;
39 static const error INVALID_MOVES; 39 static const error INVALID_MOVES;
40 static const error INVALID_TRANS; 40 static const error INVALID_TRANS;
41 static const error INVALID_FORMAT;
42 static const error INVALID_SOLVER; 41 static const error INVALID_SOLVER;
43 static const error NULL_POINTER; 42 static const error NULL_POINTER;
44 static const error BUFFER_SIZE; 43 static const error BUFFER_SIZE;
@@ -55,13 +54,9 @@ namespace nissy {
55 void invert(); 54 void invert();
56 void compose(const cube&); 55 void compose(const cube&);
57 std::string to_string() const; 56 std::string to_string() const;
58 std::variant<std::string, error> to_string(
59 const std::string& format) const;
60 57
61 static std::variant<cube, error> from_string( 58 static std::variant<cube, error> from_string(
62 const std::string&); 59 const std::string&);
63 static std::variant<cube, error> from_string(
64 const std::string& str, const std::string& format);
65 static std::variant<cube, error> get( 60 static std::variant<cube, error> get(
66 long long ep, long long eo, long long cp, long long co); 61 long long ep, long long eo, long long cp, long long co);
67 static std::variant<cube, error> get( 62 static std::variant<cube, error> get(
@@ -69,7 +64,7 @@ namespace nissy {
69 const std::string& options); 64 const std::string& options);
70 65
71 private: 66 private:
72 std::string m_b32{"ABCDEFGH=ABCDEFGHIJKL"}; 67 std::string m_str{"ABCDEFGH=ABCDEFGHIJKL=A"};
73 }; 68 };
74 69
75 class solver { 70 class solver {
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
10static bool 9static 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);
78static PyObject * 76static PyObject *
79compose(PyObject *self, PyObject *args) 77compose(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);
102static PyObject * 100static PyObject *
103inverse(PyObject *self, PyObject *args) 101inverse(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);
127static PyObject * 125static PyObject *
128applymoves(PyObject *self, PyObject *args) 126applymoves(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);
154static PyObject * 152static PyObject *
155applytrans(PyObject *self, PyObject *args) 153applytrans(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
168PyDoc_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);
180static PyObject *
181convert(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
194PyDoc_STRVAR(getcube_doc, 166PyDoc_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 },
diff --git a/shell/shell.c b/shell/shell.c
index 104e7e0..ecd39f2 100644
--- a/shell/shell.c
+++ b/shell/shell.c
@@ -18,9 +18,6 @@
18#define FLAG_PERM "-perm" 18#define FLAG_PERM "-perm"
19#define FLAG_COMMAND "-command" 19#define FLAG_COMMAND "-command"
20#define FLAG_STR_CUBE "-cubestr" 20#define FLAG_STR_CUBE "-cubestr"
21#define FLAG_FORMAT "-format"
22#define FLAG_FORMAT_IN "-fin"
23#define FLAG_FORMAT_OUT "-fout"
24#define FLAG_MOVES "-moves" 21#define FLAG_MOVES "-moves"
25#define FLAG_TRANS "-trans" 22#define FLAG_TRANS "-trans"
26#define FLAG_SOLVER "-solver" 23#define FLAG_SOLVER "-solver"
@@ -31,23 +28,18 @@
31#define FLAG_MAXSOLUTIONS "-n" 28#define FLAG_MAXSOLUTIONS "-n"
32#define FLAG_THREADS "-t" 29#define FLAG_THREADS "-t"
33 30
34#define INFO_CUBEFORMAT(cube) cube " must be given in B32 format."
35#define INFO_MOVESFORMAT "The accepted moves are U, D, R, L, F and B, " \ 31#define INFO_MOVESFORMAT "The accepted moves are U, D, R, L, F and B, " \
36 "optionally followed by a 2, a ' or a 3." 32 "optionally followed by a 2, a ' or a 3."
37#define INFO_TRANSFORMAT "The transformation must be given in the format " \ 33#define INFO_TRANSFORMAT "The transformation must be given in the format " \
38 "(rotation|mirrored) (2 letters), for exmple " \ 34 "(rotation|mirrored) (2 letters), for exmple " \
39 "'rotation UF' or 'mirrored BL'." 35 "'rotation UF' or 'mirrored BL'."
40#define INFO_FORMATS "The available formats are H48, B32 and SRC."
41 36
42typedef struct { 37typedef struct {
43 int command_index; 38 int command_index;
44 char cube[22]; 39 char cube[NISSY_SIZE_CUBE];
45 char cube_perm[22]; 40 char cube_perm[NISSY_SIZE_CUBE];
46 char *str_command; 41 char *str_command;
47 char *str_cube; 42 char *str_cube;
48 char *str_format;
49 char *str_format_in;
50 char *str_format_out;
51 char *str_moves; 43 char *str_moves;
52 char *str_trans; 44 char *str_trans;
53 char *str_solver; 45 char *str_solver;
@@ -64,7 +56,6 @@ static int64_t inverse_exec(args_t *);
64static int64_t applymoves_exec(args_t *); 56static int64_t applymoves_exec(args_t *);
65static int64_t applytrans_exec(args_t *); 57static int64_t applytrans_exec(args_t *);
66static int64_t frommoves_exec(args_t *); 58static int64_t frommoves_exec(args_t *);
67static int64_t convert_exec(args_t *);
68static int64_t randomcube_exec(args_t *); 59static int64_t randomcube_exec(args_t *);
69static int64_t solverinfo_exec(args_t *); 60static int64_t solverinfo_exec(args_t *);
70static int64_t gendata_exec(args_t *); 61static int64_t gendata_exec(args_t *);
@@ -81,9 +72,6 @@ static bool set_cube(int, char **, args_t *);
81static bool set_cube_perm(int, char **, args_t *); 72static bool set_cube_perm(int, char **, args_t *);
82static bool set_str_command(int, char **, args_t *); 73static bool set_str_command(int, char **, args_t *);
83static bool set_str_cube(int, char **, args_t *); 74static bool set_str_cube(int, char **, args_t *);
84static bool set_str_format(int, char **, args_t *);
85static bool set_str_format_in(int, char **, args_t *);
86static bool set_str_format_out(int, char **, args_t *);
87static bool set_str_moves(int, char **, args_t *); 75static bool set_str_moves(int, char **, args_t *);
88static bool set_str_trans(int, char **, args_t *); 76static bool set_str_trans(int, char **, args_t *);
89static bool set_str_solver(int, char **, args_t *); 77static bool set_str_solver(int, char **, args_t *);
@@ -107,9 +95,6 @@ struct {
107 OPTION(FLAG_PERM, 1, set_cube_perm), 95 OPTION(FLAG_PERM, 1, set_cube_perm),
108 OPTION(FLAG_COMMAND, 1, set_str_command), 96 OPTION(FLAG_COMMAND, 1, set_str_command),
109 OPTION(FLAG_STR_CUBE, 1, set_str_cube), 97 OPTION(FLAG_STR_CUBE, 1, set_str_cube),
110 OPTION(FLAG_FORMAT, 1, set_str_format),
111 OPTION(FLAG_FORMAT_IN, 1, set_str_format_in),
112 OPTION(FLAG_FORMAT_OUT, 1, set_str_format_out),
113 OPTION(FLAG_MOVES, 1, set_str_moves), 98 OPTION(FLAG_MOVES, 1, set_str_moves),
114 OPTION(FLAG_TRANS, 1, set_str_trans), 99 OPTION(FLAG_TRANS, 1, set_str_trans),
115 OPTION(FLAG_SOLVER, 1, set_str_solver), 100 OPTION(FLAG_SOLVER, 1, set_str_solver),
@@ -133,29 +118,27 @@ struct {
133 COMMAND( 118 COMMAND(
134 "compose", 119 "compose",
135 "compose " FLAG_CUBE " CUBE " FLAG_PERM " PERM", 120 "compose " FLAG_CUBE " CUBE " FLAG_PERM " PERM",
136 "Apply on CUBE the permutation defined by PERM. " 121 "Apply on CUBE the permutation defined by PERM.",
137 INFO_CUBEFORMAT("CUBE and PERM"),
138 compose_exec 122 compose_exec
139 ), 123 ),
140 COMMAND( 124 COMMAND(
141 "inverse", 125 "inverse",
142 "inverse " FLAG_CUBE " CUBE ", 126 "inverse " FLAG_CUBE " CUBE ",
143 "Compute the inverse of the given CUBE. " 127 "Compute the inverse of the given CUBE.",
144 INFO_CUBEFORMAT("CUBE"),
145 inverse_exec 128 inverse_exec
146 ), 129 ),
147 COMMAND( 130 COMMAND(
148 "applymoves", 131 "applymoves",
149 "applymoves " FLAG_CUBE " CUBE " FLAG_MOVES " MOVES", 132 "applymoves " FLAG_CUBE " CUBE " FLAG_MOVES " MOVES",
150 "Apply the given MOVES to the given CUBE. " 133 "Apply the given MOVES to the given CUBE. "
151 INFO_CUBEFORMAT("CUBE") " " INFO_MOVESFORMAT, 134 INFO_MOVESFORMAT,
152 applymoves_exec 135 applymoves_exec
153 ), 136 ),
154 COMMAND( 137 COMMAND(
155 "applytrans", 138 "applytrans",
156 "applytrans " FLAG_CUBE " CUBE " FLAG_TRANS " TRANS", 139 "applytrans " FLAG_CUBE " CUBE " FLAG_TRANS " TRANS",
157 "Apply the single transformation TRANS to the given CUBE. " 140 "Apply the single transformation TRANS to the given CUBE. "
158 INFO_CUBEFORMAT("CUBE") " " INFO_TRANSFORMAT, 141 INFO_TRANSFORMAT,
159 applytrans_exec 142 applytrans_exec
160 ), 143 ),
161 COMMAND( 144 COMMAND(
@@ -166,19 +149,9 @@ struct {
166 frommoves_exec 149 frommoves_exec
167 ), 150 ),
168 COMMAND( 151 COMMAND(
169 "convert",
170 "convert " FLAG_STR_CUBE " CUBESTR "
171 FLAG_FORMAT_IN " FORMAT_IN " FLAG_FORMAT_OUT " FORMAT_OUT",
172 "Convert the cube described by CUBESTR from FORMAT_IN to "
173 "FORMAT_OUT."
174 INFO_FORMATS " "
175 "CUBESTR must be a valid cube in the FORMAT_IN format.",
176 convert_exec
177 ),
178 COMMAND(
179 "randomcube", 152 "randomcube",
180 "randomcube", 153 "randomcube",
181 "Returns a random cube in B32 format.", 154 "Returns a random.",
182 randomcube_exec 155 randomcube_exec
183 ), 156 ),
184 COMMAND( 157 COMMAND(
@@ -202,8 +175,7 @@ struct {
202 FLAG_CUBE " CUBE" 175 FLAG_CUBE " CUBE"
203 FLAG_THREADS " T", 176 FLAG_THREADS " T",
204 "Solve the given CUBE using SOLVER, " 177 "Solve the given CUBE using SOLVER, "
205 "using at least n and at most N moves, and T threads. " 178 "using at least n and at most N moves, and T threads.",
206 INFO_CUBEFORMAT("CUBE"),
207 solve_exec 179 solve_exec
208 ), 180 ),
209 COMMAND( 181 COMMAND(
@@ -254,7 +226,7 @@ rand64(void)
254static int64_t 226static int64_t
255compose_exec(args_t *args) 227compose_exec(args_t *args)
256{ 228{
257 char result[22]; 229 char result[NISSY_SIZE_CUBE];
258 int64_t ret; 230 int64_t ret;
259 231
260 ret = nissy_compose(args->cube, args->cube_perm, result); 232 ret = nissy_compose(args->cube, args->cube_perm, result);
@@ -267,7 +239,7 @@ compose_exec(args_t *args)
267static int64_t 239static int64_t
268inverse_exec(args_t *args) 240inverse_exec(args_t *args)
269{ 241{
270 char result[22]; 242 char result[NISSY_SIZE_CUBE];
271 int64_t ret; 243 int64_t ret;
272 244
273 ret = nissy_inverse(args->cube, result); 245 ret = nissy_inverse(args->cube, result);
@@ -280,7 +252,7 @@ inverse_exec(args_t *args)
280static int64_t 252static int64_t
281applymoves_exec(args_t *args) 253applymoves_exec(args_t *args)
282{ 254{
283 char result[22]; 255 char result[NISSY_SIZE_CUBE];
284 int64_t ret; 256 int64_t ret;
285 257
286 ret = nissy_applymoves(args->cube, args->str_moves, result); 258 ret = nissy_applymoves(args->cube, args->str_moves, result);
@@ -293,7 +265,7 @@ applymoves_exec(args_t *args)
293static int64_t 265static int64_t
294applytrans_exec(args_t *args) 266applytrans_exec(args_t *args)
295{ 267{
296 char result[22]; 268 char result[NISSY_SIZE_CUBE];
297 int64_t ret; 269 int64_t ret;
298 270
299 ret = nissy_applytrans(args->cube, args->str_trans, result); 271 ret = nissy_applytrans(args->cube, args->str_trans, result);
@@ -311,20 +283,6 @@ frommoves_exec(args_t *args)
311} 283}
312 284
313static int64_t 285static int64_t
314convert_exec(args_t *args)
315{
316 char result[PRINTCUBE_BUFFER_SIZE];
317 int64_t ret;
318
319 ret = nissy_convert(args->str_format_in, args->str_format_out,
320 args->str_cube, PRINTCUBE_BUFFER_SIZE, result);
321 if (ret == NISSY_OK || ret == NISSY_WARNING_UNSOLVABLE)
322 printf("%s\n", result);
323
324 return ret;
325}
326
327static int64_t
328randomcube_exec(args_t *args) 286randomcube_exec(args_t *args)
329{ 287{
330 char result[PRINTCUBE_BUFFER_SIZE]; 288 char result[PRINTCUBE_BUFFER_SIZE];
@@ -575,9 +533,6 @@ parse_args(int argc, char **argv, args_t *args)
575 .cube = "", 533 .cube = "",
576 .cube_perm = "", 534 .cube_perm = "",
577 .str_cube = "", 535 .str_cube = "",
578 .str_format = "",
579 .str_format_in = "",
580 .str_format_out = "",
581 .str_moves = "", 536 .str_moves = "",
582 .str_trans = "", 537 .str_trans = "",
583 .str_solver = "", 538 .str_solver = "",
@@ -668,7 +623,7 @@ parse_nisstype(const char *arg)
668static bool 623static bool
669set_cube(int argc, char **argv, args_t *args) 624set_cube(int argc, char **argv, args_t *args)
670{ 625{
671 memcpy(args->cube, argv[0], 22); 626 memcpy(args->cube, argv[0], NISSY_SIZE_CUBE);
672 args->cube[21] = 0; 627 args->cube[21] = 0;
673 628
674 return true; 629 return true;
@@ -677,7 +632,7 @@ set_cube(int argc, char **argv, args_t *args)
677static bool 632static bool
678set_cube_perm(int argc, char **argv, args_t *args) 633set_cube_perm(int argc, char **argv, args_t *args)
679{ 634{
680 memcpy(args->cube_perm, argv[0], 22); 635 memcpy(args->cube_perm, argv[0], NISSY_SIZE_CUBE);
681 args->cube_perm[21] = 0; 636 args->cube_perm[21] = 0;
682 637
683 return true; 638 return true;
@@ -700,30 +655,6 @@ set_str_cube(int argc, char **argv, args_t *args)
700} 655}
701 656
702static bool 657static bool
703set_str_format(int argc, char **argv, args_t *args)
704{
705 args->str_format = argv[0];
706
707 return true;
708}
709
710static bool
711set_str_format_in(int argc, char **argv, args_t *args)
712{
713 args->str_format_in = argv[0];
714
715 return true;
716}
717
718static bool
719set_str_format_out(int argc, char **argv, args_t *args)
720{
721 args->str_format_out = argv[0];
722
723 return true;
724}
725
726static bool
727set_str_moves(int argc, char **argv, args_t *args) 658set_str_moves(int argc, char **argv, args_t *args)
728{ 659{
729 args->str_moves = argv[0]; 660 args->str_moves = argv[0];
diff --git a/src/core/core.h b/src/core/core.h
index de1c198..fce1751 100644
--- a/src/core/core.h
+++ b/src/core/core.h
@@ -1,5 +1,4 @@
1#include "constant_cubes.h" 1#include "constant_cubes.h"
2#include "cube.h" 2#include "cube.h"
3#include "io_formats.h"
4#include "moves.h" 3#include "moves.h"
5#include "transform.h" 4#include "transform.h"
diff --git a/src/core/cube.h b/src/core/cube.h
index ce8a6b8..798c99c 100644
--- a/src/core/cube.h
+++ b/src/core/cube.h
@@ -174,3 +174,193 @@ getcube(int64_t ep, int64_t eo, int64_t cp, int64_t co)
174 174
175 return cubefromarray(carr, earr); 175 return cubefromarray(carr, earr);
176} 176}
177
178
179/******************************************************************************/
180
181STATIC cube_t readcube(const char *, const char *);
182STATIC int64_t writecube(const char *, cube_t, size_t n, char [n]);
183STATIC uint8_t readco(const char *);
184STATIC uint8_t readcp(const char *);
185STATIC uint8_t readeo(const char *);
186STATIC uint8_t readep(const char *);
187
188STATIC cube_t readcube_B32(const char *);
189STATIC int64_t writecube_B32(cube_t, size_t n, char [n]);
190
191STATIC uint8_t b32toedge(char);
192STATIC uint8_t b32tocorner(char);
193STATIC char edgetob32(uint8_t);
194STATIC char cornertob32(uint8_t);
195
196STATIC cube_t
197readcube(const char *format, const char *buf)
198{
199 return readcube_B32(buf);
200}
201
202STATIC int64_t
203writecube(const char *format, cube_t cube, size_t buf_size, char buf[buf_size])
204{
205 return writecube_B32(cube, buf_size, buf);
206}
207
208STATIC uint8_t
209readco(const char *str)
210{
211 if (*str == '0')
212 return 0;
213 if (*str == '1')
214 return CTWIST_CW;
215 if (*str == '2')
216 return CTWIST_CCW;
217
218 LOG("Error reading CO\n");
219 return UINT8_ERROR;
220}
221
222STATIC uint8_t
223readcp(const char *str)
224{
225 uint8_t c;
226
227 for (c = 0; c < 8; c++)
228 if (!strncmp(str, cornerstr[c], 3) ||
229 !strncmp(str, cornerstralt[c], 3))
230 return c;
231
232 LOG("Error reading CP\n");
233 return UINT8_ERROR;
234}
235
236STATIC uint8_t
237readeo(const char *str)
238{
239 if (*str == '0')
240 return 0;
241 if (*str == '1')
242 return EFLIP;
243
244 LOG("Error reading EO\n");
245 return UINT8_ERROR;
246}
247
248STATIC uint8_t
249readep(const char *str)
250{
251 uint8_t e;
252
253 for (e = 0; e < 12; e++)
254 if (!strncmp(str, edgestr[e], 2))
255 return e;
256
257 LOG("Error reading EP\n");
258 return UINT8_ERROR;
259}
260
261STATIC cube_t
262readcube_B32(const char *buf)
263{
264 int i;
265 uint8_t c[8], e[12];
266
267 for (i = 0; i < 8; i++) {
268 c[i] = b32tocorner(buf[i]);
269 if (c[i] == UINT8_ERROR) {
270 LOG("Error reading B32 corner %d ", i);
271 if (buf[i] == 0) {
272 LOG("(string terminated early)\n");
273 } else {
274 LOG("(char '%c')\n", buf[i]);
275 }
276 return ZERO_CUBE;
277 }
278 }
279
280 if (buf[8] != '=') {
281 LOG("Error reading B32 separator: a single '=' "
282 "must be used to separate edges and corners\n");
283 return ZERO_CUBE;
284 }
285
286 for (i = 0; i < 12; i++) {
287 e[i] = b32toedge(buf[i+9]);
288 if (e[i] == UINT8_ERROR) {
289 LOG("Error reading B32 edge %d ", i);
290 if (buf[i+9] == 0) {
291 LOG("(string terminated early)\n");
292 } else {
293 LOG("(char '%c')\n", buf[i+9]);
294 }
295 return ZERO_CUBE;
296 }
297 }
298
299 return cubefromarray(c, e);
300}
301
302STATIC int64_t
303writecube_B32(cube_t cube, size_t buf_size, char buf[buf_size])
304{
305 int i;
306 uint8_t corner[8], edge[12];
307
308 if (buf_size < NISSY_SIZE_CUBE) {
309 LOG("Cannot write cube: buffer size must be at least %u "
310 "bytes, but the provided one is %zu bytes.\n",
311 NISSY_SIZE_CUBE, buf_size);
312 return NISSY_ERROR_BUFFER_SIZE;
313 }
314
315 pieces(&cube, corner, edge);
316
317 for (i = 0; i < 8; i++)
318 buf[i] = cornertob32(corner[i]);
319
320 buf[8] = '=';
321
322 for (i = 0; i < 12; i++)
323 buf[i+9] = edgetob32(edge[i]);
324
325 buf[21] = '\0';
326
327 return NISSY_OK;
328}
329
330STATIC uint8_t
331b32toedge(char c)
332{
333 if (!((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'f')))
334 return UINT8_ERROR;
335
336 return c <= 'Z' ? (uint8_t)(c - 'A') : (uint8_t)(c - 'a') + 26;
337}
338
339STATIC uint8_t
340b32tocorner(char c) {
341 uint8_t val;
342
343 if (!((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'f')))
344 return UINT8_ERROR;
345
346 val = c <= 'Z' ? (uint8_t)(c - 'A') : (uint8_t)(c - 'a') + 26;
347
348 return (val & 7) | ((val & 24) << 2);
349}
350
351STATIC char
352edgetob32(uint8_t edge)
353{
354 return edge < 26 ? 'A' + (char)edge : 'a' + (char)(edge - 26);
355}
356
357STATIC char
358cornertob32(uint8_t corner)
359{
360 uint8_t val;
361
362 val = (corner & 7) | ((corner & 96) >> 2);
363
364 return val < 26 ? 'A' + (char)val : 'a' + (char)(val - 26);
365}
366/******************************************************************************/
diff --git a/src/nissy.c b/src/nissy.c
index dfa1a90..fb3cc11 100644
--- a/src/nissy.c
+++ b/src/nissy.c
@@ -17,7 +17,7 @@ long long parse_h48_solver(
17STATIC bool checkdata(const unsigned char *, const tableinfo_t [static 1]); 17STATIC bool checkdata(const unsigned char *, const tableinfo_t [static 1]);
18STATIC bool distribution_equal(const uint64_t [static INFO_DISTRIBUTION_LEN], 18STATIC bool distribution_equal(const uint64_t [static INFO_DISTRIBUTION_LEN],
19 const uint64_t [static INFO_DISTRIBUTION_LEN], uint8_t); 19 const uint64_t [static INFO_DISTRIBUTION_LEN], uint8_t);
20STATIC long long write_result(cube_t, char [static NISSY_SIZE_B32]); 20STATIC long long write_result(cube_t, char [static NISSY_SIZE_CUBE]);
21STATIC size_t my_strnlen(const char *, size_t); 21STATIC size_t my_strnlen(const char *, size_t);
22STATIC long long nissy_dataid(const char *, char [static NISSY_SIZE_DATAID]); 22STATIC long long nissy_dataid(const char *, char [static NISSY_SIZE_DATAID]);
23STATIC long long nissy_gendata_unsafe( 23STATIC long long nissy_gendata_unsafe(
@@ -117,9 +117,9 @@ distribution_equal(
117} 117}
118 118
119STATIC long long 119STATIC long long
120write_result(cube_t cube, char result[static NISSY_SIZE_B32]) 120write_result(cube_t cube, char result[static NISSY_SIZE_CUBE])
121{ 121{
122 writecube("B32", cube, NISSY_SIZE_B32, result); 122 writecube("B32", cube, NISSY_SIZE_CUBE, result);
123 123
124 if (!issolvable(cube)) { 124 if (!issolvable(cube)) {
125 LOG("Warning: resulting cube is not solvable\n"); 125 LOG("Warning: resulting cube is not solvable\n");
@@ -143,9 +143,9 @@ my_strnlen(const char *str, size_t maxlen)
143 143
144long long 144long long
145nissy_compose( 145nissy_compose(
146 const char cube[static NISSY_SIZE_B32], 146 const char cube[static NISSY_SIZE_CUBE],
147 const char permutation[static NISSY_SIZE_B32], 147 const char permutation[static NISSY_SIZE_CUBE],
148 char result[static NISSY_SIZE_B32] 148 char result[static NISSY_SIZE_CUBE]
149) 149)
150{ 150{
151 cube_t c, p, res; 151 cube_t c, p, res;
@@ -178,14 +178,14 @@ nissy_compose(
178 return write_result(res, result); 178 return write_result(res, result);
179 179
180nissy_compose_error: 180nissy_compose_error:
181 writecube("B32", ZERO_CUBE, NISSY_SIZE_B32, result); 181 writecube("B32", ZERO_CUBE, NISSY_SIZE_CUBE, result);
182 return err; 182 return err;
183} 183}
184 184
185long long 185long long
186nissy_inverse( 186nissy_inverse(
187 const char cube[static NISSY_SIZE_B32], 187 const char cube[static NISSY_SIZE_CUBE],
188 char result[static NISSY_SIZE_B32] 188 char result[static NISSY_SIZE_CUBE]
189) 189)
190{ 190{
191 cube_t c, res; 191 cube_t c, res;
@@ -210,15 +210,15 @@ nissy_inverse(
210 return write_result(res, result); 210 return write_result(res, result);
211 211
212nissy_inverse_error: 212nissy_inverse_error:
213 writecube("B32", ZERO_CUBE, NISSY_SIZE_B32, result); 213 writecube("B32", ZERO_CUBE, NISSY_SIZE_CUBE, result);
214 return err; 214 return err;
215} 215}
216 216
217long long 217long long
218nissy_applymoves( 218nissy_applymoves(
219 const char cube[static NISSY_SIZE_B32], 219 const char cube[static NISSY_SIZE_CUBE],
220 const char *moves, 220 const char *moves,
221 char result[static NISSY_SIZE_B32] 221 char result[static NISSY_SIZE_CUBE]
222) 222)
223{ 223{
224 cube_t c, res; 224 cube_t c, res;
@@ -249,15 +249,15 @@ nissy_applymoves(
249 return write_result(res, result); 249 return write_result(res, result);
250 250
251nissy_applymoves_error: 251nissy_applymoves_error:
252 writecube("B32", ZERO_CUBE, NISSY_SIZE_B32, result); 252 writecube("B32", ZERO_CUBE, NISSY_SIZE_CUBE, result);
253 return err; 253 return err;
254} 254}
255 255
256long long 256long long
257nissy_applytrans( 257nissy_applytrans(
258 const char cube[static NISSY_SIZE_B32], 258 const char cube[static NISSY_SIZE_CUBE],
259 const char transformation[static NISSY_SIZE_TRANSFORMATION], 259 const char transformation[static NISSY_SIZE_TRANSFORMATION],
260 char result[static NISSY_SIZE_B32] 260 char result[static NISSY_SIZE_CUBE]
261) 261)
262{ 262{
263 cube_t c, res; 263 cube_t c, res;
@@ -282,51 +282,7 @@ nissy_applytrans(
282 return write_result(res, result); 282 return write_result(res, result);
283 283
284nissy_applytrans_error: 284nissy_applytrans_error:
285 writecube("B32", ZERO_CUBE, NISSY_SIZE_B32, result); 285 writecube("B32", ZERO_CUBE, NISSY_SIZE_CUBE, result);
286 return err;
287}
288
289long long
290nissy_convert(
291 const char *format_in,
292 const char *format_out,
293 const char *cube_string,
294 unsigned result_size,
295 char result[result_size]
296)
297{
298 cube_t c;
299 long long err;
300
301 if (format_in == NULL) {
302 LOG("[convert] Error: 'format_in' argument is NULL\n");
303 err = NISSY_ERROR_NULL_POINTER;
304 goto nissy_convert_error;
305 }
306
307 if (format_out == NULL) {
308 LOG("[convert] Error: 'format_out' argument is NULL\n");
309 err = NISSY_ERROR_NULL_POINTER;
310 goto nissy_convert_error;
311 }
312
313 if (cube_string == NULL) {
314 LOG("[convert] Error: 'cube_string' argument is NULL\n");
315 err = NISSY_ERROR_NULL_POINTER;
316 goto nissy_convert_error;
317 }
318
319 c = readcube(format_in, cube_string);
320
321 if (!isconsistent(c)) {
322 err = NISSY_ERROR_INVALID_CUBE;
323 goto nissy_convert_error;
324 }
325
326 return writecube(format_out, c, result_size, result);
327
328nissy_convert_error:
329 result[0] = '\0';
330 return err; 286 return err;
331} 287}
332 288
@@ -337,7 +293,7 @@ nissy_getcube(
337 long long cp, 293 long long cp,
338 long long co, 294 long long co,
339 const char *options, 295 const char *options,
340 char result[static NISSY_SIZE_B32] 296 char result[static NISSY_SIZE_CUBE]
341) 297)
342{ 298{
343 int i; 299 int i;
@@ -526,7 +482,7 @@ nissy_checkdata(
526 482
527long long 483long long
528nissy_solve( 484nissy_solve(
529 const char cube[static NISSY_SIZE_B32], 485 const char cube[static NISSY_SIZE_CUBE],
530 const char *solver, 486 const char *solver,
531 unsigned nissflag, 487 unsigned nissflag,
532 unsigned minmoves, 488 unsigned minmoves,
diff --git a/src/nissy.h b/src/nissy.h
index a5b3015..963571f 100644
--- a/src/nissy.h
+++ b/src/nissy.h
@@ -5,12 +5,11 @@ All the functions return 0 or a positive integer in case of success and
5a negative integer in case of error, unless otherwise specified. See at 5a negative integer in case of error, unless otherwise specified. See at
6the bottom of this file for the list of error codes and their meaning. 6the bottom of this file for the list of error codes and their meaning.
7 7
8All cube arguments are in B32 formats, unless otherwise specified. 8TODO: explain cube format
9Other available formats are H48 and SRC. See README.md for more info on
10these formats.
11 9
12Accepted moves are U, D, R, L, F and B, optionally followed by a 2, 10Accepted moves are U, D, R, L, F and B, optionally followed by a 2,
13a ' or a 3. 11a ' or a 3.
12TODO update when we accept also wide moves, slices and rotations
14 13
15A transformation must be given in the format 14A transformation must be given in the format
16 (rotation|mirrored) (2 letters) 15 (rotation|mirrored) (2 letters)
@@ -21,9 +20,7 @@ for example 'rotation UF' or 'mirrored BL'.
21/* Constants *****************************************************************/ 20/* Constants *****************************************************************/
22 21
23/* Some constants for size for I/O buffers */ 22/* Some constants for size for I/O buffers */
24#define NISSY_SIZE_B32 22U 23#define NISSY_SIZE_CUBE 24U
25#define NISSY_SIZE_H48 88U
26#define NISSY_SIZE_CUBE_MAX NISSY_SIZE_H48
27#define NISSY_SIZE_TRANSFORMATION 12U 24#define NISSY_SIZE_TRANSFORMATION 12U
28#define NISSY_SIZE_SOLVE_STATS 10U 25#define NISSY_SIZE_SOLVE_STATS 10U
29#define NISSY_SIZE_DATAID 255U 26#define NISSY_SIZE_DATAID 255U
@@ -37,8 +34,8 @@ for example 'rotation UF' or 'mirrored BL'.
37#define NISSY_NISSFLAG_ALL \ 34#define NISSY_NISSFLAG_ALL \
38 (NISSY_NISSFLAG_NORMAL | NISSY_NISSFLAG_INVERSE | NISSY_NISSFLAG_MIXED) 35 (NISSY_NISSFLAG_NORMAL | NISSY_NISSFLAG_INVERSE | NISSY_NISSFLAG_MIXED)
39 36
40/* The solved cube in B32 format */ 37/* The solved cube */
41#define NISSY_SOLVED_CUBE "ABCDEFGH=ABCDEFGHIJKL" 38#define NISSY_SOLVED_CUBE "ABCDEFGH=ABCDEFGHIJKL=A"
42 39
43/* Error codes ***************************************************************/ 40/* Error codes ***************************************************************/
44 41
@@ -58,8 +55,7 @@ provided an unsolvable cube as input.
58 55
59/* 56/*
60The value NISSY_ERROR_INVALID_CUBE means that the provided cube is 57The value NISSY_ERROR_INVALID_CUBE means that the provided cube is
61invalid. It could be written in an unknown format, or in a format 58invalid. It could be written in an unknown format, or be ill-formed.
62different from what specified, or simply ill-formed.
63*/ 59*/
64#define NISSY_ERROR_INVALID_CUBE -10LL 60#define NISSY_ERROR_INVALID_CUBE -10LL
65 61
@@ -85,12 +81,6 @@ is invalid.
85#define NISSY_ERROR_INVALID_TRANS -30LL 81#define NISSY_ERROR_INVALID_TRANS -30LL
86 82
87/* 83/*
88The value NISSY_ERROR_INVALID_FORMAT means that the given format is
89not known.
90*/
91#define NISSY_ERROR_INVALID_FORMAT -40LL
92
93/*
94The value NISSY_ERROR_INVALID_SOLVER means that the given solver is 84The value NISSY_ERROR_INVALID_SOLVER means that the given solver is
95not known. 85not known.
96*/ 86*/
@@ -139,10 +129,10 @@ of this kind to sebastiano@tronto.net. Thanks!
139Apply the secod argument as a permutation on the first argument. 129Apply the secod argument as a permutation on the first argument.
140 130
141Parameters: 131Parameters:
142 cube - The first cube, in B32 format. 132 cube - The first cube.
143 permutation - The second cube, in B32 format. This cube is treated as a 133 permutation - The second cub. This cube is treated as a permutation and
144 permutation and "applied" to the first cube. 134 "applied" to the first cube.
145 result - The return parameter for the resulting cube, in B32 format. 135 result - The return parameter for the resulting cube.
146 136
147Return values: 137Return values:
148 NISSY_OK - The cubes were composed succesfully. 138 NISSY_OK - The cubes were composed succesfully.
@@ -155,17 +145,17 @@ Return values:
155*/ 145*/
156long long 146long long
157nissy_compose( 147nissy_compose(
158 const char cube[static NISSY_SIZE_B32], 148 const char cube[static NISSY_SIZE_CUBE],
159 const char permutation[static NISSY_SIZE_B32], 149 const char permutation[static NISSY_SIZE_CUBE],
160 char result[static NISSY_SIZE_B32] 150 char result[static NISSY_SIZE_CUBE]
161); 151);
162 152
163/* 153/*
164Compute the inverse of the given cube. 154Compute the inverse of the given cube.
165 155
166Parameters: 156Parameters:
167 cube - The cube to be inverted, in B32 format. 157 cube - The cube to be inverted.
168 result - The return parameter for the resulting cube, in B32 format. 158 result - The return parameter for the resulting cube.
169 159
170Return values: 160Return values:
171 NISSY_OK - The cube was inverted succesfully. 161 NISSY_OK - The cube was inverted succesfully.
@@ -177,17 +167,17 @@ Return values:
177*/ 167*/
178long long 168long long
179nissy_inverse( 169nissy_inverse(
180 const char cube[static NISSY_SIZE_B32], 170 const char cube[static NISSY_SIZE_CUBE],
181 char result[static NISSY_SIZE_B32] 171 char result[static NISSY_SIZE_CUBE]
182); 172);
183 173
184/* 174/*
185Apply the given sequence of moves on the given cube. 175Apply the given sequence of moves on the given cube.
186 176
187Parameters: 177Parameters:
188 cube - The cube to move, in B32 format. 178 cube - The cube to move.
189 moves - The moves to apply to the cube. Must be a NULL-terminated string. 179 moves - The moves to apply to the cube. Must be a NULL-terminated string.
190 result - The return parameter for the resulting cube, in B32 format. 180 result - The return parameter for the resulting cube.
191 181
192Return values: 182Return values:
193 NISSY_OK - The moves were applied succesfully. 183 NISSY_OK - The moves were applied succesfully.
@@ -200,18 +190,18 @@ Return values:
200*/ 190*/
201long long 191long long
202nissy_applymoves( 192nissy_applymoves(
203 const char cube[static NISSY_SIZE_B32], 193 const char cube[static NISSY_SIZE_CUBE],
204 const char *moves, 194 const char *moves,
205 char result[static NISSY_SIZE_B32] 195 char result[static NISSY_SIZE_CUBE]
206); 196);
207 197
208/* 198/*
209Apply the single given transformation to the given cube. 199Apply the single given transformation to the given cube.
210 200
211Parameters: 201Parameters:
212 cube - The cube to be transformed, in B32 format. 202 cube - The cube to be transformed.
213 transformation - The transformation in (rotation|mirrored) xy format. 203 transformation - The transformation in "(rotation|mirrored) __" format.
214 result - The return parameter for the resulting cube, in B32 format. 204 result - The return parameter for the resulting cube.
215 205
216Return values: 206Return values:
217 NISSY_OK - The transformation was performed succesfully. 207 NISSY_OK - The transformation was performed succesfully.
@@ -222,37 +212,9 @@ Return values:
222*/ 212*/
223long long 213long long
224nissy_applytrans( 214nissy_applytrans(
225 const char cube[static NISSY_SIZE_B32], 215 const char cube[static NISSY_SIZE_CUBE],
226 const char transformation[static NISSY_SIZE_TRANSFORMATION], 216 const char transformation[static NISSY_SIZE_TRANSFORMATION],
227 char result[static NISSY_SIZE_B32] 217 char result[static NISSY_SIZE_CUBE]
228);
229
230/*
231Convert the given cube between the two given formats.
232
233Parameters:
234 format_in - The input format.
235 format_out - The output format.
236 cube_string - The cube, in format_in format.
237 result_size - The allocated size of the result array.
238 result - Return parameter for the cube in format_out format.
239
240Return values:
241 NISSY_OK - The conversion was performed succesfully.
242 NISSY_ERROR_BUFFER_SIZE - The given buffer is too small for the result.
243 NISSY_ERROR_INVALID_CUBE - The given cube is invalid.
244 NISSY_ERROR_INVALID_FORMAT - At least one of the given formats is invalid.
245 NISSY_ERROR_UNKNOWN - An unknown error occurred.
246 NISSY_ERROR_NULL_POINTER - At least one of 'format_in', 'format_out' or
247 'cube_string' arguments is NULL.
248*/
249long long
250nissy_convert(
251 const char *format_in,
252 const char *format_out,
253 const char *cube_string,
254 unsigned result_size,
255 char result[result_size]
256); 218);
257 219
258/* 220/*
@@ -267,7 +229,7 @@ Parameters:
267 cp - The corner permutation, 0 <= cp <= 40320 (8!) 229 cp - The corner permutation, 0 <= cp <= 40320 (8!)
268 co - The corner orientation, 0 <= co <= 2187 (3^7) 230 co - The corner orientation, 0 <= co <= 2187 (3^7)
269 options - Other options. 231 options - Other options.
270 result - The return parameter for the resulting cube, in B32 format. 232 result - The return parameter for the resulting cube.
271 233
272Return values: 234Return values:
273 NISSY_OK - The cube was generated succesfully. 235 NISSY_OK - The cube was generated succesfully.
@@ -281,7 +243,7 @@ nissy_getcube(
281 long long cp, 243 long long cp,
282 long long co, 244 long long co,
283 const char *options, 245 const char *options,
284 char result[static NISSY_SIZE_B32] 246 char result[static NISSY_SIZE_CUBE]
285); 247);
286 248
287/* 249/*
@@ -354,7 +316,7 @@ nissy_checkdata(
354Solve the given cube using the given solver and options. 316Solve the given cube using the given solver and options.
355 317
356Parameters: 318Parameters:
357 cube - The cube to solver, in B32 format. 319 cube - The cube to solver.
358 solver - The name of the solver. 320 solver - The name of the solver.
359 nissflag - The flags for NISS (linear, inverse, mixed, or combinations). 321 nissflag - The flags for NISS (linear, inverse, mixed, or combinations).
360 minmoves - The minimum number of moves for a solution. 322 minmoves - The minimum number of moves for a solution.
@@ -386,7 +348,7 @@ Return values:
386*/ 348*/
387long long 349long long
388nissy_solve( 350nissy_solve(
389 const char cube[static NISSY_SIZE_B32], 351 const char cube[static NISSY_SIZE_CUBE],
390 const char *solver, 352 const char *solver,
391 unsigned nissflag, 353 unsigned nissflag,
392 unsigned minmoves, 354 unsigned minmoves,
diff --git a/tools/300_solve_small/solve_small.c b/tools/300_solve_small/solve_small.c
index 2efbcb5..dcd47c1 100644
--- a/tools/300_solve_small/solve_small.c
+++ b/tools/300_solve_small/solve_small.c
@@ -25,7 +25,7 @@ void run(void) {
25 int i; 25 int i;
26 int64_t n; 26 int64_t n;
27 long long stats[NISSY_SIZE_SOLVE_STATS]; 27 long long stats[NISSY_SIZE_SOLVE_STATS];
28 char sol[SOL_BUFFER_LEN], cube[22]; 28 char sol[SOL_BUFFER_LEN], cube[NISSY_SIZE_CUBE];
29 29
30 printf("Solved the following scrambles:\n\n"); 30 printf("Solved the following scrambles:\n\n");
31 for (i = 0; scrambles[i] != NULL; i++) { 31 for (i = 0; scrambles[i] != NULL; i++) {
diff --git a/tools/301_solve_file/solve_file.c b/tools/301_solve_file/solve_file.c
index fcc018d..d9084fd 100644
--- a/tools/301_solve_file/solve_file.c
+++ b/tools/301_solve_file/solve_file.c
@@ -12,7 +12,7 @@ char scrambles[MAX_SCR][MAX_SCR_LEN];
12void run(void) { 12void run(void) {
13 int64_t i, nsols; 13 int64_t i, nsols;
14 long long stats[NISSY_SIZE_SOLVE_STATS]; 14 long long stats[NISSY_SIZE_SOLVE_STATS];
15 char sol[SOL_BUFFER_LEN], cube[22]; 15 char sol[SOL_BUFFER_LEN], cube[NISSY_SIZE_CUBE];
16 16
17 printf("Solved the following scrambles:\n\n"); 17 printf("Solved the following scrambles:\n\n");
18 for (i = 0; i < N; i++) { 18 for (i = 0; i < N; i++) {
diff --git a/tools/302_solve_multisol/solve_multisol.c b/tools/302_solve_multisol/solve_multisol.c
index f6057d7..a2896a9 100644
--- a/tools/302_solve_multisol/solve_multisol.c
+++ b/tools/302_solve_multisol/solve_multisol.c
@@ -18,7 +18,7 @@ void run(void) {
18 int i; 18 int i;
19 int64_t n; 19 int64_t n;
20 long long stats[NISSY_SIZE_SOLVE_STATS]; 20 long long stats[NISSY_SIZE_SOLVE_STATS];
21 char sol[SOL_BUFFER_LEN], cube[22]; 21 char sol[SOL_BUFFER_LEN], cube[NISSY_SIZE_CUBE];
22 22
23 printf("Solved the following scrambles:\n\n"); 23 printf("Solved the following scrambles:\n\n");
24 for (i = 0; scrambles[i] != NULL; i++) { 24 for (i = 0; scrambles[i] != NULL; i++) {
diff --git a/tools/400_solvetest/solve_test.c b/tools/400_solvetest/solve_test.c
index a724320..1bfe851 100644
--- a/tools/400_solvetest/solve_test.c
+++ b/tools/400_solvetest/solve_test.c
@@ -45,7 +45,7 @@ void run(void) {
45 int i; 45 int i;
46 int64_t n; 46 int64_t n;
47 long long stats[NISSY_SIZE_SOLVE_STATS]; 47 long long stats[NISSY_SIZE_SOLVE_STATS];
48 char sol[SOL_BUFFER_LEN], cube[22]; 48 char sol[SOL_BUFFER_LEN], cube[NISSY_SIZE_CUBE];
49 49
50 for (i = 0; s[i].scramble[0]; i++) { 50 for (i = 0; s[i].scramble[0]; i++) {
51 printf("\n%d. %s\n", i, s[i].scramble); 51 printf("\n%d. %s\n", i, s[i].scramble);
diff --git a/src/core/io_formats.h b/utils/convert.c
index f5668d4..4f4bb8c 100644
--- a/src/core/io_formats.h
+++ b/utils/convert.c
@@ -1,3 +1,9 @@
1/*
2This file contains code related to cube format conversion that used to
3be in src/core. It is to be adapted into a standalone tool for cube
4format conversion.
5*/
6
1STATIC cube_t readcube(const char *, const char *); 7STATIC cube_t readcube(const char *, const char *);
2STATIC int64_t writecube(const char *, cube_t, size_t n, char [n]); 8STATIC int64_t writecube(const char *, cube_t, size_t n, char [n]);
3STATIC void log_available_formats(void); 9STATIC void log_available_formats(void);
diff --git a/utils/genmovecode.sh b/utils/genmovecode.sh
deleted file mode 100755
index cf13441..0000000
--- a/utils/genmovecode.sh
+++ /dev/null
@@ -1,15 +0,0 @@
1#!/bin/sh
2
3cc -DDEBUG h48_to_lst.c ../src/nissy.c -o h48_to_lst
4
5gen() {
6 for f in cubes/move_??_*.txt; do
7 move="$(echo "$f" | sed 's/.*_// ; s/\.txt//')"
8 printf '#define _move_cube_%s fastcube( \\\n ' "$move"
9 ./h48_to_lst <"$f"
10 printf ')\n'
11 done
12}
13
14gen
15rm -f h48_to_lst invert
diff --git a/utils/genmoveswitch.sh b/utils/genmoveswitch.sh
deleted file mode 100755
index 3b2a74b..0000000
--- a/utils/genmoveswitch.sh
+++ /dev/null
@@ -1,8 +0,0 @@
1#!/bin/sh
2
3printf '\tswitch (m) {\n'
4for f in cubes/move_??_*.txt; do
5 t="$(echo "$f" | sed 's/.*_// ; s/\.txt//')"
6 printf '\tcase %s:\n\t\treturn _move(%s, c);\n' "$t" "$t"
7done
8printf '\t}\n'
diff --git a/utils/gentranscode.sh b/utils/gentranscode.sh
deleted file mode 100755
index 9a1de2c..0000000
--- a/utils/gentranscode.sh
+++ /dev/null
@@ -1,25 +0,0 @@
1#!/bin/sh
2
3cc -DDEBUG h48_to_lst.c ../src/nissy.c -o h48_to_lst
4cc -DDEBUG invert.c ../src/nissy.c -o invert
5
6lineavx() { printf '#define _trans_cube_%s ' "$1"; }
7linesrc() { printf '_static cube_fast_t _trans_cube_%s = ' "$1"; }
8sedavx() { sed '1,2s/$/ \\/ ; 3s/$/)/ ; 3q'; }
9sedsrc() { sed '3s/$/ };/ ; 3q'; }
10
11gen() {
12 for f in cubes/transform_??_???.txt; do
13 trans="$(echo "$f" | sed 's/.*_// ; s/\.txt//')"
14 printf '#define _trans_cube_%s fastcube( \\\n ' "$trans"
15 ./h48_to_lst <"$f"
16 printf ')\n'
17 printf '#define _trans_cube_%s_inverse fastcube( \\\n ' \
18 "$trans"
19 ./invert <"$f" | ./h48_to_lst
20 printf ')\n'
21 done
22}
23
24gen
25rm -f h48_to_lst invert
diff --git a/utils/gentransswitch.sh b/utils/gentransswitch.sh
deleted file mode 100755
index 20e2bfb..0000000
--- a/utils/gentransswitch.sh
+++ /dev/null
@@ -1,14 +0,0 @@
1#!/bin/sh
2
3printf '\tswitch (t) {\n'
4for f in cubes/transform_??_???.txt; do
5 t="$(echo "$f" | sed 's/.*_// ; s/\.txt//')"
6 mirror_or_rotation="$(echo "$t" | grep m)"
7 if [ -z "$mirror_or_rotation" ]; then
8 m="rotation"
9 else
10 m="mirrored"
11 fi
12 printf '\tcase %s:\n\t\treturn _trans_%s(%s, c);\n' "$t" "$m" "$t"
13done
14printf '\t}\n'
diff --git a/utils/gentranstests.sh b/utils/gentranstests.sh
deleted file mode 100755
index a257a0a..0000000
--- a/utils/gentranstests.sh
+++ /dev/null
@@ -1,35 +0,0 @@
1#!/bin/sh
2
3outdir="./generated_trans_tests"
4
5mkdir -p "$outdir"
6i=100
7
8while read -r line; do
9 [ -z "$line" ] && continue
10
11 trans_piece="$(echo "$line" | awk '{print $1}' | tr -d 'rm')"
12 move1="$(echo "$line" | awk '{print $2}')"
13 move2="$(echo "$line" | awk '{print $3}')"
14
15 rotation="rotation $trans_piece"
16
17 file1="$(ls cubes | grep "move_.*_${move1}.txt")"
18 file2="$(ls cubes | grep "move_.*_${move2}.txt")"
19 echo "$rotation" >"$outdir/${i}_${trans_piece}r_${move1}.in"
20 cat "cubes/$file1" >>"$outdir/${i}_${trans_piece}r_${move1}.in"
21 cp "cubes/$file2" "$outdir/${i}_${trans_piece}r_${move1}.out"
22
23 i=$((i+1))
24
25 mirrored="mirrored $trans_piece"
26 move2m="$(echo "${move2}" | tr 'LR' 'RL')3"
27
28 file1="$(ls cubes | grep "move_.*_${move1}.txt")"
29 file2="$(ls cubes | grep "move_.*_${move2m}.txt")"
30 echo "$mirrored" >"$outdir/${i}_${trans_piece}m_${move1}.in"
31 cat "cubes/$file1" >>"$outdir/${i}_${trans_piece}m_${move1}.in"
32 cp "cubes/$file2" "$outdir/${i}_${trans_piece}m_${move1}.out"
33
34 i=$((i+1))
35done <transform_moves.txt
diff --git a/utils/h48_to_lst.c b/utils/h48_to_lst.c
deleted file mode 100644
index 03265b7..0000000
--- a/utils/h48_to_lst.c
+++ /dev/null
@@ -1,22 +0,0 @@
1#include <stdio.h>
2#include <inttypes.h>
3#include <stdbool.h>
4
5#include "../src/nissy.h"
6
7#define STRLENMAX 1000
8
9int main(void) {
10 char strin[STRLENMAX], strout[STRLENMAX];
11 int result;
12
13 fgets(strin, STRLENMAX, stdin);
14
15 result = nissy_convertcube("H48", "LST", strin, strout);
16 if (result)
17 fprintf(stderr, "Error converting cube: code %d\n", result);
18
19 fputs(strout, stdout);
20
21 return 0;
22}
diff --git a/utils/invert.c b/utils/invert.c
deleted file mode 100644
index 41580c0..0000000
--- a/utils/invert.c
+++ /dev/null
@@ -1,19 +0,0 @@
1#include <stdio.h>
2#include <inttypes.h>
3#include <stdbool.h>
4
5#include "../src/nissy.h"
6
7#define STRLENMAX 1000
8
9int main(void) {
10 char str[STRLENMAX], cube[22], inv[22];
11
12 fgets(str, STRLENMAX, stdin);
13 nissy_readcube("H48", str, cube);
14 nissy_inverse(cube, inv);
15 nissy_writecube("H48", inv, str);
16 fputs(str, stdout);
17
18 return 0;
19}
diff --git a/utils/mirror.sh b/utils/mirror.sh
deleted file mode 100755
index 41a434f..0000000
--- a/utils/mirror.sh
+++ /dev/null
@@ -1,3 +0,0 @@
1#!/bin/sh
2
3tr 'LR' 'RL'

Generated with cgit - Back to sebastiano.tronto.net