h48

A prototype for an optimal Rubik's cube solver, work in progress.
git clone https://git.tronto.net/h48
Download | Log | Files | Refs | README | LICENSE

commit 6c896b0e619f83b0337d20f92b14e26fcd550b42
parent 61e03f9f4eecf3d5811b11c44c9ef778f0a93bc7
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date:   Sun, 14 Jul 2024 23:32:22 +0200

Test passes, logic error is due to coordinates admitting multiple ttreps

Diffstat:
Msrc/solve_h48.h | 32++++++++++++++------------------
Mtest/103_cocsep_ttrep/cocsep_ttrep_tests.c | 25++++++++++++++-----------
2 files changed, 28 insertions(+), 29 deletions(-)

diff --git a/src/solve_h48.h b/src/solve_h48.h @@ -307,9 +307,9 @@ gendata_cocsep_return_size: _static uint32_t gendata_cocsep_dfs(dfsarg_cocsep_t *arg) { - uint8_t m, tinv; - uint32_t cc, class, ttrep, depth, olddepth; - uint64_t t, is; + uint8_t m; + uint32_t cc, class, ttrep, depth, olddepth, tinv; + uint64_t t; int64_t i, j; cube_t d; dfsarg_cocsep_t nextarg; @@ -324,24 +324,25 @@ gendata_cocsep_dfs(dfsarg_cocsep_t *arg) if ((arg->buf32[i] & 0xFF) != 0xFF) return 0; + if (arg->rep != NULL) + arg->rep[*arg->n] = arg->cube; for (t = 0, cc = 0; t < 48; t++) { d = transform_corners(arg->cube, t); j = coord_cocsep(d); - is = (i == j); - if (arg->selfsim != NULL) - arg->selfsim[*arg->n] |= is << t; + if (i == j && arg->selfsim != NULL) + arg->selfsim[*arg->n] |= UINT64_C(1) << t; + if (COCLASS(arg->buf32[j]) != UINT32_C(0xFFFF)) + continue; set_visited(arg->visited, j); - tinv = inverse_trans(t) * (1-is); - olddepth = (uint8_t)(arg->buf32[j] & 0xFF); + tinv = inverse_trans(t); + olddepth = arg->buf32[j] & 0xFF; cc += olddepth == 0xFF; - class = (uint32_t)(*arg->n) << 16; - ttrep = (uint32_t)tinv << 8; + class = (uint32_t)(*arg->n) << UINT32_C(16); + ttrep = (uint32_t)tinv << UINT32_C(8); depth = (uint32_t)arg->depth; arg->buf32[j] = class | ttrep | depth; } - if (arg->rep != NULL) - arg->rep[*arg->n] = arg->cube; (*arg->n)++; return cc; @@ -467,6 +468,7 @@ gendata_h48h0k4_bfs_fromdone(bfsarg_esep_t *arg) transd = transform(moved, t); k = coord_h48(transd, arg->cocsepdata, 0); if (k != j) { +/* LOG("t=%" PRId64 ", tinv=%" PRIu8 "\n", t, inverse_trans(t)); int64_t ccm = coord_cocsep(moved); int64_t repm = coord_cocsep(arg->crep[j/H48_ESIZE(0)]); @@ -474,12 +476,6 @@ LOG("moved: full %" PRId64 ", cocsep %" PRId64 ", rep %" PRId64 ", ttrep %" PRId int64_t cct = coord_cocsep(transd); int64_t rept = coord_cocsep(arg->crep[k/H48_ESIZE(0)]); LOG("moved: full %" PRId64 ", cocsep %" PRId64 ", rep %" PRId64 ", ttrep %" PRId32 "\n", j, cct, rept, TTREP(arg->cocsepdata[cct])); -/* - char q[150]; - writecube_H48(moved, q); - LOG("%s\n", q) - writecube_H48(transd, q); - LOG("%s\n", q) */ } continue; diff --git a/test/103_cocsep_ttrep/cocsep_ttrep_tests.c b/test/103_cocsep_ttrep/cocsep_ttrep_tests.c @@ -1,17 +1,19 @@ #include "../test.h" #define COCSEP_CLASSES 3393 +#define TTREP_MASK (UINT32_C(0xFF) << UINT32_C(8)) +#define TTREP(x) (((x) & TTREP_MASK) >> UINT32_C(8)) uint8_t inverse_trans(uint8_t); -cube_t transform_corners(cube_t); +cube_t transform_corners(cube_t, uint8_t); int64_t coord_cocsep(cube_t); size_t gendata_cocsep(void *, uint64_t *, cube_t *); void run(void) { - uint8_t t, tinv; + uint8_t t; uint32_t buf[300000], tt; uint64_t selfsim[COCSEP_CLASSES]; - int64_t i, j; + int64_t i, j, k, l; cube_t rep[COCSEP_CLASSES], c, d; gendata_cocsep(buf, selfsim, rep); @@ -19,15 +21,16 @@ void run(void) { for (i = 0; i < COCSEP_CLASSES; i++) { c = rep[i]; for (t = 0; t < 48; t++) { - tinv = inverse_trans(t); - d = transform_corners(c); + d = transform_corners(c, t); j = coord_cocsep(d); - tt = (buf[j] & (0xFF << 8)) >> 8; - if (tt != tinv) - printf("cocsep %" PRId64 " <- %" PRId64 ": " - "expected t %" PRIu8 " (inverse of %" - PRIu8 "), got %" PRIu32 "\n", - i, j, tinv, t, tt); + tt = TTREP(buf[j]); + d = transform_corners(d, tt); + k = coord_cocsep(d); + l = coord_cocsep(c); + if (k != l) + printf("cocsep %" PRId64 " (%" PRId64 "): " + "%" PRId64 " ttrep %" PRIu8 + " -> %" PRId64 "\n", i, l, j, tt, k); } } }