aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/solvers/h48/solve.h102
1 files changed, 62 insertions, 40 deletions
diff --git a/src/solvers/h48/solve.h b/src/solvers/h48/solve.h
index 6a29b82..2abc4c9 100644
--- a/src/solvers/h48/solve.h
+++ b/src/solvers/h48/solve.h
@@ -68,8 +68,10 @@ STATIC_INLINE void h48_prune_pipeline(dfsarg_solve_h48_t [static 1],
68 h48_prune_t [static NMOVES], uint8_t, bool); 68 h48_prune_t [static NMOVES], uint8_t, bool);
69STATIC_INLINE uint8_t h48_prune_lookup( 69STATIC_INLINE uint8_t h48_prune_lookup(
70 uint64_t, cube_t, dfsarg_solve_h48_t [static 1]); 70 uint64_t, cube_t, dfsarg_solve_h48_t [static 1]);
71STATIC_INLINE void h48_prune_restore(const h48_prune_t [static 1], 71STATIC_INLINE void h48_prune_restore_normal(const h48_prune_t [static 1],
72 dfsarg_solve_h48_t [static 1], uint8_t, bool); 72 dfsarg_solve_h48_t [static 1], uint8_t);
73STATIC_INLINE void h48_prune_restore_inverse(const h48_prune_t [static 1],
74 dfsarg_solve_h48_t [static 1], uint8_t);
73STATIC int64_t solve_h48_maketasks( 75STATIC int64_t solve_h48_maketasks(
74 dfsarg_solve_h48_t [static 1], dfsarg_solve_h48_maketasks_t [static 1], 76 dfsarg_solve_h48_t [static 1], dfsarg_solve_h48_maketasks_t [static 1],
75 solve_h48_task_t [static H48_STARTING_CUBES], int [static 1]); 77 solve_h48_task_t [static H48_STARTING_CUBES], int [static 1]);
@@ -229,34 +231,46 @@ h48_prune_pipeline(
229} 231}
230 232
231STATIC_INLINE void 233STATIC_INLINE void
232h48_prune_restore( 234h48_prune_restore_normal(
233 const h48_prune_t prune[static 1], 235 const h48_prune_t prune[static 1],
234 dfsarg_solve_h48_t arg[static 1], 236 dfsarg_solve_h48_t arg[static 1],
235 uint8_t target, 237 uint8_t target
236 bool normal
237) 238)
238{ 239{
239 uint8_t nm; 240 uint8_t nm;
240 241
241 if (normal) { 242 arg->cube = prune->cube;
242 arg->cube = prune->cube; 243 arg->inverse = prune->inverse;
243 arg->inverse = prune->inverse; 244 arg->lb_inverse = prune->pi;
244 arg->lb_inverse = prune->pi; 245 arg->lb_normal = prune->pn;
245 arg->lb_normal = prune->pn;
246 246
247 nm = arg->solution_moves->nmoves; 247 nm = arg->solution_moves->nmoves;
248 arg->solution_moves->moves[nm-1] = prune->m; 248 arg->solution_moves->moves[nm-1] = prune->m;
249 arg->movemask_normal = allowedmask[movebase(prune->m)]; 249 arg->movemask_normal = allowedmask[movebase(prune->m)];
250 } else {
251 arg->cube = prune->inverse;
252 arg->inverse = prune->cube;
253 arg->lb_inverse = prune->pn;
254 arg->lb_normal = prune->pi;
255 250
256 nm = arg->solution_moves->npremoves; 251 if (arg->lb_inverse == target)
257 arg->solution_moves->premoves[nm-1] = prune->m; 252 arg->movemask_normal &= MM18_NOHALFTURNS;
258 arg->movemask_inverse = allowedmask[movebase(prune->m)]; 253 if (arg->lb_normal == target)
259 } 254 arg->movemask_inverse &= MM18_NOHALFTURNS;
255}
256
257STATIC_INLINE void
258h48_prune_restore_inverse(
259 const h48_prune_t prune[static 1],
260 dfsarg_solve_h48_t arg[static 1],
261 uint8_t target
262)
263{
264 uint8_t nm;
265
266 arg->cube = prune->inverse;
267 arg->inverse = prune->cube;
268 arg->lb_inverse = prune->pn;
269 arg->lb_normal = prune->pi;
270
271 nm = arg->solution_moves->npremoves;
272 arg->solution_moves->premoves[nm-1] = prune->m;
273 arg->movemask_inverse = allowedmask[movebase(prune->m)];
260 274
261 if (arg->lb_inverse == target) 275 if (arg->lb_inverse == target)
262 arg->movemask_normal &= MM18_NOHALFTURNS; 276 arg->movemask_normal &= MM18_NOHALFTURNS;
@@ -301,27 +315,35 @@ solve_h48_dfs(dfsarg_solve_h48_t arg[static 1])
301 315
302 h48_prune_pipeline(arg, prune, target, normal); 316 h48_prune_pipeline(arg, prune, target, normal);
303 317
304 if (normal) 318 if (normal) {
305 arg->solution_moves->nmoves++; 319 arg->solution_moves->nmoves++;
306 else 320 for (m = 0; m < NMOVES; m++) {
307 arg->solution_moves->npremoves++; 321 if (prune[m].stop)
308 322 continue;
309 for (m = 0; m < NMOVES; m++) { 323 arg->movemask_normal = mm_normal;
310 if (prune[m].stop) 324 arg->movemask_inverse = mm_inverse;
311 continue; 325 h48_prune_restore_normal(&prune[m], arg, target);
312 arg->movemask_normal = mm_normal; 326 n = solve_h48_dfs(arg);
313 arg->movemask_inverse = mm_inverse; 327 if (n < 0)
314 h48_prune_restore(&prune[m], arg, target, normal); 328 return n;
315 n = solve_h48_dfs(arg); 329 ret += n;
316 if (n < 0) 330 }
317 return n;
318 ret += n;
319 }
320
321 if (normal)
322 arg->solution_moves->nmoves--; 331 arg->solution_moves->nmoves--;
323 else 332 } else {
333 arg->solution_moves->npremoves++;
334 for (m = 0; m < NMOVES; m++) {
335 if (prune[m].stop)
336 continue;
337 arg->movemask_normal = mm_normal;
338 arg->movemask_inverse = mm_inverse;
339 h48_prune_restore_inverse(&prune[m], arg, target);
340 n = solve_h48_dfs(arg);
341 if (n < 0)
342 return n;
343 ret += n;
344 }
324 arg->solution_moves->npremoves--; 345 arg->solution_moves->npremoves--;
346 }
325 347
326 arg->cube = backup_cube; 348 arg->cube = backup_cube;
327 arg->inverse = backup_inverse; 349 arg->inverse = backup_inverse;

Generated with cgit - Back to sebastiano.tronto.net