From 039267a278bb9e0580e8aebd85ef5f3ed774688f Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Wed, 23 Apr 2025 14:42:28 +0200 Subject: Adjusted solvers, fixed bug --- src/solvers/coord/solve.h | 17 +++++++++-------- src/solvers/h48/solve.h | 15 ++++++++------- src/solvers/solutions.h | 18 +++++++++++++++++- src/solvers/solutions_types_macros.h | 1 + 4 files changed, 35 insertions(+), 16 deletions(-) (limited to 'src/solvers') diff --git a/src/solvers/coord/solve.h b/src/solvers/coord/solve.h index fb996ac..48cc704 100644 --- a/src/solvers/coord/solve.h +++ b/src/solvers/coord/solve.h @@ -12,12 +12,12 @@ typedef struct { const unsigned char *ptable; } dfsarg_solve_coord_t; -STATIC int64_t solve_coord(cube_t, coord_t [static 1], uint8_t, uint8_t, +STATIC int64_t solve_coord(oriented_cube_t, coord_t [static 1], uint8_t, + uint8_t, uint8_t, uint8_t, uint64_t, uint8_t, uint8_t, uint64_t, + const unsigned char *, size_t n, char [n]); +STATIC int64_t solve_coord_dispatch(oriented_cube_t, const char *, uint8_t, uint8_t, uint8_t, uint64_t, uint8_t, uint8_t, uint64_t, const unsigned char *, size_t n, char [n]); -STATIC int64_t solve_coord_dispatch(cube_t, const char *, uint8_t, uint8_t, - uint8_t, uint64_t, uint8_t, uint8_t, uint64_t, const unsigned char *, - size_t n, char [n]); STATIC bool coord_solution_admissible(const dfsarg_solve_coord_t [static 1]); STATIC bool solve_coord_dfs_stop(const dfsarg_solve_coord_t [static 1]); STATIC bool coord_continue_onnormal(const dfsarg_solve_coord_t [static 1]); @@ -200,7 +200,7 @@ solve_coord_dfs(dfsarg_solve_coord_t arg[static 1]) STATIC int64_t solve_coord_dispatch( - cube_t cube, + oriented_cube_t oc, const char *coord_and_axis, uint8_t nissflag, uint8_t minmoves, @@ -231,14 +231,14 @@ solve_coord_dispatch( return NISSY_ERROR_INVALID_SOLVER; } - return solve_coord(cube, coord, axis, nissflag, minmoves, maxmoves, + return solve_coord(oc, coord, axis, nissflag, minmoves, maxmoves, maxsolutions, optimal, threads, data_size, data, solutions_size, sols); } STATIC int64_t solve_coord( - cube_t cube, + oriented_cube_t oc, coord_t coord [static 1], uint8_t axis, uint8_t nissflag, @@ -266,7 +266,7 @@ solve_coord( solution_list_t solution_list; t = coord->axistrans[axis]; - c = transform(cube, t); + c = transform(oc.cube, t); if (!coord->is_solvable(c)) goto solve_coord_error_unsolvable; @@ -295,6 +295,7 @@ solve_coord( .maxmoves = maxmoves, .maxsolutions = maxsolutions, .optimal = optimal, + .orientation = oc.orientation, }; arg = (dfsarg_solve_coord_t) { diff --git a/src/solvers/h48/solve.h b/src/solvers/h48/solve.h index d19309b..86c590a 100644 --- a/src/solvers/h48/solve.h +++ b/src/solvers/h48/solve.h @@ -52,8 +52,8 @@ STATIC int64_t solve_h48_maketasks( solve_h48_task_t [static STARTING_CUBES], int [static 1]); STATIC void *solve_h48_runthread(void *); STATIC int64_t solve_h48_dfs(dfsarg_solve_h48_t [static 1]); -STATIC int64_t solve_h48(cube_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, - uint64_t, const unsigned char *, size_t n, char [n], +STATIC int64_t solve_h48(oriented_cube_t, uint8_t, uint8_t, uint8_t, uint8_t, + uint8_t, uint64_t, const unsigned char *, size_t n, char [n], long long [static NISSY_SIZE_SOLVE_STATS]); STATIC_INLINE bool @@ -342,7 +342,7 @@ solve_h48_maketasks( STATIC int64_t solve_h48( - cube_t cube, + oriented_cube_t oc, uint8_t minmoves, uint8_t maxmoves, uint8_t maxsolutions, @@ -407,17 +407,18 @@ solve_h48( fallback2 = h48data + offset; settings = (solution_settings_t) { - .tmask = symmetry_mask(cube), + .tmask = symmetry_mask(oc.cube), .unniss = true, .maxmoves = maxmoves, .maxsolutions = maxsolutions, .optimal = optimal, + .orientation = oc.orientation, }; for (i = 0; i < threads; i++) { arg[i] = (dfsarg_solve_h48_t) { - .start_cube = cube, - .cube = cube, + .start_cube = oc.cube, + .cube = oc.cube, .h = info.h48h, .k = info.bits, .base = info.base, @@ -441,7 +442,7 @@ solve_h48( pthread_mutex_init(&solutions_mutex, NULL); maketasks_arg = (dfsarg_solve_h48_maketasks_t) { - .cube = cube, + .cube = oc.cube, .nmoves = 0, .minmoves = minmoves, .maxmoves = maxmoves, diff --git a/src/solvers/solutions.h b/src/solvers/solutions.h index 2340a80..75d0804 100644 --- a/src/solvers/solutions.h +++ b/src/solvers/solutions.h @@ -1,5 +1,6 @@ STATIC void solution_moves_reset(solution_moves_t [static 1]); -STATIC void solution_moves_transform(solution_moves_t [static 1], uint8_t t); +STATIC void solution_moves_transform(solution_moves_t [static 1], uint8_t); +STATIC void solution_moves_reorient(solution_moves_t [static 1], uint8_t); STATIC bool solution_list_init( solution_list_t [static 1], size_t n, char [n]); STATIC bool solution_moves_equal( @@ -35,6 +36,20 @@ solution_moves_transform(solution_moves_t moves[static 1], uint8_t t) moves->premoves[i] = transform_move(moves->premoves[i], t); } +STATIC void +solution_moves_reorient(solution_moves_t moves[static 1], uint8_t or) +{ + uint8_t i; + + for (i = 0; i < moves->nmoves; i++) + moves->moves[i] = + inverse_reorient_move(moves->moves[i], or); + + for (i = 0; i < moves->npremoves; i++) + moves->premoves[i] = + inverse_reorient_move(moves->premoves[i], or); +} + STATIC bool solution_list_init(solution_list_t sols[static 1], size_t n, char buf[n]) { @@ -187,6 +202,7 @@ appendsolution( continue; } solution_moves_transform(&tsol[r], t); + solution_moves_reorient(&tsol[r], settings->orientation); sortparallel_moves(tsol[r].nmoves, tsol[r].moves); sortparallel_moves(tsol[r].npremoves, tsol[r].premoves); diff --git a/src/solvers/solutions_types_macros.h b/src/solvers/solutions_types_macros.h index 9b1431f..f1cb517 100644 --- a/src/solvers/solutions_types_macros.h +++ b/src/solvers/solutions_types_macros.h @@ -13,6 +13,7 @@ typedef struct { uint8_t maxmoves; uint64_t maxsolutions; uint8_t optimal; + uint8_t orientation; } solution_settings_t; typedef struct { -- cgit v1.3