aboutsummaryrefslogtreecommitdiff
path: root/src/nissy.h
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2025-04-22 14:17:03 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2025-04-22 14:17:03 +0200
commitac652bb6fb45099008e862e3ced650299dc3ebb7 (patch)
tree12fb1c902c271fbeac41c4ee416cf1cd76b16fd7 /src/nissy.h
parent71e104d84b3538e15f27df79b151e6b49cbad1eb (diff)
parente391c4624055138f075c0e5772ccaf8ede094b5a (diff)
downloadnissy-core-ac652bb6fb45099008e862e3ced650299dc3ebb7.tar.gz
nissy-core-ac652bb6fb45099008e862e3ced650299dc3ebb7.zip
Merge branch 'master' into extend_moves
Diffstat (limited to 'src/nissy.h')
-rw-r--r--src/nissy.h102
1 files changed, 32 insertions, 70 deletions
diff --git a/src/nissy.h b/src/nissy.h
index a5b3015..4b2d1eb 100644
--- a/src/nissy.h
+++ b/src/nissy.h
@@ -2,12 +2,11 @@
2This is libnissy (temporarily also known as h48), a Rubik's cube library. 2This is libnissy (temporarily also known as h48), a Rubik's cube library.
3 3
4All the functions return 0 or a positive integer in case of success and 4All 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
6the bottom of this file for the list of error codes and their meaning. 6below for the list of error codes and their meaning.
7 7
8All cube arguments are in B32 formats, unless otherwise specified. 8Cubes are passed as strings in the cccccccc=eeeeeeeeeeee=r format,
9Other available formats are H48 and SRC. See README.md for more info on 9see the README.md file for more information.
10these formats.
11 10
12Accepted moves are U, D, R, L, F and B, optionally followed by a 2, 11Accepted moves are U, D, R, L, F and B, optionally followed by a 2,
13a ' or a 3. 12a ' or a 3.
@@ -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,

Generated with cgit - Back to sebastiano.tronto.net