From b0053277e385bee23336d1fe6b69a12f49f9172f Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Tue, 1 Apr 2025 09:33:26 +0200 Subject: simplified allowedmoves logic --- src/solvers/coord/solve.h | 14 ++++++++++++-- src/solvers/h48/gendata_h48.h | 4 ++-- src/solvers/h48/solve.h | 21 ++++++++++++++++----- src/solvers/solutions.h | 2 +- 4 files changed, 31 insertions(+), 10 deletions(-) (limited to 'src/solvers') diff --git a/src/solvers/coord/solve.h b/src/solvers/coord/solve.h index c3fbd02..fa4134a 100644 --- a/src/solvers/coord/solve.h +++ b/src/solvers/coord/solve.h @@ -135,7 +135,12 @@ solve_coord_dfs(dfsarg_solve_coord_t arg[static 1]) ret = 0; if (coord_continue_onnormal(arg)) { l = arg->solution_moves->nmoves; - mm = allowednextmove_mask(l, arg->solution_moves->moves); + if (l == 0) { + mm = MM_ALLMOVES; + } else { + m = arg->solution_moves->moves[l-1]; + mm = allowedmask[movebase(m)]; + } arg->solution_moves->nmoves++; arg->lastisnormal = true; @@ -160,7 +165,12 @@ solve_coord_dfs(dfsarg_solve_coord_t arg[static 1]) if (coord_continue_oninverse(arg)) { l = arg->solution_moves->npremoves; - mm = allowednextmove_mask(l, arg->solution_moves->premoves); + if (l == 0) { + mm = MM_ALLMOVES; + } else { + m = arg->solution_moves->premoves[l-1]; + mm = allowedmask[movebase(m)]; + } arg->solution_moves->npremoves++; arg->lastisnormal = false; diff --git a/src/solvers/h48/gendata_h48.h b/src/solvers/h48/gendata_h48.h index 959264d..b6647ed 100644 --- a/src/solvers/h48/gendata_h48.h +++ b/src/solvers/h48/gendata_h48.h @@ -526,7 +526,7 @@ gendata_h48k2_dfs(h48k2_dfs_arg_t arg[static 1]) /* Depth d+3 */ for (m[2] = 0; m[2] < 18; m[2]++) { markarg.depth = d+3; - if (!allowednextmove(3, m)) { + if (!allowednextmove(m[1], m[2])) { m[2] += 2; continue; } @@ -541,7 +541,7 @@ gendata_h48k2_dfs(h48k2_dfs_arg_t arg[static 1]) /* Depth d+4 */ for (m[3] = 0; m[3] < 18; m[3]++) { markarg.depth = d+4; - if (!allowednextmove(4, m)) { + if (!allowednextmove(m[2], m[3])) { m[3] += 2; continue; } diff --git a/src/solvers/h48/solve.h b/src/solvers/h48/solve.h index dcec5a4..fc7631f 100644 --- a/src/solvers/h48/solve.h +++ b/src/solvers/h48/solve.h @@ -176,10 +176,16 @@ solve_h48_dfs(dfsarg_solve_h48_t arg[static 1]) ulbi = arg->use_lb_inverse; ret = 0; - mm_normal = allowednextmove_mask(arg->solution_moves->nmoves, - arg->solution_moves->moves) & arg->movemask_normal; - mm_inverse = allowednextmove_mask(arg->solution_moves->npremoves, - arg->solution_moves->premoves) & arg->movemask_inverse; + mm_normal = arg->movemask_normal; + if (arg->solution_moves->nmoves > 0) { + m = arg->solution_moves->moves[arg->solution_moves->nmoves-1]; + mm_normal &= allowedmask[movebase(m)]; + } + mm_inverse = arg->movemask_inverse; + if (arg->solution_moves->npremoves > 0) { + m = arg->solution_moves->premoves[arg->solution_moves->npremoves-1]; + mm_inverse &= allowedmask[movebase(m)]; + } if (popcount_u32(mm_normal) <= popcount_u32(mm_inverse)) { arg->solution_moves->nmoves++; for (m = 0; m < 18; m++) { @@ -299,7 +305,12 @@ solve_h48_maketasks( return NISSY_OK; } - mm = allowednextmove_mask(maketasks_arg->nmoves, maketasks_arg->moves); + if (maketasks_arg->nmoves == 0) { + mm = MM_ALLMOVES; + } else { + m = maketasks_arg->moves[maketasks_arg->nmoves-1]; + mm = allowedmask[movebase(m)]; + } maketasks_arg->nmoves++; backup_cube = maketasks_arg->cube; diff --git a/src/solvers/solutions.h b/src/solvers/solutions.h index bbff9cf..1b5517c 100644 --- a/src/solvers/solutions.h +++ b/src/solvers/solutions.h @@ -128,7 +128,7 @@ appendsolution( /* This is a bit ugly: we have to sort now and then again - later, because the allowednext check would fail with + later, because the allowedmoves check would fail with improperly sorted parallel moves, but then transforming could swap the pairs the wrong way around. TODO: maybe fix this -- cgit v1.3