diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2024-04-16 16:16:02 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2024-04-16 16:24:26 +0200 |
| commit | 5378be20bc24ea0c8681da17d0585ee6ff82f788 (patch) | |
| tree | e2b33612d750a35551a443d710fee5ad6f9f03f3 /cube.c | |
| parent | 1cf6502c9f3d8994e5c97f90cc29392043e40f2b (diff) | |
| download | nissy-core-5378be20bc24ea0c8681da17d0585ee6ff82f788.tar.gz nissy-core-5378be20bc24ea0c8681da17d0585ee6ff82f788.zip | |
const char *
Diffstat (limited to 'cube.c')
| -rw-r--r-- | cube.c | 107 |
1 files changed, 48 insertions, 59 deletions
| @@ -406,7 +406,7 @@ _static cube_t solved = { | |||
| 406 | #define _trans_cube_BLm_inverse fastcube( \ | 406 | #define _trans_cube_BLm_inverse fastcube( \ |
| 407 | 38, 37, 39, 36, 67, 64, 66, 65, 23, 20, 21, 22, 24, 27, 26, 25, 3, 2, 1, 0) | 407 | 38, 37, 39, 36, 67, 64, 66, 65, 23, 20, 21, 22, 24, 27, 26, 25, 3, 2, 1, 0) |
| 408 | 408 | ||
| 409 | _static char *cornerstr[] = { | 409 | _static const char *cornerstr[] = { |
| 410 | [_c_ufr] = "UFR", | 410 | [_c_ufr] = "UFR", |
| 411 | [_c_ubl] = "UBL", | 411 | [_c_ubl] = "UBL", |
| 412 | [_c_dfl] = "DFL", | 412 | [_c_dfl] = "DFL", |
| @@ -417,7 +417,7 @@ _static char *cornerstr[] = { | |||
| 417 | [_c_dbl] = "DBL" | 417 | [_c_dbl] = "DBL" |
| 418 | }; | 418 | }; |
| 419 | 419 | ||
| 420 | _static char *cornerstralt[] = { | 420 | _static const char *cornerstralt[] = { |
| 421 | [_c_ufr] = "URF", | 421 | [_c_ufr] = "URF", |
| 422 | [_c_ubl] = "ULB", | 422 | [_c_ubl] = "ULB", |
| 423 | [_c_dfl] = "DLF", | 423 | [_c_dfl] = "DLF", |
| @@ -428,7 +428,7 @@ _static char *cornerstralt[] = { | |||
| 428 | [_c_dbl] = "DLB" | 428 | [_c_dbl] = "DLB" |
| 429 | }; | 429 | }; |
| 430 | 430 | ||
| 431 | _static char *edgestr[] = { | 431 | _static const char *edgestr[] = { |
| 432 | [_e_uf] = "UF", | 432 | [_e_uf] = "UF", |
| 433 | [_e_ub] = "UB", | 433 | [_e_ub] = "UB", |
| 434 | [_e_db] = "DB", | 434 | [_e_db] = "DB", |
| @@ -443,7 +443,7 @@ _static char *edgestr[] = { | |||
| 443 | [_e_br] = "BR" | 443 | [_e_br] = "BR" |
| 444 | }; | 444 | }; |
| 445 | 445 | ||
| 446 | _static char *movestr[] = { | 446 | _static const char *movestr[] = { |
| 447 | [U] = "U", | 447 | [U] = "U", |
| 448 | [U2] = "U2", | 448 | [U2] = "U2", |
| 449 | [U3] = "U'", | 449 | [U3] = "U'", |
| @@ -464,7 +464,7 @@ _static char *movestr[] = { | |||
| 464 | [B3] = "B'", | 464 | [B3] = "B'", |
| 465 | }; | 465 | }; |
| 466 | 466 | ||
| 467 | _static char *transstr[] = { | 467 | _static const char *transstr[] = { |
| 468 | [UFr] = "rotation UF", | 468 | [UFr] = "rotation UF", |
| 469 | [UFm] = "mirrored UF", | 469 | [UFm] = "mirrored UF", |
| 470 | [ULr] = "rotation UL", | 470 | [ULr] = "rotation UL", |
| @@ -1153,33 +1153,20 @@ previous sections, while some other operate directly on the cube. | |||
| 1153 | for (_t = 0; _t < 48; _t++) { _d = transform(_c, _t); instruction } | 1153 | for (_t = 0; _t < 48; _t++) { _d = transform(_c, _t); instruction } |
| 1154 | #endif | 1154 | #endif |
| 1155 | 1155 | ||
| 1156 | cube_t solvedcube(void); | ||
| 1157 | bool isconsistent(cube_t); | ||
| 1158 | bool issolvable(cube_t); | ||
| 1159 | bool issolved(cube_t cube); | ||
| 1160 | bool equal(cube_t, cube_t); | ||
| 1161 | bool iserror(cube_t); | ||
| 1162 | cube_t compose(cube_t, cube_t); | ||
| 1163 | cube_t inverse(cube_t); | ||
| 1164 | cube_t applymoves(cube_t, char *); | ||
| 1165 | cube_t applytrans(cube_t, char *); | ||
| 1166 | cube_t readcube(char *, char *); | ||
| 1167 | void writecube(char *, cube_t, char *); | ||
| 1168 | |||
| 1169 | _static int permsign(uint8_t *, int); | 1156 | _static int permsign(uint8_t *, int); |
| 1170 | _static uint8_t readco(char *); | 1157 | _static uint8_t readco(const char *); |
| 1171 | _static uint8_t readcp(char *); | 1158 | _static uint8_t readcp(const char *); |
| 1172 | _static uint8_t readeo(char *); | 1159 | _static uint8_t readeo(const char *); |
| 1173 | _static uint8_t readep(char *); | 1160 | _static uint8_t readep(const char *); |
| 1174 | _static cube_t readcube_H48(char *); | 1161 | _static cube_t readcube_H48(const char *); |
| 1175 | _static uint8_t readpiece_LST(char **); | 1162 | _static uint8_t readpiece_LST(const char **); |
| 1176 | _static cube_t readcube_LST(char *); | 1163 | _static cube_t readcube_LST(const char *); |
| 1177 | _static int writepiece_LST(uint8_t, char *); | 1164 | _static int writepiece_LST(uint8_t, char *); |
| 1178 | _static void writecube_H48(cube_t, char *); | 1165 | _static void writecube_H48(cube_t, char *); |
| 1179 | _static void writecube_LST(cube_t, char *); | 1166 | _static void writecube_LST(cube_t, char *); |
| 1180 | _static uint8_t readmove(char); | 1167 | _static uint8_t readmove(char); |
| 1181 | _static uint8_t readmodifier(char); | 1168 | _static uint8_t readmodifier(char); |
| 1182 | _static uint8_t readtrans(char *); | 1169 | _static uint8_t readtrans(const char *); |
| 1183 | _static int writemoves(uint8_t *, int, char *); | 1170 | _static int writemoves(uint8_t *, int, char *); |
| 1184 | _static void writetrans(uint8_t, char *); | 1171 | _static void writetrans(uint8_t, char *); |
| 1185 | _static cube_fast_t move(cube_fast_t, uint8_t); | 1172 | _static cube_fast_t move(cube_fast_t, uint8_t); |
| @@ -1355,11 +1342,11 @@ inverse(cube_t cube) | |||
| 1355 | } | 1342 | } |
| 1356 | 1343 | ||
| 1357 | cube_t | 1344 | cube_t |
| 1358 | applymoves(cube_t cube, char *buf) | 1345 | applymoves(cube_t cube, const char *buf) |
| 1359 | { | 1346 | { |
| 1360 | cube_fast_t fast; | 1347 | cube_fast_t fast; |
| 1361 | uint8_t r, m; | 1348 | uint8_t r, m; |
| 1362 | char *b; | 1349 | const char *b; |
| 1363 | 1350 | ||
| 1364 | DBG_ASSERT(isconsistent(cube), zero, | 1351 | DBG_ASSERT(isconsistent(cube), zero, |
| 1365 | "move error: inconsistent cube\n"); | 1352 | "move error: inconsistent cube\n"); |
| @@ -1387,7 +1374,7 @@ applymoves_error: | |||
| 1387 | } | 1374 | } |
| 1388 | 1375 | ||
| 1389 | cube_t | 1376 | cube_t |
| 1390 | applytrans(cube_t cube, char *buf) | 1377 | applytrans(cube_t cube, const char *buf) |
| 1391 | { | 1378 | { |
| 1392 | cube_fast_t fast; | 1379 | cube_fast_t fast; |
| 1393 | uint8_t t; | 1380 | uint8_t t; |
| @@ -1403,7 +1390,7 @@ applytrans(cube_t cube, char *buf) | |||
| 1403 | } | 1390 | } |
| 1404 | 1391 | ||
| 1405 | cube_t | 1392 | cube_t |
| 1406 | readcube(char *format, char *buf) | 1393 | readcube(const char *format, const char *buf) |
| 1407 | { | 1394 | { |
| 1408 | cube_t cube; | 1395 | cube_t cube; |
| 1409 | 1396 | ||
| @@ -1420,7 +1407,7 @@ readcube(char *format, char *buf) | |||
| 1420 | } | 1407 | } |
| 1421 | 1408 | ||
| 1422 | void | 1409 | void |
| 1423 | writecube(char *format, cube_t cube, char *buf) | 1410 | writecube(const char *format, cube_t cube, char *buf) |
| 1424 | { | 1411 | { |
| 1425 | char *errormsg; | 1412 | char *errormsg; |
| 1426 | size_t len; | 1413 | size_t len; |
| @@ -1463,7 +1450,7 @@ permsign(uint8_t *a, int n) | |||
| 1463 | } | 1450 | } |
| 1464 | 1451 | ||
| 1465 | _static uint8_t | 1452 | _static uint8_t |
| 1466 | readco(char *str) | 1453 | readco(const char *str) |
| 1467 | { | 1454 | { |
| 1468 | if (*str == '0') | 1455 | if (*str == '0') |
| 1469 | return 0; | 1456 | return 0; |
| @@ -1477,7 +1464,7 @@ readco(char *str) | |||
| 1477 | } | 1464 | } |
| 1478 | 1465 | ||
| 1479 | _static uint8_t | 1466 | _static uint8_t |
| 1480 | readcp(char *str) | 1467 | readcp(const char *str) |
| 1481 | { | 1468 | { |
| 1482 | uint8_t c; | 1469 | uint8_t c; |
| 1483 | 1470 | ||
| @@ -1491,7 +1478,7 @@ readcp(char *str) | |||
| 1491 | } | 1478 | } |
| 1492 | 1479 | ||
| 1493 | _static uint8_t | 1480 | _static uint8_t |
| 1494 | readeo(char *str) | 1481 | readeo(const char *str) |
| 1495 | { | 1482 | { |
| 1496 | if (*str == '0') | 1483 | if (*str == '0') |
| 1497 | return 0; | 1484 | return 0; |
| @@ -1503,7 +1490,7 @@ readeo(char *str) | |||
| 1503 | } | 1490 | } |
| 1504 | 1491 | ||
| 1505 | _static uint8_t | 1492 | _static uint8_t |
| 1506 | readep(char *str) | 1493 | readep(const char *str) |
| 1507 | { | 1494 | { |
| 1508 | uint8_t e; | 1495 | uint8_t e; |
| 1509 | 1496 | ||
| @@ -1516,12 +1503,12 @@ readep(char *str) | |||
| 1516 | } | 1503 | } |
| 1517 | 1504 | ||
| 1518 | _static cube_t | 1505 | _static cube_t |
| 1519 | readcube_H48(char *buf) | 1506 | readcube_H48(const char *buf) |
| 1520 | { | 1507 | { |
| 1521 | int i; | 1508 | int i; |
| 1522 | uint8_t piece, orient; | 1509 | uint8_t piece, orient; |
| 1523 | cube_t ret = {0}; | 1510 | cube_t ret = {0}; |
| 1524 | char *b; | 1511 | const char *b; |
| 1525 | 1512 | ||
| 1526 | b = buf; | 1513 | b = buf; |
| 1527 | 1514 | ||
| @@ -1552,7 +1539,7 @@ readcube_H48(char *buf) | |||
| 1552 | } | 1539 | } |
| 1553 | 1540 | ||
| 1554 | _static uint8_t | 1541 | _static uint8_t |
| 1555 | readpiece_LST(char **b) | 1542 | readpiece_LST(const char **b) |
| 1556 | { | 1543 | { |
| 1557 | uint8_t ret; | 1544 | uint8_t ret; |
| 1558 | bool read; | 1545 | bool read; |
| @@ -1569,7 +1556,7 @@ readpiece_LST(char **b) | |||
| 1569 | } | 1556 | } |
| 1570 | 1557 | ||
| 1571 | _static cube_t | 1558 | _static cube_t |
| 1572 | readcube_LST(char *buf) | 1559 | readcube_LST(const char *buf) |
| 1573 | { | 1560 | { |
| 1574 | int i; | 1561 | int i; |
| 1575 | cube_t ret = {0}; | 1562 | cube_t ret = {0}; |
| @@ -1693,7 +1680,7 @@ readmodifier(char c) | |||
| 1693 | } | 1680 | } |
| 1694 | 1681 | ||
| 1695 | _static uint8_t | 1682 | _static uint8_t |
| 1696 | readtrans(char *buf) | 1683 | readtrans(const char *buf) |
| 1697 | { | 1684 | { |
| 1698 | uint8_t t; | 1685 | uint8_t t; |
| 1699 | 1686 | ||
| @@ -1710,7 +1697,8 @@ writemoves(uint8_t *m, int n, char *buf) | |||
| 1710 | { | 1697 | { |
| 1711 | int i; | 1698 | int i; |
| 1712 | size_t len; | 1699 | size_t len; |
| 1713 | char *b, *s; | 1700 | const char *s; |
| 1701 | char *b; | ||
| 1714 | 1702 | ||
| 1715 | for (i = 0, b = buf; i < n; i++, b++) { | 1703 | for (i = 0, b = buf; i < n; i++, b++) { |
| 1716 | s = movestr[m[i]]; | 1704 | s = movestr[m[i]]; |
| @@ -1963,10 +1951,10 @@ _static size_t gendata_cocsep(void *); | |||
| 1963 | _static uint32_t dfs_cocsep( /* TODO: use dfsarg */ | 1951 | _static uint32_t dfs_cocsep( /* TODO: use dfsarg */ |
| 1964 | cube_fast_t, uint8_t, uint8_t, uint16_t *, uint32_t *, bool *); | 1952 | cube_fast_t, uint8_t, uint8_t, uint16_t *, uint32_t *, bool *); |
| 1965 | 1953 | ||
| 1966 | _static size_t gendata_eoesep(uint8_t, uint8_t, void *, void *); | 1954 | _static size_t gendata_eoesep(uint8_t, uint8_t, const void *, void *); |
| 1967 | _static uint32_t dfs_eoesep(dfsarg_gendata_t *); | 1955 | _static uint32_t dfs_eoesep(dfsarg_gendata_t *); |
| 1968 | 1956 | ||
| 1969 | _static_inline uint8_t get_h48_pval(uint32_t *, int64_t, uint8_t); | 1957 | _static_inline uint8_t get_h48_pval(const uint32_t *, int64_t, uint8_t); |
| 1970 | _static_inline void set_h48_pval(uint32_t *, int64_t, uint8_t, uint8_t); | 1958 | _static_inline void set_h48_pval(uint32_t *, int64_t, uint8_t, uint8_t); |
| 1971 | 1959 | ||
| 1972 | /* | 1960 | /* |
| @@ -2073,7 +2061,7 @@ h is the number of eo bits | |||
| 2073 | k is the compression size (4, 2 or 1 bit) | 2061 | k is the compression size (4, 2 or 1 bit) |
| 2074 | */ | 2062 | */ |
| 2075 | _static size_t | 2063 | _static size_t |
| 2076 | gendata_eoesep(uint8_t h, uint8_t k, void *cocsepdata, void *buf) | 2064 | gendata_eoesep(uint8_t h, uint8_t k, const void *cocsepdata, void *buf) |
| 2077 | { | 2065 | { |
| 2078 | DBG_ASSERT(k == 4, 0, "eoesep: only k=4 is supported"); | 2066 | DBG_ASSERT(k == 4, 0, "eoesep: only k=4 is supported"); |
| 2079 | 2067 | ||
| @@ -2108,7 +2096,7 @@ gendata_eoesep(uint8_t h, uint8_t k, void *cocsepdata, void *buf) | |||
| 2108 | } | 2096 | } |
| 2109 | 2097 | ||
| 2110 | _static_inline uint8_t | 2098 | _static_inline uint8_t |
| 2111 | get_h48_pval(uint32_t *buf32, int64_t index, uint8_t k) | 2099 | get_h48_pval(const uint32_t *buf32, int64_t index, uint8_t k) |
| 2112 | { | 2100 | { |
| 2113 | uint8_t mask, shift; | 2101 | uint8_t mask, shift; |
| 2114 | 2102 | ||
| @@ -2188,30 +2176,25 @@ typedef struct { | |||
| 2188 | uint8_t (*estimate)(cube_fast_t); | 2176 | uint8_t (*estimate)(cube_fast_t); |
| 2189 | } dfsarg_generic_t; | 2177 | } dfsarg_generic_t; |
| 2190 | 2178 | ||
| 2191 | int64_t solve(cube_t, char *, char *, char *, int8_t, int8_t, int64_t, int8_t, | ||
| 2192 | void *, char *); | ||
| 2193 | void multisolve(int, cube_t *, char *, void *, char *); | ||
| 2194 | int64_t gendata(char *, void *); | ||
| 2195 | |||
| 2196 | _static bool allowednextmove(uint8_t *, int, uint8_t); | 2179 | _static bool allowednextmove(uint8_t *, int, uint8_t); |
| 2197 | _static void solve_generic_appendsolution(dfsarg_generic_t); | 2180 | _static void solve_generic_appendsolution(dfsarg_generic_t); |
| 2198 | _static int solve_generic_dfs(dfsarg_generic_t); | 2181 | _static int solve_generic_dfs(dfsarg_generic_t); |
| 2199 | _static int64_t solve_generic(cube_t, char *, int8_t, int8_t, int64_t, int8_t, | 2182 | _static int64_t solve_generic(cube_t, const char *, int8_t, int8_t, int64_t, |
| 2200 | char *, uint8_t (*)(cube_fast_t)); | 2183 | int8_t, char *, uint8_t (*)(cube_fast_t)); |
| 2201 | _static uint8_t estimate_simple(cube_fast_t); | 2184 | _static uint8_t estimate_simple(cube_fast_t); |
| 2202 | _static int64_t solve_simple(cube_t, int8_t, int8_t, int64_t, int8_t, char *); | 2185 | _static int64_t solve_simple(cube_t, int8_t, int8_t, int64_t, int8_t, char *); |
| 2203 | 2186 | ||
| 2204 | int64_t | 2187 | int64_t |
| 2205 | solve( | 2188 | solve( |
| 2206 | cube_t cube, | 2189 | cube_t cube, |
| 2207 | char *solver, | 2190 | const char *solver, |
| 2208 | char *options, | 2191 | const char *options, |
| 2209 | char *nisstype, | 2192 | const char *nisstype, |
| 2210 | int8_t minmoves, | 2193 | int8_t minmoves, |
| 2211 | int8_t maxmoves, | 2194 | int8_t maxmoves, |
| 2212 | int64_t maxsols, | 2195 | int64_t maxsols, |
| 2213 | int8_t optimal, | 2196 | int8_t optimal, |
| 2214 | void *data, | 2197 | const void *data, |
| 2215 | char *solutions | 2198 | char *solutions |
| 2216 | ) | 2199 | ) |
| 2217 | { | 2200 | { |
| @@ -2243,7 +2226,13 @@ solve( | |||
| 2243 | } | 2226 | } |
| 2244 | 2227 | ||
| 2245 | void | 2228 | void |
| 2246 | multisolve(int n, cube_t *cube, char *solver, void *data, char *sols) | 2229 | multisolve( |
| 2230 | int n, | ||
| 2231 | cube_t *cube, | ||
| 2232 | const char *solver, | ||
| 2233 | const void *data, | ||
| 2234 | char *sols | ||
| 2235 | ) | ||
| 2247 | { | 2236 | { |
| 2248 | char *s; | 2237 | char *s; |
| 2249 | int i; | 2238 | int i; |
| @@ -2256,7 +2245,7 @@ multisolve(int n, cube_t *cube, char *solver, void *data, char *sols) | |||
| 2256 | } | 2245 | } |
| 2257 | 2246 | ||
| 2258 | int64_t | 2247 | int64_t |
| 2259 | gendata(char *solver, void *data) | 2248 | gendata(const char *solver, void *data) |
| 2260 | { | 2249 | { |
| 2261 | DBG_LOG("gendata: not implemented yet\n"); | 2250 | DBG_LOG("gendata: not implemented yet\n"); |
| 2262 | 2251 | ||
| @@ -2345,7 +2334,7 @@ solve_generic_dfs(dfsarg_generic_t arg) | |||
| 2345 | _static int64_t | 2334 | _static int64_t |
| 2346 | solve_generic( | 2335 | solve_generic( |
| 2347 | cube_t cube, | 2336 | cube_t cube, |
| 2348 | char *nisstype, | 2337 | const char *nisstype, |
| 2349 | /* TODO: handle NISS */ | 2338 | /* TODO: handle NISS */ |
| 2350 | int8_t minmoves, | 2339 | int8_t minmoves, |
| 2351 | int8_t maxmoves, | 2340 | int8_t maxmoves, |
