diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2024-09-18 17:21:36 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2024-09-18 17:21:36 +0200 |
| commit | 89173fe1a7e839191a92ab82f79b42af46b1f9bc (patch) | |
| tree | f75111451cdb1cfb650bd1a2518d3a57c8b99671 /src/solvers/h48/solve.h | |
| parent | 59baae55d72f3aae5ff0d656bf3a3cda7795a879 (diff) | |
| download | nissy-core-89173fe1a7e839191a92ab82f79b42af46b1f9bc.tar.gz nissy-core-89173fe1a7e839191a92ab82f79b42af46b1f9bc.zip | |
Split solve h48 from stats
Diffstat (limited to 'src/solvers/h48/solve.h')
| -rw-r--r-- | src/solvers/h48/solve.h | 100 |
1 files changed, 0 insertions, 100 deletions
diff --git a/src/solvers/h48/solve.h b/src/solvers/h48/solve.h index 4bf55ca..b67aedc 100644 --- a/src/solvers/h48/solve.h +++ b/src/solvers/h48/solve.h | |||
| @@ -16,16 +16,6 @@ typedef struct { | |||
| 16 | uint8_t premoves[MAXLEN]; | 16 | uint8_t premoves[MAXLEN]; |
| 17 | } dfsarg_solveh48_t; | 17 | } dfsarg_solveh48_t; |
| 18 | 18 | ||
| 19 | typedef struct { | ||
| 20 | cube_t cube; | ||
| 21 | int8_t nmoves; | ||
| 22 | int8_t depth; | ||
| 23 | uint8_t moves[MAXLEN]; | ||
| 24 | uint32_t *cocsepdata; | ||
| 25 | uint8_t *h48data; | ||
| 26 | char *s; | ||
| 27 | } dfsarg_solveh48stats_t; | ||
| 28 | |||
| 29 | STATIC uint32_t allowednextmove_h48(uint8_t *, uint8_t, uint32_t); | 19 | STATIC uint32_t allowednextmove_h48(uint8_t *, uint8_t, uint32_t); |
| 30 | 20 | ||
| 31 | STATIC void solve_h48_appendsolution(dfsarg_solveh48_t *); | 21 | STATIC void solve_h48_appendsolution(dfsarg_solveh48_t *); |
| @@ -33,9 +23,6 @@ STATIC_INLINE bool solve_h48_stop(dfsarg_solveh48_t *); | |||
| 33 | STATIC int64_t solve_h48_dfs(dfsarg_solveh48_t *); | 23 | STATIC int64_t solve_h48_dfs(dfsarg_solveh48_t *); |
| 34 | STATIC int64_t solve_h48(cube_t, int8_t, int8_t, int8_t, const void *, char *); | 24 | STATIC int64_t solve_h48(cube_t, int8_t, int8_t, int8_t, const void *, char *); |
| 35 | 25 | ||
| 36 | STATIC int64_t solve_h48stats_dfs(dfsarg_solveh48stats_t *); | ||
| 37 | STATIC int64_t solve_h48stats(cube_t, int8_t, const void *, char [static 12]); | ||
| 38 | |||
| 39 | STATIC uint32_t | 26 | STATIC uint32_t |
| 40 | allowednextmove_h48(uint8_t *moves, uint8_t n, uint32_t h48branch) | 27 | allowednextmove_h48(uint8_t *moves, uint8_t n, uint32_t h48branch) |
| 41 | { | 28 | { |
| @@ -215,90 +202,3 @@ solve_h48( | |||
| 215 | 202 | ||
| 216 | return nsols; | 203 | return nsols; |
| 217 | } | 204 | } |
| 218 | |||
| 219 | /* | ||
| 220 | The h48stats solver computes how many moves it takes to solve to | ||
| 221 | each of the 12 h48 coordinates, one for each value of h from 0 to 11. | ||
| 222 | The solutions array is filled with the length of the solutions. The | ||
| 223 | solution array is therefore not a printable string. | ||
| 224 | */ | ||
| 225 | STATIC int64_t | ||
| 226 | solve_h48stats_dfs(dfsarg_solveh48stats_t *arg) | ||
| 227 | { | ||
| 228 | const int64_t limit = 11; | ||
| 229 | |||
| 230 | int8_t bound, u; | ||
| 231 | uint8_t m; | ||
| 232 | uint32_t d; | ||
| 233 | int64_t coord, h; | ||
| 234 | dfsarg_solveh48stats_t nextarg; | ||
| 235 | |||
| 236 | /* Check cocsep lower bound (corners only) */ | ||
| 237 | bound = get_h48_cdata(arg->cube, arg->cocsepdata, &d); | ||
| 238 | if (bound + arg->nmoves > arg->depth) | ||
| 239 | return 0; | ||
| 240 | |||
| 241 | /* Check h48 lower bound for h=0 (esep, but no eo) */ | ||
| 242 | coord = coord_h48_edges(arg->cube, COCLASS(d), TTREP(d), 0); | ||
| 243 | bound = get_h48_bound(arg->cube, d, 0, 4, arg->h48data); | ||
| 244 | if (bound + arg->nmoves > arg->depth) | ||
| 245 | return 0; | ||
| 246 | |||
| 247 | /* Update all other values, if solved */ | ||
| 248 | coord = coord_h48_edges(arg->cube, COCLASS(d), TTREP(d), 11); | ||
| 249 | for (h = 0; h <= limit; h++) { | ||
| 250 | u = coord >> (11-h) == 0 && arg->s[h] == 99; | ||
| 251 | arg->s[h] = u * arg->nmoves + (1-u) * arg->s[h]; | ||
| 252 | } | ||
| 253 | |||
| 254 | if (arg->s[limit] != 99) | ||
| 255 | return 0; | ||
| 256 | |||
| 257 | nextarg = *arg; | ||
| 258 | nextarg.nmoves = arg->nmoves + 1; | ||
| 259 | for (m = 0; m < 18; m++) { | ||
| 260 | nextarg.moves[arg->nmoves] = m; | ||
| 261 | if (!allowednextmove(nextarg.moves, nextarg.nmoves)) { | ||
| 262 | /* If a move is not allowed, neither are its 180 | ||
| 263 | * and 270 degree variations */ | ||
| 264 | m += 2; | ||
| 265 | continue; | ||
| 266 | } | ||
| 267 | nextarg.cube = move(arg->cube, m); | ||
| 268 | solve_h48stats_dfs(&nextarg); | ||
| 269 | } | ||
| 270 | |||
| 271 | return 0; | ||
| 272 | } | ||
| 273 | |||
| 274 | STATIC int64_t | ||
| 275 | solve_h48stats( | ||
| 276 | cube_t cube, | ||
| 277 | int8_t maxmoves, | ||
| 278 | const void *data, | ||
| 279 | char solutions[static 12] | ||
| 280 | ) | ||
| 281 | { | ||
| 282 | int i; | ||
| 283 | dfsarg_solveh48stats_t arg; | ||
| 284 | |||
| 285 | arg = (dfsarg_solveh48stats_t) { | ||
| 286 | .cube = cube, | ||
| 287 | .cocsepdata = get_cocsepdata_ptr(data), | ||
| 288 | .h48data = get_h48data_ptr(data), | ||
| 289 | .s = solutions | ||
| 290 | }; | ||
| 291 | |||
| 292 | for (i = 0; i < 12; i++) | ||
| 293 | solutions[i] = (char)99; | ||
| 294 | |||
| 295 | for (arg.depth = 0; | ||
| 296 | arg.depth <= maxmoves && solutions[11] == 99; | ||
| 297 | arg.depth++) | ||
| 298 | { | ||
| 299 | arg.nmoves = 0; | ||
| 300 | solve_h48stats_dfs(&arg); | ||
| 301 | } | ||
| 302 | |||
| 303 | return 0; | ||
| 304 | } | ||
