nissy-core

The "engine" of nissy, including the H48 optimal solver.
git clone https://git.tronto.net/nissy-core
Download | Log | Files | Refs | README | LICENSE

commit bf3497420c9a12397dc13a34faf3ce3e456f3aa7
parent 037461be140429aaa80af75fcd110ee60ba410ee
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date:   Thu, 31 Jul 2025 13:09:42 +0200

Fix bug

Diffstat:
Msrc/solvers/coord/solve.h | 80+++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------
Msrc/solvers/solutions.h | 1-
2 files changed, 58 insertions(+), 23 deletions(-)

diff --git a/src/solvers/coord/solve.h b/src/solvers/coord/solve.h @@ -66,47 +66,83 @@ solve_coord_dfs_stop(const dfsarg_solve_coord_t arg[static 1]) STATIC bool coord_continue_onnormal(const dfsarg_solve_coord_t arg[static 1]) { - uint8_t f, nn, ni, th; + uint8_t flag, nn, ni, swbound_n, swbound_i; - f = arg->nissflag; + flag = arg->nissflag; nn = arg->solution_moves->nmoves; ni = arg->solution_moves->npremoves; - th = DIV_ROUND_UP(arg->target_depth, 2); + swbound_n = arg->target_depth / 2; + swbound_i = DIV_ROUND_UP(arg->target_depth, 2) - 1; + /* If only inverse moves are allowed */ + if (flag == NISSY_NISSFLAG_INVERSE) + return false; + + /* It's the first move */ if (nn + ni == 0) - return f & (NISSY_NISSFLAG_NORMAL | NISSY_NISSFLAG_MIXED); + return true; + + if (arg->lastisnormal) { + /* Can continue if we have already switched */ + if (ni > 0) + return true; - /* TODO logic here can probably be simplified */ - if (arg->lastisnormal) - return (f & NISSY_NISSFLAG_NORMAL) || - ((f & NISSY_NISSFLAG_MIXED) && (ni > 0 || nn <= th)); + /* Check that we have enough moves left to switch */ + return flag & NISSY_NISSFLAG_NORMAL || nn < swbound_n; + } else { + /* Forbid switching multiple times */ + if (nn > 0) + return false; + + /* Some coordinates are not allowed to switch */ + if (!coord_can_switch(arg->coord, arg->coord_data, + ni, arg->solution_moves->premoves)) + return false; - return (f & NISSY_NISSFLAG_MIXED) && nn == 0 && ni < th && - coord_can_switch(arg->coord, arg->coord_data, - ni, arg->solution_moves->premoves); + /* Only switch before half solution is found */ + return ni <= swbound_i; + } } STATIC bool coord_continue_oninverse(const dfsarg_solve_coord_t arg[static 1]) { - uint8_t f, nn, ni, th; + uint8_t flag, nn, ni, swbound_n, swbound_i; - f = arg->nissflag; + flag = arg->nissflag; nn = arg->solution_moves->nmoves; ni = arg->solution_moves->npremoves; - th = DIV_ROUND_UP(arg->target_depth, 2); + swbound_n = arg->target_depth / 2; + swbound_i = DIV_ROUND_UP(arg->target_depth, 2) - 1; + /* If only normal moves are allowed */ + if (flag == NISSY_NISSFLAG_NORMAL) + return false; + + /* It's the first move */ if (nn + ni == 0) - return f & (NISSY_NISSFLAG_INVERSE | NISSY_NISSFLAG_MIXED); + return true; + + if (!arg->lastisnormal) { + /* Can continue if we have already switched */ + if (nn > 0) + return true; - /* TODO logic here can probably be simplified */ - if (!arg->lastisnormal) - return (f & NISSY_NISSFLAG_INVERSE) || - ((f & NISSY_NISSFLAG_MIXED) && (nn > 0 || ni < th)); + /* Check that we have enough moves left to switch */ + return flag & NISSY_NISSFLAG_INVERSE || ni < swbound_i; + } else { + /* Forbid switching multiple times */ + if (ni > 0) + return false; + + /* Some coordinates are not allowed to switch */ + if (!coord_can_switch(arg->coord, arg->coord_data, + nn, arg->solution_moves->moves)) + return false; - return (f & NISSY_NISSFLAG_MIXED) && ni == 0 && nn <= th && - coord_can_switch(arg->coord, arg->coord_data, - nn, arg->solution_moves->moves); + /* Only switch before half solution is found */ + return nn <= swbound_n; + } } STATIC int64_t diff --git a/src/solvers/solutions.h b/src/solvers/solutions.h @@ -233,7 +233,6 @@ appendsolution( list->shortest_sol = MIN( list->shortest_sol, tsol[r].nmoves + tsol[r].npremoves); r++; - } list->buf[list->used] = '\0';