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 99b746a01c11e061c4bd42cf096d27be9507ae21
parent de70dc746f16607e2110f2c6acee8ed8ba2507f8
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date:   Sun, 15 Dec 2024 16:55:01 +0100

Fix rare bug, but one more bug to go

Diffstat:
Msrc/core/moves.h | 12++++++++++++
Msrc/solvers/h48/solve.h | 8++++----
2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/src/core/moves.h b/src/core/moves.h @@ -12,6 +12,7 @@ STATIC cube_t move(cube_t, uint8_t); STATIC cube_t premove(cube_t, uint8_t); STATIC uint8_t inverse_move(uint8_t); STATIC void invertmoves(uint8_t *, uint8_t, uint8_t *); +STATIC void sortparallel(uint8_t *, uint8_t); STATIC int readmoves(const char *, int, uint8_t *); STATIC cube_t applymoves(cube_t, const char *); @@ -229,6 +230,17 @@ invertmoves(uint8_t *moves, uint8_t nmoves, uint8_t *ret) } #pragma GCC pop_options +STATIC void +sortparallel(uint8_t *moves, uint8_t n) +{ + uint8_t i; + + for (i = 0; i < n-1; i++) + if (moveaxis(moves[i]) == moveaxis(moves[i+1]) && + movebase(moves[i]) == movebase(moves[i+1]) + 1) + SWAP(moves[i], moves[i+1]); +} + STATIC int readmoves(const char *buf, int max, uint8_t *ret) { diff --git a/src/solvers/h48/solve.h b/src/solvers/h48/solve.h @@ -78,6 +78,9 @@ solve_h48_appendsolution(dfsarg_solve_h48_t *arg) invertmoves(arg->premoves, arg->npremoves, arg->moves + arg->nmoves); + /* Sort parallel moves for consistency */ + sortparallel(arg->moves, arg->nmoves + arg->npremoves); + /* Do not append the solution in case premoves cancel with normal */ if (arg->npremoves > 0 && !allowednextmove(arg->moves, arg->nmoves+1)) return 0; @@ -106,10 +109,7 @@ solve_h48_appendallsym(dfsarg_solve_h48_t *arg) all[j][i] = transform_move(arg->moves[i], t); /* Sort parallel moves for consistency */ - for (i = 0; i < n - 1; i++) - if (moveaxis(all[j][i]) == moveaxis(all[j][i+1]) && - movebase(all[j][i]) == movebase(all[j][i+1]) + 1) - SWAP(all[j][i], all[j][i+1]); + sortparallel(all[j], n); /* Check for duplicate solutions */ for (k = 0; k < j; k++) {