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 0083a7eb4677542aced3ea2fa335bc9cf1f7b419
parent 861a8a5fc4b62e5f70081f8e72b0854889a6cec6
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date:   Tue, 26 Dec 2023 18:29:25 +0100

Added coord_co

Diffstat:
MTODO.txt | 2++
Mcube.c | 45+++++++++++++++++++++++++++++++++++++++++----
Mtest/071_coord_eo/coord_eo_tests.c | 4++--
Atest/072_coord_co/00_solved.in | 1+
Atest/072_coord_co/00_solved.out | 1+
Atest/072_coord_co/01_U.in | 1+
Atest/072_coord_co/01_U.out | 1+
Atest/072_coord_co/02_U2.in | 1+
Atest/072_coord_co/02_U2.out | 1+
Atest/072_coord_co/03_U3.in | 1+
Atest/072_coord_co/03_U3.out | 1+
Atest/072_coord_co/04_D.in | 1+
Atest/072_coord_co/04_D.out | 1+
Atest/072_coord_co/07_R.in | 1+
Atest/072_coord_co/07_R.out | 1+
Atest/072_coord_co/08_R2.in | 1+
Atest/072_coord_co/08_R2.out | 1+
Atest/072_coord_co/10_L.in | 1+
Atest/072_coord_co/10_L.out | 1+
Atest/072_coord_co/13_F.in | 1+
Atest/072_coord_co/13_F.out | 1+
Atest/072_coord_co/14_F2.in | 1+
Atest/072_coord_co/14_F2.out | 1+
Atest/072_coord_co/16_B.in | 1+
Atest/072_coord_co/16_B.out | 1+
Atest/072_coord_co/17_B2.in | 1+
Atest/072_coord_co/17_B2.out | 1+
Atest/072_coord_co/20_scrambled.in | 3+++
Atest/072_coord_co/20_scrambled.out | 1+
Atest/072_coord_co/coord_co_tests.c | 21+++++++++++++++++++++
30 files changed, 94 insertions(+), 6 deletions(-)

diff --git a/TODO.txt b/TODO.txt @@ -1,5 +1,7 @@ ## (find better name) H48 solver, ideas +TODO next: implement cosep coordinate + First compute co + csep. Use csep as a binary number (2^8 instead of 70, loose a factor of 3.66 but still fits in a few megabytes or less). Use co + csep as an index in a table whose entries have: 6 bits for ttrep, diff --git a/cube.c b/cube.c @@ -509,6 +509,8 @@ _static_inline bool equal_fast(cube_fast_t, cube_fast_t); _static_inline bool issolved_fast(cube_fast_t); _static_inline cube_fast_t invertco_fast(cube_fast_t); _static_inline cube_fast_t compose_fast(cube_fast_t, cube_fast_t); + +_static_inline int64_t coord_fast_co(cube_fast_t); _static_inline int64_t coord_fast_eo(cube_fast_t); _static_inline cube_fast_t @@ -637,6 +639,22 @@ compose_fast(cube_fast_t c1, cube_fast_t c2) } _static_inline int64_t +coord_fast_co(cube_fast_t c) +{ + cube_fast_t co, shifted; + int64_t mem[4], ret, i, p; + + co = _mm256_and_si256(c, _co2_avx2); + _mm256_storeu_si256((__m256i *)mem, co); + + mem[0] >>= 5L; + for (i = 0, ret = 0, p = 1; i < 7; i++, mem[0] >>= 8L, p *= 3) + ret += (mem[0] & 3L) * p; + + return ret; +} + +_static_inline int64_t coord_fast_eo(cube_fast_t c) { cube_fast_t eo, shifted; @@ -689,6 +707,8 @@ _static_inline bool equal_fast(cube_fast_t, cube_fast_t); _static_inline bool issolved_fast(cube_fast_t); _static_inline cube_fast_t invertco_fast(cube_fast_t); _static_inline cube_fast_t compose_fast(cube_fast_t, cube_fast_t); + +_static_inline int64_t coord_fast_co(cube_fast_t); _static_inline int64_t coord_fast_eo(cube_fast_t); _static_inline cube_fast_t @@ -812,14 +832,25 @@ compose_fast(cube_fast_t c1, cube_fast_t c2) } _static_inline int64_t -coord_fast_eo(cube_fast_t cube) +coord_fast_co(cube_fast_t c) { int i, p; int64_t ret; - ret = 0; - for (i = 1, p = 1; i < 12; i++, p *= 2) - ret += p * (cube.edge[i] >> 4); + for (ret = 0, i = 0, p = 1; i < 7; i++, p *= 3) + ret += p * (c.corner[i] >> _coshift); + + return ret; +} + +_static_inline int64_t +coord_fast_eo(cube_fast_t c) +{ + int i, p; + int64_t ret; + + for (ret = 0, i = 1, p = 1; i < 12; i++, p *= 2) + ret += p * (c.edge[i] >> _eoshift); return ret; } @@ -1600,6 +1631,12 @@ moveaxis(uint8_t move) } /****************************************************************************** +Section: auxiliary procedures for H48 optimal solver (temporary) +******************************************************************************/ + + + +/****************************************************************************** Section: solvers Here you can find the implementation of all the solving algorithms. diff --git a/test/071_coord_eo/coord_eo_tests.c b/test/071_coord_eo/coord_eo_tests.c @@ -7,7 +7,7 @@ int main(void) { char str[STRLENMAX]; cube_t cube; cube_fast_t fast; - int16_t result; + int64_t result; fgets(str, STRLENMAX, stdin); cube = readcube("H48", str); @@ -15,7 +15,7 @@ int main(void) { result = coord_fast_eo(fast); - printf("%" PRId16 "\n", result); + printf("%" PRId64 "\n", result); return 0; } diff --git a/test/072_coord_co/00_solved.in b/test/072_coord_co/00_solved.in @@ -0,0 +1 @@ +UF0 UB0 DB0 DF0 UR0 UL0 DL0 DR0 FR0 FL0 BL0 BR0 UFR0 UBL0 DFL0 DBR0 UFL0 UBR0 DFR0 DBL0 diff --git a/test/072_coord_co/00_solved.out b/test/072_coord_co/00_solved.out @@ -0,0 +1 @@ +0 diff --git a/test/072_coord_co/01_U.in b/test/072_coord_co/01_U.in @@ -0,0 +1 @@ +UR0 UL0 DB0 DF0 UB0 UF0 DL0 DR0 FR0 FL0 BL0 BR0 UBR0 UFL0 DFL0 DBR0 UFR0 UBL0 DFR0 DBL0 diff --git a/test/072_coord_co/01_U.out b/test/072_coord_co/01_U.out @@ -0,0 +1 @@ +0 diff --git a/test/072_coord_co/02_U2.in b/test/072_coord_co/02_U2.in @@ -0,0 +1 @@ +UB0 UF0 DB0 DF0 UL0 UR0 DL0 DR0 FR0 FL0 BL0 BR0 UBL0 UFR0 DFL0 DBR0 UBR0 UFL0 DFR0 DBL0 diff --git a/test/072_coord_co/02_U2.out b/test/072_coord_co/02_U2.out @@ -0,0 +1 @@ +0 diff --git a/test/072_coord_co/03_U3.in b/test/072_coord_co/03_U3.in @@ -0,0 +1 @@ +UL0 UR0 DB0 DF0 UF0 UB0 DL0 DR0 FR0 FL0 BL0 BR0 UFL0 UBR0 DFL0 DBR0 UBL0 UFR0 DFR0 DBL0 diff --git a/test/072_coord_co/03_U3.out b/test/072_coord_co/03_U3.out @@ -0,0 +1 @@ +0 diff --git a/test/072_coord_co/04_D.in b/test/072_coord_co/04_D.in @@ -0,0 +1 @@ +UF0 UB0 DR0 DL0 UR0 UL0 DB0 DF0 FR0 FL0 BL0 BR0 UFR0 UBL0 DBL0 DFR0 UFL0 UBR0 DFL0 DBR0 diff --git a/test/072_coord_co/04_D.out b/test/072_coord_co/04_D.out @@ -0,0 +1 @@ +0 diff --git a/test/072_coord_co/07_R.in b/test/072_coord_co/07_R.in @@ -0,0 +1 @@ +UF0 UB0 DB0 DF0 FR0 UL0 DL0 BR0 DR0 FL0 BL0 UR0 DFR2 UBL0 DFL0 UBR2 UFL0 UFR1 DBR1 DBL0 diff --git a/test/072_coord_co/07_R.out b/test/072_coord_co/07_R.out @@ -0,0 +1 @@ +1028 diff --git a/test/072_coord_co/08_R2.in b/test/072_coord_co/08_R2.in @@ -0,0 +1 @@ +UF0 UB0 DB0 DF0 DR0 UL0 DL0 UR0 BR0 FL0 BL0 FR0 DBR0 UBL0 DFL0 UFR0 UFL0 DFR0 UBR0 DBL0 diff --git a/test/072_coord_co/08_R2.out b/test/072_coord_co/08_R2.out @@ -0,0 +1 @@ +0 diff --git a/test/072_coord_co/10_L.in b/test/072_coord_co/10_L.in @@ -0,0 +1 @@ +UF0 UB0 DB0 DF0 UR0 BL0 FL0 DR0 FR0 UL0 DL0 BR0 UFR0 DBL2 UFL2 DBR0 UBL1 UBR0 DFR0 DFL1 diff --git a/test/072_coord_co/10_L.out b/test/072_coord_co/10_L.out @@ -0,0 +1 @@ +105 diff --git a/test/072_coord_co/13_F.in b/test/072_coord_co/13_F.in @@ -0,0 +1 @@ +FL1 UB0 DB0 FR1 UR0 UL0 DL0 DR0 UF1 DF1 BL0 BR0 UFL1 UBL0 DFR1 DBR0 DFL2 UBR0 UFR2 DBL0 diff --git a/test/072_coord_co/13_F.out b/test/072_coord_co/13_F.out @@ -0,0 +1 @@ +1630 diff --git a/test/072_coord_co/14_F2.in b/test/072_coord_co/14_F2.in @@ -0,0 +1 @@ +DF0 UB0 DB0 UF0 UR0 UL0 DL0 DR0 FL0 FR0 BL0 BR0 DFL0 UBL0 UFR0 DBR0 DFR0 UBR0 UFL0 DBL0 diff --git a/test/072_coord_co/14_F2.out b/test/072_coord_co/14_F2.out @@ -0,0 +1 @@ +0 diff --git a/test/072_coord_co/16_B.in b/test/072_coord_co/16_B.in @@ -0,0 +1 @@ +UF0 BR1 BL1 DF0 UR0 UL0 DL0 DR0 FR0 FL0 UB1 DB1 UFR0 UBR1 DFL0 DBL1 UFL0 DBR2 DFR0 UBL2 diff --git a/test/072_coord_co/16_B.out b/test/072_coord_co/16_B.out @@ -0,0 +1 @@ +516 diff --git a/test/072_coord_co/17_B2.in b/test/072_coord_co/17_B2.in @@ -0,0 +1 @@ +UF0 DB0 UB0 DF0 UR0 UL0 DL0 DR0 FR0 FL0 BR0 BL0 UFR0 DBR0 DFL0 UBL0 UFL0 DBL0 DFR0 UBR0 diff --git a/test/072_coord_co/17_B2.out b/test/072_coord_co/17_B2.out @@ -0,0 +1 @@ +0 diff --git a/test/072_coord_co/20_scrambled.in b/test/072_coord_co/20_scrambled.in @@ -0,0 +1,3 @@ +UL0 BL0 BR1 DL0 FR0 DF0 DB1 DR1 UB0 FL0 UF0 UR1 DFL0 UFR1 DBR1 UBR2 DBL2 DFR0 UFL1 UBL2 + +// Scramble: U R D' L D' F L2 D L F B D2 B' L2 F U2 L2 D2 R2 L2 B' diff --git a/test/072_coord_co/20_scrambled.out b/test/072_coord_co/20_scrambled.out @@ -0,0 +1 @@ +957 diff --git a/test/072_coord_co/coord_co_tests.c b/test/072_coord_co/coord_co_tests.c @@ -0,0 +1,21 @@ +#include "../test.h" + +int64_t coord_fast_co(cube_fast_t); +cube_fast_t cubetofast(cube_t); + +int main(void) { + char str[STRLENMAX]; + cube_t cube; + cube_fast_t fast; + int64_t result; + + fgets(str, STRLENMAX, stdin); + cube = readcube("H48", str); + fast = cubetofast(cube); + + result = coord_fast_co(fast); + + printf("%" PRId64 "\n", result); + + return 0; +}