From 0550a16c1cce868bbc3f3b5ad59f80e35cf2a6cd Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Wed, 19 Mar 2025 17:16:41 +0100 Subject: Filter solutions for coordinate solver and fix ordering --- src/core/moves.h | 28 ++++++++++++++++++++++++++++ src/solvers/coord/eo.h | 1 + src/solvers/coord/solve.h | 8 +++++--- src/solvers/coord/types_macros.h | 1 + 4 files changed, 35 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/core/moves.h b/src/core/moves.h index 3a1158b..a45bc05 100644 --- a/src/core/moves.h +++ b/src/core/moves.h @@ -6,6 +6,8 @@ STATIC_INLINE uint32_t allowednextmove_mask(uint8_t *, uint8_t); STATIC_INLINE uint8_t movebase(uint8_t); STATIC_INLINE uint8_t moveaxis(uint8_t); +STATIC_INLINE bool isbase(uint8_t); +STATIC_INLINE bool parallel(uint8_t, uint8_t); STATIC_INLINE uint32_t disable_moves(uint32_t, uint8_t); STATIC cube_t move(cube_t, uint8_t); @@ -13,6 +15,7 @@ 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 bool are_lastmoves_singlecw(int n, uint8_t [n]); STATIC int readmoves(const char *, int, uint8_t *); STATIC cube_t applymoves(cube_t, const char *); @@ -91,6 +94,18 @@ moveaxis(uint8_t move) return move / 6; } +STATIC_INLINE bool +isbase(uint8_t move) +{ + return move == 3 * movebase(move); +} + +STATIC_INLINE bool +parallel(uint8_t m1, uint8_t m2) +{ + return moveaxis(m1) == moveaxis(m2); +} + STATIC_INLINE uint8_t moveopposite(uint8_t move) { @@ -241,6 +256,19 @@ sortparallel(uint8_t *moves, uint8_t n) SWAP(moves[i], moves[i+1]); } +STATIC bool +are_lastmoves_singlecw(int n, uint8_t moves[n]) +{ + bool two; + + if (n == 0) + return true; + + two = n > 1 && parallel(moves[n-1], moves[n-2]); + + return isbase(moves[n-1]) && (!two || isbase(moves[n-2])); +} + STATIC int readmoves(const char *buf, int max, uint8_t *ret) { diff --git a/src/solvers/coord/eo.h b/src/solvers/coord/eo.h index 449397f..46a6f70 100644 --- a/src/solvers/coord/eo.h +++ b/src/solvers/coord/eo.h @@ -15,6 +15,7 @@ STATIC coord_t coordinate_eo = { [AXIS_RL] = TRANS_URr, [AXIS_FB] = TRANS_UFr, }, + .is_admissible = &are_lastmoves_singlecw, }; STATIC uint64_t diff --git a/src/solvers/coord/solve.h b/src/solvers/coord/solve.h index 73ae9b1..6903d1e 100644 --- a/src/solvers/coord/solve.h +++ b/src/solvers/coord/solve.h @@ -35,15 +35,17 @@ solve_coord_appendsolution(dfsarg_solve_coord_t *arg) char *m; if (*arg->nsols >= arg->maxsolutions || - arg->nmoves > *arg->shortest_sol + arg->optimal) + arg->nmoves > *arg->shortest_sol + arg->optimal || + (arg->coord->is_admissible != NULL && + !arg->coord->is_admissible(arg->nmoves, arg->moves))) return 0; - sortparallel(arg->moves, arg->nmoves); - t = inverse_trans(arg->trans); for (i = 0; i < arg->nmoves; i++) tmoves[i] = transform_move(arg->moves[i], t); + sortparallel(tmoves, arg->nmoves); + l = arg->solutions_size - *arg->solutions_used; m = *arg->solutions + *arg->solutions_used; strl = writemoves(tmoves, arg->nmoves, l, m); diff --git a/src/solvers/coord/types_macros.h b/src/solvers/coord/types_macros.h index 84085ad..2309efc 100644 --- a/src/solvers/coord/types_macros.h +++ b/src/solvers/coord/types_macros.h @@ -11,4 +11,5 @@ typedef struct { uint32_t moves_mask; uint64_t trans_mask; uint8_t axistrans[3]; + bool (*is_admissible)(int n, uint8_t [n]); } coord_t; -- cgit v1.3