diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2025-04-22 09:00:15 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2025-04-22 09:00:15 +0200 |
| commit | 8b72e391c7185e3da0dfbf0ab60068ac37e4d5cc (patch) | |
| tree | b79d8154f16a0dadd8d8265d32b8bd95e96263aa /src | |
| parent | 510a7471348788fccba6b7c4b9f7b7cc9aee6ba9 (diff) | |
| download | nissy-core-8b72e391c7185e3da0dfbf0ab60068ac37e4d5cc.tar.gz nissy-core-8b72e391c7185e3da0dfbf0ab60068ac37e4d5cc.zip | |
Removed old scripts and updated public API
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/core.h | 1 | ||||
| -rw-r--r-- | src/core/cube.h | 190 | ||||
| -rw-r--r-- | src/core/io_formats.h | 403 | ||||
| -rw-r--r-- | src/nissy.c | 80 | ||||
| -rw-r--r-- | src/nissy.h | 98 |
5 files changed, 238 insertions, 534 deletions
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 | |||
| 181 | STATIC cube_t readcube(const char *, const char *); | ||
| 182 | STATIC int64_t writecube(const char *, cube_t, size_t n, char [n]); | ||
| 183 | STATIC uint8_t readco(const char *); | ||
| 184 | STATIC uint8_t readcp(const char *); | ||
| 185 | STATIC uint8_t readeo(const char *); | ||
| 186 | STATIC uint8_t readep(const char *); | ||
| 187 | |||
| 188 | STATIC cube_t readcube_B32(const char *); | ||
| 189 | STATIC int64_t writecube_B32(cube_t, size_t n, char [n]); | ||
| 190 | |||
| 191 | STATIC uint8_t b32toedge(char); | ||
| 192 | STATIC uint8_t b32tocorner(char); | ||
| 193 | STATIC char edgetob32(uint8_t); | ||
| 194 | STATIC char cornertob32(uint8_t); | ||
| 195 | |||
| 196 | STATIC cube_t | ||
| 197 | readcube(const char *format, const char *buf) | ||
| 198 | { | ||
| 199 | return readcube_B32(buf); | ||
| 200 | } | ||
| 201 | |||
| 202 | STATIC int64_t | ||
| 203 | writecube(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 | |||
| 208 | STATIC uint8_t | ||
| 209 | readco(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 | |||
| 222 | STATIC uint8_t | ||
| 223 | readcp(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 | |||
| 236 | STATIC uint8_t | ||
| 237 | readeo(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 | |||
| 248 | STATIC uint8_t | ||
| 249 | readep(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 | |||
| 261 | STATIC cube_t | ||
| 262 | readcube_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 | |||
| 302 | STATIC int64_t | ||
| 303 | writecube_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 | |||
| 330 | STATIC uint8_t | ||
| 331 | b32toedge(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 | |||
| 339 | STATIC uint8_t | ||
| 340 | b32tocorner(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 | |||
| 351 | STATIC char | ||
| 352 | edgetob32(uint8_t edge) | ||
| 353 | { | ||
| 354 | return edge < 26 ? 'A' + (char)edge : 'a' + (char)(edge - 26); | ||
| 355 | } | ||
| 356 | |||
| 357 | STATIC char | ||
| 358 | cornertob32(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/core/io_formats.h b/src/core/io_formats.h deleted file mode 100644 index f5668d4..0000000 --- a/src/core/io_formats.h +++ /dev/null | |||
| @@ -1,403 +0,0 @@ | |||
| 1 | STATIC cube_t readcube(const char *, const char *); | ||
| 2 | STATIC int64_t writecube(const char *, cube_t, size_t n, char [n]); | ||
| 3 | STATIC void log_available_formats(void); | ||
| 4 | STATIC uint8_t readco(const char *); | ||
| 5 | STATIC uint8_t readcp(const char *); | ||
| 6 | STATIC uint8_t readeo(const char *); | ||
| 7 | STATIC uint8_t readep(const char *); | ||
| 8 | STATIC cube_t readcube_B32(const char *); | ||
| 9 | STATIC cube_t readcube_H48(const char *); | ||
| 10 | STATIC uint8_t readpiece_LST(const char **); | ||
| 11 | STATIC cube_t readcube_LST(const char *); | ||
| 12 | |||
| 13 | STATIC int64_t writepiece_LST(uint8_t, size_t n, char [n]); | ||
| 14 | STATIC int64_t writecube_B32(cube_t, size_t n, char [n]); | ||
| 15 | STATIC int64_t writecube_H48(cube_t, size_t n, char [n]); | ||
| 16 | STATIC int64_t writecube_LST(cube_t, size_t n, char [n]); | ||
| 17 | |||
| 18 | STATIC uint8_t b32toedge(char); | ||
| 19 | STATIC uint8_t b32tocorner(char); | ||
| 20 | STATIC char edgetob32(uint8_t); | ||
| 21 | STATIC char cornertob32(uint8_t); | ||
| 22 | |||
| 23 | STATIC struct { | ||
| 24 | const char *name; | ||
| 25 | cube_t (*read)(const char *); | ||
| 26 | int64_t (*write)(cube_t, size_t n, char [n]); | ||
| 27 | } ioformat[] = | ||
| 28 | { | ||
| 29 | { .name = "B32", .read = readcube_B32, .write = writecube_B32 }, | ||
| 30 | { .name = "LST", .read = readcube_LST, .write = writecube_LST }, | ||
| 31 | { .name = "H48", .read = readcube_H48, .write = writecube_H48 }, | ||
| 32 | { .name = "NONE", .read = NULL, .write = NULL }, | ||
| 33 | }; | ||
| 34 | |||
| 35 | STATIC cube_t | ||
| 36 | readcube(const char *format, const char *buf) | ||
| 37 | { | ||
| 38 | int i; | ||
| 39 | |||
| 40 | for (i = 0; ioformat[i].read != NULL; i++) | ||
| 41 | if (!strcmp(format, ioformat[i].name)) | ||
| 42 | return ioformat[i].read(buf); | ||
| 43 | |||
| 44 | LOG("Cannot read cube: unknown format '%s'\n", format); | ||
| 45 | log_available_formats(); | ||
| 46 | return ZERO_CUBE; | ||
| 47 | } | ||
| 48 | |||
| 49 | STATIC int64_t | ||
| 50 | writecube(const char *format, cube_t cube, size_t buf_size, char buf[buf_size]) | ||
| 51 | { | ||
| 52 | int i; | ||
| 53 | |||
| 54 | for (i = 0; ioformat[i].write != NULL; i++) | ||
| 55 | if (!strcmp(format, ioformat[i].name)) | ||
| 56 | return ioformat[i].write(cube, buf_size, buf); | ||
| 57 | |||
| 58 | LOG("Cannot write cube: unknown format '%s'\n", format); | ||
| 59 | log_available_formats(); | ||
| 60 | return NISSY_ERROR_INVALID_FORMAT; | ||
| 61 | } | ||
| 62 | |||
| 63 | STATIC void | ||
| 64 | log_available_formats(void) | ||
| 65 | { | ||
| 66 | int i; | ||
| 67 | |||
| 68 | LOG("Available formats: "); | ||
| 69 | for (i = 0; ioformat[i].read != NULL; i++) | ||
| 70 | LOG("'%s' ", ioformat[i].name); | ||
| 71 | LOG("\n"); | ||
| 72 | } | ||
| 73 | |||
| 74 | STATIC uint8_t | ||
| 75 | readco(const char *str) | ||
| 76 | { | ||
| 77 | if (*str == '0') | ||
| 78 | return 0; | ||
| 79 | if (*str == '1') | ||
| 80 | return CTWIST_CW; | ||
| 81 | if (*str == '2') | ||
| 82 | return CTWIST_CCW; | ||
| 83 | |||
| 84 | LOG("Error reading CO\n"); | ||
| 85 | return UINT8_ERROR; | ||
| 86 | } | ||
| 87 | |||
| 88 | STATIC uint8_t | ||
| 89 | readcp(const char *str) | ||
| 90 | { | ||
| 91 | uint8_t c; | ||
| 92 | |||
| 93 | for (c = 0; c < 8; c++) | ||
| 94 | if (!strncmp(str, cornerstr[c], 3) || | ||
| 95 | !strncmp(str, cornerstralt[c], 3)) | ||
| 96 | return c; | ||
| 97 | |||
| 98 | LOG("Error reading CP\n"); | ||
| 99 | return UINT8_ERROR; | ||
| 100 | } | ||
| 101 | |||
| 102 | STATIC uint8_t | ||
| 103 | readeo(const char *str) | ||
| 104 | { | ||
| 105 | if (*str == '0') | ||
| 106 | return 0; | ||
| 107 | if (*str == '1') | ||
| 108 | return EFLIP; | ||
| 109 | |||
| 110 | LOG("Error reading EO\n"); | ||
| 111 | return UINT8_ERROR; | ||
| 112 | } | ||
| 113 | |||
| 114 | STATIC uint8_t | ||
| 115 | readep(const char *str) | ||
| 116 | { | ||
| 117 | uint8_t e; | ||
| 118 | |||
| 119 | for (e = 0; e < 12; e++) | ||
| 120 | if (!strncmp(str, edgestr[e], 2)) | ||
| 121 | return e; | ||
| 122 | |||
| 123 | LOG("Error reading EP\n"); | ||
| 124 | return UINT8_ERROR; | ||
| 125 | } | ||
| 126 | |||
| 127 | STATIC cube_t | ||
| 128 | readcube_B32(const char *buf) | ||
| 129 | { | ||
| 130 | int i; | ||
| 131 | uint8_t c[8], e[12]; | ||
| 132 | |||
| 133 | for (i = 0; i < 8; i++) { | ||
| 134 | c[i] = b32tocorner(buf[i]); | ||
| 135 | if (c[i] == UINT8_ERROR) { | ||
| 136 | LOG("Error reading B32 corner %d ", i); | ||
| 137 | if (buf[i] == 0) { | ||
| 138 | LOG("(string terminated early)\n"); | ||
| 139 | } else { | ||
| 140 | LOG("(char '%c')\n", buf[i]); | ||
| 141 | } | ||
| 142 | return ZERO_CUBE; | ||
| 143 | } | ||
| 144 | } | ||
| 145 | |||
| 146 | if (buf[8] != '=') { | ||
| 147 | LOG("Error reading B32 separator: a single '=' " | ||
| 148 | "must be used to separate edges and corners\n"); | ||
| 149 | return ZERO_CUBE; | ||
| 150 | } | ||
| 151 | |||
| 152 | for (i = 0; i < 12; i++) { | ||
| 153 | e[i] = b32toedge(buf[i+9]); | ||
| 154 | if (e[i] == UINT8_ERROR) { | ||
| 155 | LOG("Error reading B32 edge %d ", i); | ||
| 156 | if (buf[i+9] == 0) { | ||
| 157 | LOG("(string terminated early)\n"); | ||
| 158 | } else { | ||
| 159 | LOG("(char '%c')\n", buf[i+9]); | ||
| 160 | } | ||
| 161 | return ZERO_CUBE; | ||
| 162 | } | ||
| 163 | } | ||
| 164 | |||
| 165 | return cubefromarray(c, e); | ||
| 166 | } | ||
| 167 | |||
| 168 | STATIC cube_t | ||
| 169 | readcube_H48(const char *buf) | ||
| 170 | { | ||
| 171 | int i; | ||
| 172 | uint8_t piece, orient, c[8], e[12]; | ||
| 173 | const char *b; | ||
| 174 | |||
| 175 | b = buf; | ||
| 176 | |||
| 177 | for (i = 0; i < 12; i++) { | ||
| 178 | while (*b == ' ' || *b == '\t' || *b == '\n') | ||
| 179 | b++; | ||
| 180 | if ((piece = readep(b)) == UINT8_ERROR) | ||
| 181 | return ZERO_CUBE; | ||
| 182 | b += 2; | ||
| 183 | if ((orient = readeo(b)) == UINT8_ERROR) | ||
| 184 | return ZERO_CUBE; | ||
| 185 | b++; | ||
| 186 | e[i] = piece | orient; | ||
| 187 | } | ||
| 188 | for (i = 0; i < 8; i++) { | ||
| 189 | while (*b == ' ' || *b == '\t' || *b == '\n') | ||
| 190 | b++; | ||
| 191 | if ((piece = readcp(b)) == UINT8_ERROR) | ||
| 192 | return ZERO_CUBE; | ||
| 193 | b += 3; | ||
| 194 | if ((orient = readco(b)) == UINT8_ERROR) | ||
| 195 | return ZERO_CUBE; | ||
| 196 | b++; | ||
| 197 | c[i] = piece | orient; | ||
| 198 | } | ||
| 199 | |||
| 200 | return cubefromarray(c, e); | ||
| 201 | } | ||
| 202 | |||
| 203 | STATIC uint8_t | ||
| 204 | readpiece_LST(const char **b) | ||
| 205 | { | ||
| 206 | uint8_t ret; | ||
| 207 | bool read; | ||
| 208 | |||
| 209 | while (**b == ',' || **b == ' ' || **b == '\t' || **b == '\n') | ||
| 210 | (*b)++; | ||
| 211 | |||
| 212 | for (ret = 0, read = false; **b >= '0' && **b <= '9'; (*b)++) { | ||
| 213 | read = true; | ||
| 214 | ret = ret * 10 + (**b) - '0'; | ||
| 215 | } | ||
| 216 | |||
| 217 | return read ? ret : UINT8_ERROR; | ||
| 218 | } | ||
| 219 | |||
| 220 | STATIC cube_t | ||
| 221 | readcube_LST(const char *buf) | ||
| 222 | { | ||
| 223 | int i; | ||
| 224 | uint8_t c[8], e[12]; | ||
| 225 | |||
| 226 | for (i = 0; i < 8; i++) | ||
| 227 | c[i] = readpiece_LST(&buf); | ||
| 228 | |||
| 229 | for (i = 0; i < 12; i++) | ||
| 230 | e[i] = readpiece_LST(&buf); | ||
| 231 | |||
| 232 | return cubefromarray(c, e); | ||
| 233 | } | ||
| 234 | |||
| 235 | STATIC int64_t | ||
| 236 | writepiece_LST(uint8_t piece, size_t buf_size, char buf[buf_size]) | ||
| 237 | { | ||
| 238 | char digits[3]; | ||
| 239 | size_t i, len; | ||
| 240 | |||
| 241 | if (piece > 99 || buf_size < 3) | ||
| 242 | return 0; | ||
| 243 | |||
| 244 | len = 0; | ||
| 245 | while (piece != 0) { | ||
| 246 | digits[len++] = (piece % 10) + '0'; | ||
| 247 | piece /= 10; | ||
| 248 | } | ||
| 249 | |||
| 250 | if (buf_size < len+2) | ||
| 251 | return 0; | ||
| 252 | |||
| 253 | if (len == 0) | ||
| 254 | digits[len++] = '0'; | ||
| 255 | |||
| 256 | for (i = 0; i < len; i++) | ||
| 257 | buf[i] = digits[len-i-1]; | ||
| 258 | |||
| 259 | buf[len] = ','; | ||
| 260 | buf[len+1] = ' '; | ||
| 261 | |||
| 262 | return len+2; | ||
| 263 | } | ||
| 264 | |||
| 265 | STATIC int64_t | ||
| 266 | writecube_B32(cube_t cube, size_t buf_size, char buf[buf_size]) | ||
| 267 | { | ||
| 268 | int i; | ||
| 269 | uint8_t corner[8], edge[12]; | ||
| 270 | |||
| 271 | if (buf_size < NISSY_SIZE_B32) { | ||
| 272 | LOG("Cannot write cube in B32 format: buffer size must be at " | ||
| 273 | "least %u bytes, but the provided one is %zu bytes.\n", | ||
| 274 | NISSY_SIZE_B32, buf_size); | ||
| 275 | return NISSY_ERROR_BUFFER_SIZE; | ||
| 276 | } | ||
| 277 | |||
| 278 | pieces(&cube, corner, edge); | ||
| 279 | |||
| 280 | for (i = 0; i < 8; i++) | ||
| 281 | buf[i] = cornertob32(corner[i]); | ||
| 282 | |||
| 283 | buf[8] = '='; | ||
| 284 | |||
| 285 | for (i = 0; i < 12; i++) | ||
| 286 | buf[i+9] = edgetob32(edge[i]); | ||
| 287 | |||
| 288 | buf[21] = '\0'; | ||
| 289 | |||
| 290 | return NISSY_OK; | ||
| 291 | } | ||
| 292 | |||
| 293 | STATIC int64_t | ||
| 294 | writecube_H48(cube_t cube, size_t buf_size, char buf[buf_size]) | ||
| 295 | { | ||
| 296 | uint8_t piece, perm, orient, corner[8], edge[12]; | ||
| 297 | int i; | ||
| 298 | |||
| 299 | if (buf_size < NISSY_SIZE_H48) { | ||
| 300 | LOG("Cannot write cube in H48 format: buffer size must be " | ||
| 301 | "at least %u bytes, but the provided one is %zu bytes.\n", | ||
| 302 | NISSY_SIZE_H48, buf_size); | ||
| 303 | return NISSY_ERROR_BUFFER_SIZE; | ||
| 304 | } | ||
| 305 | |||
| 306 | pieces(&cube, corner, edge); | ||
| 307 | |||
| 308 | for (i = 0; i < 12; i++) { | ||
| 309 | piece = edge[i]; | ||
| 310 | perm = piece & PBITS; | ||
| 311 | orient = (piece & EOBIT) >> EOSHIFT; | ||
| 312 | buf[4*i ] = edgestr[perm][0]; | ||
| 313 | buf[4*i + 1] = edgestr[perm][1]; | ||
| 314 | buf[4*i + 2] = orient + '0'; | ||
| 315 | buf[4*i + 3] = ' '; | ||
| 316 | } | ||
| 317 | for (i = 0; i < 8; i++) { | ||
| 318 | piece = corner[i]; | ||
| 319 | perm = piece & PBITS; | ||
| 320 | orient = (piece & COBITS) >> COSHIFT; | ||
| 321 | buf[48 + 5*i ] = cornerstr[perm][0]; | ||
| 322 | buf[48 + 5*i + 1] = cornerstr[perm][1]; | ||
| 323 | buf[48 + 5*i + 2] = cornerstr[perm][2]; | ||
| 324 | buf[48 + 5*i + 3] = orient + '0'; | ||
| 325 | buf[48 + 5*i + 4] = ' '; | ||
| 326 | } | ||
| 327 | |||
| 328 | buf[48+39] = '\0'; | ||
| 329 | |||
| 330 | return NISSY_OK; | ||
| 331 | } | ||
| 332 | |||
| 333 | STATIC int64_t | ||
| 334 | writecube_LST(cube_t cube, size_t buf_size, char buf[buf_size]) | ||
| 335 | { | ||
| 336 | int i; | ||
| 337 | uint64_t ptr; | ||
| 338 | uint8_t piece, corner[8], edge[12]; | ||
| 339 | |||
| 340 | ptr = 0; | ||
| 341 | pieces(&cube, corner, edge); | ||
| 342 | |||
| 343 | for (i = 0; i < 8; i++) { | ||
| 344 | piece = corner[i]; | ||
| 345 | ptr += writepiece_LST(piece, buf_size - ptr, buf + ptr); | ||
| 346 | if (ptr == 0) | ||
| 347 | goto writecube_LST_error; | ||
| 348 | } | ||
| 349 | |||
| 350 | for (i = 0; i < 12; i++) { | ||
| 351 | piece = edge[i]; | ||
| 352 | ptr += writepiece_LST(piece, buf_size - ptr, buf + ptr); | ||
| 353 | if (ptr == 0) | ||
| 354 | goto writecube_LST_error; | ||
| 355 | } | ||
| 356 | |||
| 357 | *(buf+ptr-2) = '\0'; | ||
| 358 | |||
| 359 | return NISSY_OK; | ||
| 360 | |||
| 361 | writecube_LST_error: | ||
| 362 | LOG("Cannot write cube in LST: buffer is too small (%" PRIu64 | ||
| 363 | " bytes given). The LST format has a variable size, try a " | ||
| 364 | "larger buffer.\n", buf_size); | ||
| 365 | return NISSY_ERROR_BUFFER_SIZE; | ||
| 366 | } | ||
| 367 | |||
| 368 | STATIC uint8_t | ||
| 369 | b32toedge(char c) | ||
| 370 | { | ||
| 371 | if (!((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'f'))) | ||
| 372 | return UINT8_ERROR; | ||
| 373 | |||
| 374 | return c <= 'Z' ? (uint8_t)(c - 'A') : (uint8_t)(c - 'a') + 26; | ||
| 375 | } | ||
| 376 | |||
| 377 | STATIC uint8_t | ||
| 378 | b32tocorner(char c) { | ||
| 379 | uint8_t val; | ||
| 380 | |||
| 381 | if (!((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'f'))) | ||
| 382 | return UINT8_ERROR; | ||
| 383 | |||
| 384 | val = c <= 'Z' ? (uint8_t)(c - 'A') : (uint8_t)(c - 'a') + 26; | ||
| 385 | |||
| 386 | return (val & 7) | ((val & 24) << 2); | ||
| 387 | } | ||
| 388 | |||
| 389 | STATIC char | ||
| 390 | edgetob32(uint8_t edge) | ||
| 391 | { | ||
| 392 | return edge < 26 ? 'A' + (char)edge : 'a' + (char)(edge - 26); | ||
| 393 | } | ||
| 394 | |||
| 395 | STATIC char | ||
| 396 | cornertob32(uint8_t corner) | ||
| 397 | { | ||
| 398 | uint8_t val; | ||
| 399 | |||
| 400 | val = (corner & 7) | ((corner & 96) >> 2); | ||
| 401 | |||
| 402 | return val < 26 ? 'A' + (char)val : 'a' + (char)(val - 26); | ||
| 403 | } | ||
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( | |||
| 17 | STATIC bool checkdata(const unsigned char *, const tableinfo_t [static 1]); | 17 | STATIC bool checkdata(const unsigned char *, const tableinfo_t [static 1]); |
| 18 | STATIC bool distribution_equal(const uint64_t [static INFO_DISTRIBUTION_LEN], | 18 | STATIC 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); |
| 20 | STATIC long long write_result(cube_t, char [static NISSY_SIZE_B32]); | 20 | STATIC long long write_result(cube_t, char [static NISSY_SIZE_CUBE]); |
| 21 | STATIC size_t my_strnlen(const char *, size_t); | 21 | STATIC size_t my_strnlen(const char *, size_t); |
| 22 | STATIC long long nissy_dataid(const char *, char [static NISSY_SIZE_DATAID]); | 22 | STATIC long long nissy_dataid(const char *, char [static NISSY_SIZE_DATAID]); |
| 23 | STATIC long long nissy_gendata_unsafe( | 23 | STATIC long long nissy_gendata_unsafe( |
| @@ -117,9 +117,9 @@ distribution_equal( | |||
| 117 | } | 117 | } |
| 118 | 118 | ||
| 119 | STATIC long long | 119 | STATIC long long |
| 120 | write_result(cube_t cube, char result[static NISSY_SIZE_B32]) | 120 | write_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 | ||
| 144 | long long | 144 | long long |
| 145 | nissy_compose( | 145 | nissy_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 | ||
| 180 | nissy_compose_error: | 180 | nissy_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 | ||
| 185 | long long | 185 | long long |
| 186 | nissy_inverse( | 186 | nissy_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 | ||
| 212 | nissy_inverse_error: | 212 | nissy_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 | ||
| 217 | long long | 217 | long long |
| 218 | nissy_applymoves( | 218 | nissy_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 | ||
| 251 | nissy_applymoves_error: | 251 | nissy_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 | ||
| 256 | long long | 256 | long long |
| 257 | nissy_applytrans( | 257 | nissy_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 | ||
| 284 | nissy_applytrans_error: | 284 | nissy_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 | |||
| 289 | long long | ||
| 290 | nissy_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 | |||
| 328 | nissy_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 | ||
| 527 | long long | 483 | long long |
| 528 | nissy_solve( | 484 | nissy_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 | |||
| 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 at |
| 6 | the bottom of this file for the list of error codes and their meaning. | 6 | the bottom of this file for the list of error codes and their meaning. |
| 7 | 7 | ||
| 8 | All cube arguments are in B32 formats, unless otherwise specified. | 8 | TODO: explain cube format |
| 9 | Other available formats are H48 and SRC. See README.md for more info on | ||
| 10 | these formats. | ||
| 11 | 9 | ||
| 12 | Accepted moves are U, D, R, L, F and B, optionally followed by a 2, | 10 | Accepted moves are U, D, R, L, F and B, optionally followed by a 2, |
| 13 | a ' or a 3. | 11 | a ' or a 3. |
| 12 | TODO update when we accept also wide moves, slices and rotations | ||
| 14 | 13 | ||
| 15 | A transformation must be given in the format | 14 | A 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 | /* |
| 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, |
