From 99b746a01c11e061c4bd42cf096d27be9507ae21 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Sun, 15 Dec 2024 16:55:01 +0100 Subject: Fix rare bug, but one more bug to go --- src/core/moves.h | 12 ++++++++++++ src/solvers/h48/solve.h | 8 ++++---- 2 files changed, 16 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/core/moves.h b/src/core/moves.h index 037944b..3a1158b 100644 --- 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 index c415370..9f0cb78 100644 --- 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++) { -- cgit v1.3