aboutsummaryrefslogtreecommitdiff
path: root/src/nissy.h
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2024-10-11 12:04:02 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2024-10-11 12:04:02 +0200
commit79c9c600f7a620e3e804ff7783511ad7da7d8f93 (patch)
treec1cfd2320148f6a9d3af67f090e720cf6817eb91 /src/nissy.h
parent5e291466fbbc45aed74f67a1b2e555d1f0c44d8f (diff)
downloadnissy-core-79c9c600f7a620e3e804ff7783511ad7da7d8f93.tar.gz
nissy-core-79c9c600f7a620e3e804ff7783511ad7da7d8f93.zip
Error codes, documentation, change nisstype from string to flags
Diffstat (limited to 'src/nissy.h')
-rw-r--r--src/nissy.h229
1 files changed, 189 insertions, 40 deletions
diff --git a/src/nissy.h b/src/nissy.h
index c78fb50..c019998 100644
--- a/src/nissy.h
+++ b/src/nissy.h
@@ -8,10 +8,9 @@ If you include this file, you should also use the following includes:
8#include <stdbool> 8#include <stdbool>
9#include <string> 9#include <string>
10 10
11All the functions below return 0 in case of success and a positive number 11All the functions return 0 or a positive integer in case of success and
12in case of error, unless otherwise specified. Errors are checked in code 12a negative integer in case of error, unless otherwise specified.
13order: for example if error code 1 is returned then it could that also 13You can see the list of error codes below, or use nissy_explainerror().
14an error with code 2 or higher occurred.
15 14
16Arguments of type char [static 22] denote a cube in B32 format. 15Arguments of type char [static 22] denote a cube in B32 format.
17Other available formats are H48 and SRC. See README.md for more info on 16Other available formats are H48 and SRC. See README.md for more info on
@@ -25,14 +24,48 @@ A transformation must be given in the format
25for example 'rotation UF' or 'mirrored BL'. 24for example 'rotation UF' or 'mirrored BL'.
26*/ 25*/
27 26
27/* Error codes */
28#define NISSY_OK INT64_C(0)
29#define NISSY_WARNING_UNSOLVABLE INT64_C(-1)
30#define NISSY_WARNING_NULL_CALLBACK INT64_C(-2)
31#define NISSY_ERROR_INVALID_CUBE INT64_C(-10)
32#define NISSY_ERROR_UNSOLVABLE_CUBE INT64_C(-11)
33#define NISSY_ERROR_INVALID_MOVES INT64_C(-20)
34#define NISSY_ERROR_INVALID_TRANS INT64_C(-30)
35#define NISSY_ERROR_INVALID_FORMAT INT64_C(-40)
36#define NISSY_ERROR_INVALID_SOLVER INT64_C(-50)
37#define NISSY_ERROR_NULL_POINTER INT64_C(-60)
38#define NISSY_ERROR_DATA INT64_C(-70)
39#define NISSY_ERROR_OPTIONS INT64_C(-80)
40#define NISSY_ERROR_INVALID_CODE INT64_C(-90)
41#define NISSY_ERROR_UNKNOWN INT64_C(-999)
42
43/* Flags for NISS options */
44#define NISSY_NISSFLAG_NORMAL UINT8_C(1)
45#define NISSY_NISSFLAG_INVERSE UINT8_C(2)
46#define NISSY_NISSFLAG_MIXED UINT8_C(4)
47#define NISSY_NISSFLAG_LINEAR \
48 (NISSY_NISSFLAG_NORMAL | NISSY_NISSFLAG_INVERSE)
49#define NISSY_NISSFLAG_ALL \
50 (NISSY_NISSFLAG_NORMAL | NISSY_NISSFLAG_INVERSE | NISSY_NISSFLAG_MIXED)
51
28/* 52/*
29Apply the secod argument as a permutation on the first argument. 53Apply the secod argument as a permutation on the first argument.
30 54
55Parameters:
56 cube - The first cube, in B32 format.
57 permutation - The second cube, in B32 format. This cube is treated as a
58 permutation and "applied" to the first cube.
59 result - The return parameter for the resulting cube, in B32 format.
60
31Return values: 61Return values:
32 0 Valid result 62 NISSY_OK - The cubes were composed succesfully.
33 1 The given cube is invalid 63 NISSY_WARNING_UNSOLVABLE - The resulting cube is not solvable. This is
34 2 The given permutation is invalid 64 either because at least on of the given cubes
35 9 The resulting cube is not solvable 65 was not solvable, or due to an unknown internal
66 error.
67 NISSY_ERROR_INVALID_CUBE - At least one of the given cubes is invalid.
68 NISSY_ERROR_UNKNOWN - An unknown error occurred.
36*/ 69*/
37int64_t nissy_compose( 70int64_t nissy_compose(
38 const char cube[static 22], 71 const char cube[static 22],
@@ -43,10 +76,17 @@ int64_t nissy_compose(
43/* 76/*
44Compute the inverse of the given cube. 77Compute the inverse of the given cube.
45 78
79Parameters:
80 cube - The cube to be inverted, in B32 format.
81 result - The return parameter for the resulting cube, in B32 format.
82
46Return values: 83Return values:
47 0 Valid result 84 NISSY_OK - The cube was inverted succesfully.
48 1 The given cube is invalid 85 NISSY_WARNING_UNSOLVABLE - The resulting cube is not solvable. This is
49 9 The resulting cube is not solvable 86 either because the given cube was not solvable,
87 or due to an unknown internal error.
88 NISSY_ERROR_INVALID_CUBE - The given cube is invalid.
89 NISSY_ERROR_UNKNOWN - An unknown error occurred.
50*/ 90*/
51int64_t nissy_inverse( 91int64_t nissy_inverse(
52 const char cube[static 22], 92 const char cube[static 22],
@@ -56,11 +96,18 @@ int64_t nissy_inverse(
56/* 96/*
57Apply the given sequence of moves on the given cube. 97Apply the given sequence of moves on the given cube.
58 98
99Parameters:
100 cube - The cube to move, in B32 format.
101 moves - The moves to apply to the cube.
102 result - The return parameter for the resulting cube, in B32 format.
103
59Return values: 104Return values:
60 0 Valid result 105 NISSY_OK - The moves were applied succesfully.
61 1 The given cube is invalid 106 NISSY_WARNING_UNSOLVABLE - The resulting cube is not solvable. This is
62 8 The given moves are invalid 107 either because the given cube was not solvable,
63 9 The resulting cube is not solvable 108 or due to an unknown internal error.
109 NISSY_ERROR_INVALID_CUBE - The given cube is invalid.
110 NISSY_ERROR_INVALID_MOVES - The given moves are invalid.
64*/ 111*/
65int64_t nissy_applymoves( 112int64_t nissy_applymoves(
66 const char cube[static 22], 113 const char cube[static 22],
@@ -71,11 +118,17 @@ int64_t nissy_applymoves(
71/* 118/*
72Apply the single given transformation to the given cube. 119Apply the single given transformation to the given cube.
73 120
121Parameters:
122 cube - The cube to be transformed, in B32 format.
123 transformation - The transformation in (rotation|mirrored) xy format.
124 result - The return parameter for the resulting cube, in B32 format.
125
74Return values: 126Return values:
75 0 Valid result 127 NISSY_OK - The transformation was performed succesfully.
76 1 The given cube is invalid 128 NISSY_WARNING_UNSOLVABLE - The resulting cube is not solvable. This is
77 8 The given transformation is invalid 129 probably due to an unknown internal error.
78 9 The resulting cube is not solvable 130 NISSY_ERROR_INVALID_CUBE - The given cube is invalid.
131 NISSY_ERROR_INVALID_TRANS - The given transformation is invalid.
79*/ 132*/
80int64_t nissy_applytrans( 133int64_t nissy_applytrans(
81 const char cube[static 22], 134 const char cube[static 22],
@@ -86,9 +139,15 @@ int64_t nissy_applytrans(
86/* 139/*
87Apply the given moves to the solved cube. 140Apply the given moves to the solved cube.
88 141
142Parameters:
143 moves - The moves to be applied to the solved cube.
144 result - Return parameter for the resulting cube, in B32 format.
145
89Return values: 146Return values:
90 0 Valid result 147 NISSY_OK - The moves were performed succesfully.
91 1 The given moves are invalid 148 NISSY_WARNING_UNSOLVABLE - The resulting cube is not solvable. This is
149 probably due to an unknown internal error.
150 NISSY_ERROR_INVALID_MOVES - The given moves are invalid.
92*/ 151*/
93int64_t nissy_frommoves( 152int64_t nissy_frommoves(
94 const char *moves, 153 const char *moves,
@@ -98,20 +157,45 @@ int64_t nissy_frommoves(
98/* 157/*
99Convert the given cube between the two given formats. 158Convert the given cube between the two given formats.
100 159
160Parameters:
161 format_in - The input format.
162 format_out - The output format.
163 string - The cube, in format_in format.
164 result - Return parameter for the cube in format_out format. Must be
165 large enough to contains the cube in this format.
166
101Return values: 167Return values:
102 0 Valid result 168 NISSY_OK - The conversion was performed succesfully.
103 1 The given cube or format_in is invalid 169 NISSY_ERROR_INVALID_CUBE - The given cube is invalid.
104 2 The resulting cube or format_out is invalid 170 NISSY_ERROR_INVALID_FORMAT - At least one of the given formats is invalid.
105 3 The resulting cube is inconsistent 171 NISSY_ERROR_UNKNOWN - An unknown error occurred.
106*/ 172*/
107int64_t nissy_convert( 173int64_t nissy_convert(
108 const char *format_in, 174 const char *format_in,
109 const char *format_out, 175 const char *format_out,
110 const char *cube_string, 176 const char *cube,
111 char *result 177 char *result
112); 178);
113 179
114/* Get the cube with the given ep, eo, cp and co values. */ 180/*
181Get the cube with the given ep, eo, cp and co values. The values must be in the
182ranges specified below, but if the option "fix" is given any values outside its
183range will be adjusted before using it. The option "fix" also fixes parity and
184orientation issues, resulting always in a solvable cube.
185
186Parameters:
187 ep - The edge permutation, 0 <= ep <= 479001600 (12!)
188 eo - The edge orientation, 0 <= eo <= 2047 (2^11)
189 cp - The corner permutation, 0 <= cp <= 40320 (8!)
190 co - The corner orientation, 0 <= co <= 2187 (3^7)
191 options - Other options.
192 result - The return parameter for the resulting cube, in B32 format.
193
194Return values:
195 NISSY_OK - The cube was generated succesfully.
196 NISSY_WARNING_UNSOLVABLE - The resulting cube is unsolvable.
197 NISSY_ERROR_OPTIONS - One or more of the given parameters is invalid.
198*/
115int64_t nissy_getcube( 199int64_t nissy_getcube(
116 int64_t ep, 200 int64_t ep,
117 int64_t eo, 201 int64_t eo,
@@ -125,9 +209,13 @@ int64_t nissy_getcube(
125Compute the size of the data generated by nissy_gendata, when called with 209Compute the size of the data generated by nissy_gendata, when called with
126the same parameters, or -1 in case of error. 210the same parameters, or -1 in case of error.
127 211
212Parameters:
213 solver - The name of the solver.
214
128Return values: 215Return values:
129 -1 Error 216 NISSY_ERROR_INVALID_SOLVER - The given solver is not known.
130 >=0 The size of the table, in bytes 217 NISSY_ERROR_UNKNOWN - An unknown error occurred.
218 Any value >= 0 - The size of the data, in bytes.
131*/ 219*/
132int64_t nissy_datasize( 220int64_t nissy_datasize(
133 const char *solver 221 const char *solver
@@ -136,38 +224,71 @@ int64_t nissy_datasize(
136/* 224/*
137Compute the data for the given solver and store it in generated_data. 225Compute the data for the given solver and store it in generated_data.
138 226
227Parameters:
228 solver - The name of the solver.
229 data - The return parameter for the generated data. Must be large enoguh
230 to contain the whole data. It is advised to use nissy_datasize to
231 check how much memory is needed.
232
139Return values: 233Return values:
140 -1 Error 234 NISSY_ERROR_INVALID_SOLVER - The given solver is not known.
141 >=0 The size of the table, in bytes 235 NISSY_ERROR_UNKNOWN - An error occurred while generating the data.
236 Any value >= 0 - The size of the data, in bytes.
142*/ 237*/
143int64_t nissy_gendata( 238int64_t nissy_gendata(
144 const char *solver, 239 const char *solver,
145 void *generated_data 240 void *data
146); 241);
147 242
148/* 243/*
149Print information on a data table via the provided callback writer. 244Print information on a data table via the provided callback writer.
150 245
246Parameters:
247 data - The data
248 write - A callback writer with the same signature as printf(3).
249
151Return values: 250Return values:
152 0 No error 251 NISSY_OK - The data is correct.
153 1 The given data could not be read correctly 252 NISSY_ERROR_DATA - The data contains errors.
154*/ 253*/
155int64_t nissy_datainfo( 254int64_t nissy_datainfo(
156 const void *table, 255 const void *data,
157 void (*write)(const char *, ...) 256 void (*write)(const char *, ...)
158); 257);
159 258
160/* 259/*
161Solve the given cube using the given solver and options 260Solve the given cube using the given solver and options.
261
262Parameters:
263 cube - The cube to solver, in B32 format.
264 solver - The name of the solver.
265 nissflag - The flags for NISS (linear, inverse, mixed, or combinations).
266 minmoves - The minimum number of moves for a solution.
267 maxmoves - The maximum number of moves for a solution.
268 maxsolutions - The maximum number of solutions.
269 optimal - If set to a non-negative value, the maximum number of moves
270 above the optimal solution length.
271 data - The data for the solver. Can be computed with gendata.
272 solutions - The return parameter for the solutions. Must be large enough
273 to store all found solutions. The solutions are separated by
274 a '\n' (newline) and a '\0' (NULL character) terminates the
275 list.
276 TODO: replace with callback writer.
162 277
163Return values: 278Return values:
164 -1 Error 279 NISSY_OK - Cube solved succesfully.
165 >=0 The number of solutions found 280 NISSY_ERROR_INVALID_CUBE - The given cube is invalid.
281 NISSY_ERROR_UNSOLVABLE_CUBE - The given cube is valid, but not solvable with
282 the given solver.
283 NISSY_ERROR_OPTIONS - One or more of the given options are invalid.
284 NISSY_ERROR_NULL_POINTER - One of the provided pointers is null.
285 NISSY_ERROR_INVALID_SOLVER - The given solver is not known.
286 Any value >= 0 - The number of solutions found.
166*/ 287*/
167int64_t nissy_solve( 288int64_t nissy_solve(
168 const char cube[static 22], 289 const char cube[static 22],
169 const char *solver, 290 const char *solver,
170 const char *nisstype, /* TODO: remove, use flags */ 291 uint8_t nissflag,
171 int8_t minmoves, 292 int8_t minmoves,
172 int8_t maxmoves, 293 int8_t maxmoves,
173 int64_t maxsolutions, 294 int64_t maxsolutions,
@@ -178,5 +299,33 @@ int64_t nissy_solve(
178 299
179/* 300/*
180Set a global logger function used by this library. 301Set a global logger function used by this library.
302
303Parameters:
304 write - A callback writer with the same signature as printf(3).
305
306Return values:
307 NISSY_OK - Logger set succesfully.
308 NISSY_WARNING_NULL_CALLBACK - The provided callback writer is NULL.
181*/ 309*/
182void nissy_setlogger(void (*logger_function)(const char *, ...)); 310int64_t nissy_setlogger(
311 void (*logger_function)(const char *, ...)
312);
313
314/*
315Print an explanation of the given error code via the provided callback writer.
316
317Parameters:
318 error_code - The error code to be explained. It can be any value returned
319 by a function in this library, not necessarily an error.
320 write - A callback writer with the same signature as printf(3).
321 Must be non-NULL.
322
323Return values:
324 NISSY_OK - The error code is known.
325 NISSY_WARNING_NULL_CALLBACK - The provided callback writer is NULL.
326 NISSY_ERROR_INVALID_CODE - The error code is unknown.
327*/
328int64_t nissy_explainerror(
329 int64_t error_code,
330 void (*write)(const char *, ...)
331);

Generated with cgit - Back to sebastiano.tronto.net