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 /src/nissy.h | |
| 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 'src/nissy.h')
| -rw-r--r-- | src/nissy.h | 102 |
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 @@ | |||
| 2 | This is libnissy (temporarily also known as h48), a Rubik's cube library. | 2 | This is libnissy (temporarily also known as h48), a Rubik's cube library. |
| 3 | 3 | ||
| 4 | All the functions return 0 or a positive integer in case of success and | 4 | All the functions return 0 or a positive integer in case of success and |
| 5 | a negative integer in case of error, unless otherwise specified. See at | 5 | a negative integer in case of error, unless otherwise specified. See |
| 6 | the bottom of this file for the list of error codes and their meaning. | 6 | below for the list of error codes and their meaning. |
| 7 | 7 | ||
| 8 | All cube arguments are in B32 formats, unless otherwise specified. | 8 | Cubes are passed as strings in the cccccccc=eeeeeeeeeeee=r format, |
| 9 | Other available formats are H48 and SRC. See README.md for more info on | 9 | see the README.md file for more information. |
| 10 | these formats. | ||
| 11 | 10 | ||
| 12 | Accepted moves are U, D, R, L, F and B, optionally followed by a 2, | 11 | Accepted moves are U, D, R, L, F and B, optionally followed by a 2, |
| 13 | a ' or a 3. | 12 | a ' 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 | /* |
| 60 | The value NISSY_ERROR_INVALID_CUBE means that the provided cube is | 57 | The value NISSY_ERROR_INVALID_CUBE means that the provided cube is |
| 61 | invalid. It could be written in an unknown format, or in a format | 58 | invalid. It could be written in an unknown format, or be ill-formed. |
| 62 | different 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 | /* |
| 88 | The value NISSY_ERROR_INVALID_FORMAT means that the given format is | ||
| 89 | not known. | ||
| 90 | */ | ||
| 91 | #define NISSY_ERROR_INVALID_FORMAT -40LL | ||
| 92 | |||
| 93 | /* | ||
| 94 | The value NISSY_ERROR_INVALID_SOLVER means that the given solver is | 84 | The value NISSY_ERROR_INVALID_SOLVER means that the given solver is |
| 95 | not known. | 85 | not known. |
| 96 | */ | 86 | */ |
| @@ -139,10 +129,10 @@ of this kind to sebastiano@tronto.net. Thanks! | |||
| 139 | Apply the secod argument as a permutation on the first argument. | 129 | Apply the secod argument as a permutation on the first argument. |
| 140 | 130 | ||
| 141 | Parameters: | 131 | Parameters: |
| 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 | ||
| 147 | Return values: | 137 | Return 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 | */ |
| 156 | long long | 146 | long long |
| 157 | nissy_compose( | 147 | nissy_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 | /* |
| 164 | Compute the inverse of the given cube. | 154 | Compute the inverse of the given cube. |
| 165 | 155 | ||
| 166 | Parameters: | 156 | Parameters: |
| 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 | ||
| 170 | Return values: | 160 | Return 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 | */ |
| 178 | long long | 168 | long long |
| 179 | nissy_inverse( | 169 | nissy_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 | /* |
| 185 | Apply the given sequence of moves on the given cube. | 175 | Apply the given sequence of moves on the given cube. |
| 186 | 176 | ||
| 187 | Parameters: | 177 | Parameters: |
| 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 | ||
| 192 | Return values: | 182 | Return 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 | */ |
| 201 | long long | 191 | long long |
| 202 | nissy_applymoves( | 192 | nissy_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 | /* |
| 209 | Apply the single given transformation to the given cube. | 199 | Apply the single given transformation to the given cube. |
| 210 | 200 | ||
| 211 | Parameters: | 201 | Parameters: |
| 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 | ||
| 216 | Return values: | 206 | Return 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 | */ |
| 223 | long long | 213 | long long |
| 224 | nissy_applytrans( | 214 | nissy_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 | /* | ||
| 231 | Convert the given cube between the two given formats. | ||
| 232 | |||
| 233 | Parameters: | ||
| 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 | |||
| 240 | Return 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 | */ | ||
| 249 | long long | ||
| 250 | nissy_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 | ||
| 272 | Return values: | 234 | Return 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( | |||
| 354 | Solve the given cube using the given solver and options. | 316 | Solve the given cube using the given solver and options. |
| 355 | 317 | ||
| 356 | Parameters: | 318 | Parameters: |
| 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 | */ |
| 387 | long long | 349 | long long |
| 388 | nissy_solve( | 350 | nissy_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, |
