aboutsummaryrefslogtreecommitdiff
path: root/cube.c
diff options
context:
space:
mode:
Diffstat (limited to 'cube.c')
-rw-r--r--cube.c107
1 files changed, 48 insertions, 59 deletions
diff --git a/cube.c b/cube.c
index e77bf9e..9084dd0 100644
--- a/cube.c
+++ b/cube.c
@@ -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
1156cube_t solvedcube(void);
1157bool isconsistent(cube_t);
1158bool issolvable(cube_t);
1159bool issolved(cube_t cube);
1160bool equal(cube_t, cube_t);
1161bool iserror(cube_t);
1162cube_t compose(cube_t, cube_t);
1163cube_t inverse(cube_t);
1164cube_t applymoves(cube_t, char *);
1165cube_t applytrans(cube_t, char *);
1166cube_t readcube(char *, char *);
1167void 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
1357cube_t 1344cube_t
1358applymoves(cube_t cube, char *buf) 1345applymoves(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
1389cube_t 1376cube_t
1390applytrans(cube_t cube, char *buf) 1377applytrans(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
1405cube_t 1392cube_t
1406readcube(char *format, char *buf) 1393readcube(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
1422void 1409void
1423writecube(char *format, cube_t cube, char *buf) 1410writecube(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
1466readco(char *str) 1453readco(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
1480readcp(char *str) 1467readcp(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
1494readeo(char *str) 1481readeo(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
1506readep(char *str) 1493readep(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
1519readcube_H48(char *buf) 1506readcube_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
1555readpiece_LST(char **b) 1542readpiece_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
1572readcube_LST(char *buf) 1559readcube_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
1696readtrans(char *buf) 1683readtrans(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
2073k is the compression size (4, 2 or 1 bit) 2061k is the compression size (4, 2 or 1 bit)
2074*/ 2062*/
2075_static size_t 2063_static size_t
2076gendata_eoesep(uint8_t h, uint8_t k, void *cocsepdata, void *buf) 2064gendata_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
2111get_h48_pval(uint32_t *buf32, int64_t index, uint8_t k) 2099get_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
2191int64_t solve(cube_t, char *, char *, char *, int8_t, int8_t, int64_t, int8_t,
2192 void *, char *);
2193void multisolve(int, cube_t *, char *, void *, char *);
2194int64_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
2204int64_t 2187int64_t
2205solve( 2188solve(
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
2245void 2228void
2246multisolve(int n, cube_t *cube, char *solver, void *data, char *sols) 2229multisolve(
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
2258int64_t 2247int64_t
2259gendata(char *solver, void *data) 2248gendata(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
2346solve_generic( 2335solve_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,

Generated with cgit - Back to sebastiano.tronto.net