diff options
| author | Sebastiano Tronto <sebastiano.tronto@gmail.com> | 2021-12-26 00:36:39 +0100 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano.tronto@gmail.com> | 2021-12-26 00:36:39 +0100 |
| commit | b82df53eb461506984eb2b6a9b53e445b75e46af (patch) | |
| tree | 56140ec158318b67d8673993acc123c0ed3c5992 | |
| parent | ce4d6f93c8d00a56b9356d0c0d8489c28e1459df (diff) | |
| download | nissy-b82df53eb461506984eb2b6a9b53e445b75e46af.tar.gz nissy-b82df53eb461506984eb2b6a9b53e445b75e46af.zip | |
Better trans-detection system (for e.g. drfin for HTR scramble)
| -rw-r--r-- | TODO.md | 10 | ||||
| -rwxr-xr-x | nissy | bin | 322224 -> 317952 bytes | |||
| -rwxr-xr-x | nissy.exe | bin | 783820 -> 782089 bytes | |||
| -rw-r--r-- | src/cubetypes.h | 4 | ||||
| -rw-r--r-- | src/solve.c | 73 | ||||
| -rw-r--r-- | src/steps.c | 165 |
6 files changed, 97 insertions, 155 deletions
| @@ -24,8 +24,6 @@ including e.g. solutions that were not shown because -c) | |||
| 24 | ### Improvements to currently implemented commands | 24 | ### Improvements to currently implemented commands |
| 25 | * **solve should re-orient first if needed and not just give up if centers are off** | 25 | * **solve should re-orient first if needed and not just give up if centers are off** |
| 26 | * solve should try up to a small bound without loading the large pruning table | 26 | * solve should try up to a small bound without loading the large pruning table |
| 27 | * **drfin for HTR scrambles should try all 3 axis and pick the best solutions; | ||
| 28 | in general every step that automatically detects orientation should do this** | ||
| 29 | 27 | ||
| 30 | ### New features | 28 | ### New features |
| 31 | * cleanup: translate an alg to the standard HTM moveset + reorient at the end | 29 | * cleanup: translate an alg to the standard HTM moveset + reorient at the end |
| @@ -33,7 +31,7 @@ including e.g. solutions that were not shown because -c) | |||
| 33 | * configure max ram to be used (via config file and/or command line option) | 31 | * configure max ram to be used (via config file and/or command line option) |
| 34 | * transform alg, rufify etc... | 32 | * transform alg, rufify etc... |
| 35 | * more scramble stuff (scramble FMC with rufify...) | 33 | * more scramble stuff (scramble FMC with rufify...) |
| 36 | * **command notation to list available moves** | 34 | * command notation to list available moves |
| 37 | 35 | ||
| 38 | ## Distribution | 36 | ## Distribution |
| 39 | 37 | ||
| @@ -73,7 +71,7 @@ including e.g. solutions that were not shown because -c) | |||
| 73 | ### Cleanup | 71 | ### Cleanup |
| 74 | * Remove khuge from everywhere | 72 | * Remove khuge from everywhere |
| 75 | * sort again functions alphabetically in their files | 73 | * sort again functions alphabetically in their files |
| 76 | * **more stuff to load at start (or when suitable command is called) rather | 74 | * more stuff to load at start (or when suitable command is called) rather |
| 77 | than when called directly, to avoid nasty problems with threading** | 75 | than when called directly, to avoid nasty problems with threading |
| 78 | * unniss and inverse_alg work differently (one in place, the other makes | 76 | * unniss and inverse_alg work differently (one in place, the other makes |
| 79 | a copy and returns). | 77 | a copy and returns) changing inverse_alg seems the best option. |
| Binary files differ | |||
| Binary files differ | |||
diff --git a/src/cubetypes.h b/src/cubetypes.h index 1b679aa..b002e8b 100644 --- a/src/cubetypes.h +++ b/src/cubetypes.h | |||
| @@ -100,7 +100,7 @@ typedef bool (*Validator) (Alg *); | |||
| 100 | typedef void (*Exec) (CommandArgs *); | 100 | typedef void (*Exec) (CommandArgs *); |
| 101 | typedef uint64_t (*Indexer) (Cube); | 101 | typedef uint64_t (*Indexer) (Cube); |
| 102 | typedef CommandArgs * (*ArgParser) (int, char **); | 102 | typedef CommandArgs * (*ArgParser) (int, char **); |
| 103 | typedef Trans (*TransDetector) (Cube); | 103 | typedef int (*TransDetector) (Cube, Trans *); |
| 104 | typedef int (*TransFinder) (uint64_t, Trans *); | 104 | typedef int (*TransFinder) (uint64_t, Trans *); |
| 105 | 105 | ||
| 106 | 106 | ||
| @@ -202,6 +202,7 @@ dfsarg | |||
| 202 | { | 202 | { |
| 203 | Step * step; | 203 | Step * step; |
| 204 | SolveOptions * opts; | 204 | SolveOptions * opts; |
| 205 | Trans t; | ||
| 205 | Cube cube; | 206 | Cube cube; |
| 206 | Cube inverse; | 207 | Cube inverse; |
| 207 | int d; | 208 | int d; |
| @@ -323,6 +324,7 @@ struct | |||
| 323 | threaddatasolve | 324 | threaddatasolve |
| 324 | { | 325 | { |
| 325 | int thid; | 326 | int thid; |
| 327 | Trans t; | ||
| 326 | Cube cube; | 328 | Cube cube; |
| 327 | Step * step; | 329 | Step * step; |
| 328 | int depth; | 330 | int depth; |
diff --git a/src/solve.c b/src/solve.c index 79e421d..5a72bba 100644 --- a/src/solve.c +++ b/src/solve.c | |||
| @@ -13,8 +13,10 @@ static void dfs_niss(DfsArg *arg); | |||
| 13 | static bool dfs_stop(DfsArg *arg); | 13 | static bool dfs_stop(DfsArg *arg); |
| 14 | static void * instance_thread(void *arg); | 14 | static void * instance_thread(void *arg); |
| 15 | static void invert_branch(DfsArg *arg); | 15 | static void invert_branch(DfsArg *arg); |
| 16 | static void multidfs(Cube c, Step *s, SolveOptions *opts, AlgList *sols, int d); | 16 | static void multidfs(Cube c, Trans t, Step *s, SolveOptions *opts, |
| 17 | AlgList *sols, int d); | ||
| 17 | static bool niss_makes_sense(DfsArg *arg); | 18 | static bool niss_makes_sense(DfsArg *arg); |
| 19 | static bool solvestop(int d, int op, SolveOptions *opts, AlgList *sols); | ||
| 18 | 20 | ||
| 19 | /* Local functions ***********************************************************/ | 21 | /* Local functions ***********************************************************/ |
| 20 | 22 | ||
| @@ -62,6 +64,7 @@ copy_dfsarg(DfsArg *src, DfsArg *dst) | |||
| 62 | { | 64 | { |
| 63 | dst->step = src->step; | 65 | dst->step = src->step; |
| 64 | dst->opts = src->opts; | 66 | dst->opts = src->opts; |
| 67 | dst->t = src->t; | ||
| 65 | dst->cube = src->cube; | 68 | dst->cube = src->cube; |
| 66 | dst->inverse = src->inverse; | 69 | dst->inverse = src->inverse; |
| 67 | dst->d = src->d; | 70 | dst->d = src->d; |
| @@ -146,7 +149,7 @@ dfs_check_solved(DfsArg *arg) | |||
| 146 | append_alg(arg->sols, arg->current_alg); | 149 | append_alg(arg->sols, arg->current_alg); |
| 147 | 150 | ||
| 148 | transform_alg( | 151 | transform_alg( |
| 149 | inverse_trans(arg->step->pre_trans), | 152 | inverse_trans(arg->t), |
| 150 | arg->sols->last->alg | 153 | arg->sols->last->alg |
| 151 | ); | 154 | ); |
| 152 | if (arg->step->final) | 155 | if (arg->step->final) |
| @@ -260,6 +263,7 @@ instance_thread(void *arg) | |||
| 260 | 263 | ||
| 261 | darg.step = td->step; | 264 | darg.step = td->step; |
| 262 | darg.opts = td->opts; | 265 | darg.opts = td->opts; |
| 266 | darg.t = td->t; | ||
| 263 | darg.cube = c; | 267 | darg.cube = c; |
| 264 | darg.d = td->depth; | 268 | darg.d = td->depth; |
| 265 | darg.niss = node->alg->inv[0]; | 269 | darg.niss = node->alg->inv[0]; |
| @@ -304,7 +308,7 @@ invert_branch(DfsArg *arg) | |||
| 304 | } | 308 | } |
| 305 | 309 | ||
| 306 | static void | 310 | static void |
| 307 | multidfs(Cube c, Step *s, SolveOptions *opts, AlgList *sols, int d) | 311 | multidfs(Cube c, Trans tr, Step *s, SolveOptions *opts, AlgList *sols, int d) |
| 308 | { | 312 | { |
| 309 | int i; | 313 | int i; |
| 310 | Alg *alg; | 314 | Alg *alg; |
| @@ -324,8 +328,6 @@ multidfs(Cube c, Step *s, SolveOptions *opts, AlgList *sols, int d) | |||
| 324 | 328 | ||
| 325 | for (i = 0; s->moveset->sorted_moves[i] != NULLMOVE; i++) { | 329 | for (i = 0; s->moveset->sorted_moves[i] != NULLMOVE; i++) { |
| 326 | alg = new_alg(""); | 330 | alg = new_alg(""); |
| 327 | /* TODO: start on inverse also in case of final step | ||
| 328 | and ed->sw true */ | ||
| 329 | append_move(alg, s->moveset->sorted_moves[i], false); | 331 | append_move(alg, s->moveset->sorted_moves[i], false); |
| 330 | append_alg(start, alg); | 332 | append_alg(start, alg); |
| 331 | if (opts->can_niss) { | 333 | if (opts->can_niss) { |
| @@ -338,6 +340,7 @@ multidfs(Cube c, Step *s, SolveOptions *opts, AlgList *sols, int d) | |||
| 338 | 340 | ||
| 339 | for (i = 0; i < opts->nthreads; i++) { | 341 | for (i = 0; i < opts->nthreads; i++) { |
| 340 | td[i].thid = i; | 342 | td[i].thid = i; |
| 343 | td[i].t = tr; | ||
| 341 | td[i].cube = c; | 344 | td[i].cube = c; |
| 342 | td[i].step = s; | 345 | td[i].step = s; |
| 343 | td[i].depth = d; | 346 | td[i].depth = d; |
| @@ -368,47 +371,69 @@ niss_makes_sense(DfsArg *arg) | |||
| 368 | return arg->current_alg->len == 0 || arg->step->is_done(testcube); | 371 | return arg->current_alg->len == 0 || arg->step->is_done(testcube); |
| 369 | } | 372 | } |
| 370 | 373 | ||
| 374 | static bool | ||
| 375 | solvestop(int d, int op, SolveOptions *opts, AlgList *sols) | ||
| 376 | { | ||
| 377 | bool opt_done, max_moves_exceeded, max_sols_exceeded; | ||
| 378 | |||
| 379 | opt_done = opts->optimal != -1 && op != -1 && d > opts->optimal + op; | ||
| 380 | max_moves_exceeded = d > opts->max_moves; | ||
| 381 | max_sols_exceeded = sols->len >= opts->max_solutions; | ||
| 382 | |||
| 383 | return opt_done || max_moves_exceeded || max_sols_exceeded; | ||
| 384 | } | ||
| 385 | |||
| 371 | /* Public functions **********************************************************/ | 386 | /* Public functions **********************************************************/ |
| 372 | 387 | ||
| 373 | AlgList * | 388 | AlgList * |
| 374 | solve(Cube cube, Step *step, SolveOptions *opts) | 389 | solve(Cube cube, Step *step, SolveOptions *opts) |
| 375 | { | 390 | { |
| 376 | int d, op; | 391 | bool ready; |
| 392 | int i, d, op, nt; | ||
| 377 | AlgList *sols; | 393 | AlgList *sols; |
| 378 | Cube c; | 394 | Cube c; |
| 395 | Trans tt[NTRANS]; | ||
| 379 | 396 | ||
| 380 | prepare_step(step, opts); | 397 | prepare_step(step, opts); |
| 381 | 398 | ||
| 382 | if (step->detect != NULL) | 399 | if (step->detect != NULL) { |
| 383 | step->pre_trans = step->detect(cube); | 400 | nt = step->detect(cube, tt); |
| 384 | c = apply_trans(step->pre_trans, cube); | 401 | } else { |
| 402 | tt[0] = step->pre_trans; | ||
| 403 | ready = step->ready == NULL || | ||
| 404 | step->ready(apply_trans(tt[0], cube)); | ||
| 405 | nt = ready ? 1 : 0; | ||
| 406 | } | ||
| 385 | 407 | ||
| 386 | sols = new_alglist(); | 408 | sols = new_alglist(); |
| 387 | 409 | ||
| 388 | if (step->ready != NULL && !step->ready(c)) { | 410 | if (nt == 0) { |
| 389 | fprintf(stderr, "Cube not ready for solving step: "); | 411 | fprintf(stderr, "Cube not ready for solving step: "); |
| 390 | fprintf(stderr, "%s\n", step->ready_msg); | 412 | fprintf(stderr, "%s\n", step->ready_msg); |
| 391 | return sols; | 413 | return sols; |
| 392 | } | 414 | } |
| 393 | 415 | ||
| 394 | if (opts->min_moves == 0 && step->is_done(cube)) { | 416 | if (opts->min_moves == 0) { |
| 395 | append_alg(sols, new_alg("")); | 417 | for (i = 0; i < nt; i++) { |
| 396 | return sols; | 418 | c = apply_trans(tt[i], cube); |
| 419 | if (step->is_done(c)) { | ||
| 420 | append_alg(sols, new_alg("")); | ||
| 421 | return sols; | ||
| 422 | } | ||
| 423 | } | ||
| 397 | } | 424 | } |
| 398 | 425 | ||
| 399 | op = -1; | 426 | op = -1; |
| 400 | for (d = opts->min_moves; | 427 | for (d = opts->min_moves; !solvestop(d, op, opts, sols); d++) { |
| 401 | d <= opts->max_moves && | ||
| 402 | !(opts->optimal != -1 && op != -1 && opts->optimal + op < d) && | ||
| 403 | sols->len < opts->max_solutions; | ||
| 404 | d++) { | ||
| 405 | if (opts->verbose) | 428 | if (opts->verbose) |
| 406 | fprintf(stderr, | 429 | fprintf(stderr, "Searching depth %d\n", d); |
| 407 | "Found %d solutions, searching depth %d...\n", | 430 | |
| 408 | sols->len, d); | 431 | for (i = 0; i < nt && !solvestop(d, op, opts, sols); i++) { |
| 409 | multidfs(c, step, opts, sols, d); | 432 | c = apply_trans(tt[i], cube); |
| 410 | if (sols->len > 0 && op == -1) | 433 | multidfs(c, tt[i], step, opts, sols, d); |
| 411 | op = d; | 434 | if (sols->len > 0 && op == -1) |
| 435 | op = d; | ||
| 436 | } | ||
| 412 | } | 437 | } |
| 413 | 438 | ||
| 414 | return sols; | 439 | return sols; |
diff --git a/src/steps.c b/src/steps.c index cfd9a23..98e26b5 100644 --- a/src/steps.c +++ b/src/steps.c | |||
| @@ -5,30 +5,22 @@ | |||
| 5 | /* Checkers, estimators and validators ***************************************/ | 5 | /* Checkers, estimators and validators ***************************************/ |
| 6 | 6 | ||
| 7 | static bool check_centers(Cube cube); | 7 | static bool check_centers(Cube cube); |
| 8 | static bool check_coany_HTM(Cube cube); | ||
| 9 | static bool check_coud_HTM(Cube cube); | 8 | static bool check_coud_HTM(Cube cube); |
| 10 | static bool check_coany_URF(Cube cube); | ||
| 11 | static bool check_coud_URF(Cube cube); | 9 | static bool check_coud_URF(Cube cube); |
| 12 | static bool check_corners_HTM(Cube cube); | 10 | static bool check_corners_HTM(Cube cube); |
| 13 | static bool check_corners_URF(Cube cube); | 11 | static bool check_corners_URF(Cube cube); |
| 14 | static bool check_cornershtr(Cube cube); | 12 | static bool check_cornershtr(Cube cube); |
| 15 | static bool check_eoany(Cube cube); | ||
| 16 | static bool check_eofb(Cube cube); | 13 | static bool check_eofb(Cube cube); |
| 17 | static bool check_drany(Cube cube); | ||
| 18 | static bool check_drud(Cube cube); | 14 | static bool check_drud(Cube cube); |
| 19 | static bool check_htr(Cube cube); | 15 | static bool check_htr(Cube cube); |
| 20 | 16 | ||
| 21 | static int estimate_eoany_HTM(DfsArg *arg); | ||
| 22 | static int estimate_eofb_HTM(DfsArg *arg); | 17 | static int estimate_eofb_HTM(DfsArg *arg); |
| 23 | static int estimate_coany_HTM(DfsArg *arg); | ||
| 24 | static int estimate_coud_HTM(DfsArg *arg); | 18 | static int estimate_coud_HTM(DfsArg *arg); |
| 25 | static int estimate_coany_URF(DfsArg *arg); | ||
| 26 | static int estimate_coud_URF(DfsArg *arg); | 19 | static int estimate_coud_URF(DfsArg *arg); |
| 27 | static int estimate_corners_HTM(DfsArg *arg); | 20 | static int estimate_corners_HTM(DfsArg *arg); |
| 28 | static int estimate_cornershtr_HTM(DfsArg *arg); | 21 | static int estimate_cornershtr_HTM(DfsArg *arg); |
| 29 | static int estimate_corners_URF(DfsArg *arg); | 22 | static int estimate_corners_URF(DfsArg *arg); |
| 30 | static int estimate_cornershtr_URF(DfsArg *arg); | 23 | static int estimate_cornershtr_URF(DfsArg *arg); |
| 31 | static int estimate_drany_HTM(DfsArg *arg); | ||
| 32 | static int estimate_drud_HTM(DfsArg *arg); | 24 | static int estimate_drud_HTM(DfsArg *arg); |
| 33 | static int estimate_drud_eofb(DfsArg *arg); | 25 | static int estimate_drud_eofb(DfsArg *arg); |
| 34 | static int estimate_dr_eofb(DfsArg *arg); | 26 | static int estimate_dr_eofb(DfsArg *arg); |
| @@ -46,8 +38,9 @@ static bool validate_singlecw_ending(Alg *alg); | |||
| 46 | 38 | ||
| 47 | /* Pre-transformation detectors **********************************************/ | 39 | /* Pre-transformation detectors **********************************************/ |
| 48 | 40 | ||
| 49 | static Trans detect_pretrans_eofb(Cube cube); | 41 | static int detect_pretrans_eofb(Cube cube, Trans *ret); |
| 50 | static Trans detect_pretrans_drud(Cube cube); | 42 | static int detect_pretrans_drud(Cube cube, Trans *ret); |
| 43 | static int detect_pretrans_void_3axis(Cube cube, Trans *ret); | ||
| 51 | 44 | ||
| 52 | /* Messages for when cube is not ready ***************************************/ | 45 | /* Messages for when cube is not ready ***************************************/ |
| 53 | 46 | ||
| @@ -206,14 +199,14 @@ eoany_HTM = { | |||
| 206 | .name = "EO on any axis", | 199 | .name = "EO on any axis", |
| 207 | 200 | ||
| 208 | .final = false, | 201 | .final = false, |
| 209 | .is_done = check_eoany, | 202 | .is_done = check_eofb, |
| 210 | .estimate = estimate_eoany_HTM, | 203 | .estimate = estimate_eofb_HTM, |
| 211 | .ready = check_centers, | 204 | .ready = check_centers, |
| 212 | .ready_msg = check_centers_msg, | 205 | .ready_msg = check_centers_msg, |
| 213 | .is_valid = validate_singlecw_ending, | 206 | .is_valid = validate_singlecw_ending, |
| 214 | .moveset = &moveset_HTM, | 207 | .moveset = &moveset_HTM, |
| 215 | 208 | ||
| 216 | .pre_trans = uf, | 209 | .detect = detect_pretrans_void_3axis, |
| 217 | 210 | ||
| 218 | .tables = {&pd_eofb_HTM}, | 211 | .tables = {&pd_eofb_HTM}, |
| 219 | .ntables = 1, | 212 | .ntables = 1, |
| @@ -283,13 +276,13 @@ coany_HTM = { | |||
| 283 | .name = "CO on any axis", | 276 | .name = "CO on any axis", |
| 284 | 277 | ||
| 285 | .final = false, | 278 | .final = false, |
| 286 | .is_done = check_coany_HTM, | 279 | .is_done = check_coud_HTM, |
| 287 | .estimate = estimate_coany_HTM, | 280 | .estimate = estimate_coud_HTM, |
| 288 | .ready = NULL, | 281 | .ready = NULL, |
| 289 | .is_valid = validate_singlecw_ending, | 282 | .is_valid = validate_singlecw_ending, |
| 290 | .moveset = &moveset_HTM, | 283 | .moveset = &moveset_HTM, |
| 291 | 284 | ||
| 292 | .pre_trans = uf, | 285 | .detect = detect_pretrans_void_3axis, |
| 293 | 286 | ||
| 294 | .tables = {&pd_coud_HTM}, | 287 | .tables = {&pd_coud_HTM}, |
| 295 | .ntables = 1, | 288 | .ntables = 1, |
| @@ -355,13 +348,13 @@ coany_URF = { | |||
| 355 | .name = "CO any axis (URF moveset)", | 348 | .name = "CO any axis (URF moveset)", |
| 356 | 349 | ||
| 357 | .final = false, | 350 | .final = false, |
| 358 | .is_done = check_coany_URF, | 351 | .is_done = check_coud_URF, |
| 359 | .estimate = estimate_coany_URF, | 352 | .estimate = estimate_coud_URF, |
| 360 | .ready = NULL, | 353 | .ready = NULL, |
| 361 | .is_valid = validate_singlecw_ending, | 354 | .is_valid = validate_singlecw_ending, |
| 362 | .moveset = &moveset_URF, | 355 | .moveset = &moveset_URF, |
| 363 | 356 | ||
| 364 | .pre_trans = uf, | 357 | .detect = detect_pretrans_void_3axis, |
| 365 | 358 | ||
| 366 | .tables = {&pd_coud_HTM}, | 359 | .tables = {&pd_coud_HTM}, |
| 367 | .ntables = 1, | 360 | .ntables = 1, |
| @@ -501,14 +494,14 @@ drany_HTM = { | |||
| 501 | .name = "DR on any axis", | 494 | .name = "DR on any axis", |
| 502 | 495 | ||
| 503 | .final = false, | 496 | .final = false, |
| 504 | .is_done = check_drany, | 497 | .is_done = check_drud, |
| 505 | .estimate = estimate_drany_HTM, | 498 | .estimate = estimate_drud_HTM, |
| 506 | .ready = check_centers, | 499 | .ready = check_centers, |
| 507 | .ready_msg = check_centers_msg, | 500 | .ready_msg = check_centers_msg, |
| 508 | .is_valid = validate_singlecw_ending, | 501 | .is_valid = validate_singlecw_ending, |
| 509 | .moveset = &moveset_HTM, | 502 | .moveset = &moveset_HTM, |
| 510 | 503 | ||
| 511 | .pre_trans = uf, | 504 | .detect = detect_pretrans_void_3axis, |
| 512 | 505 | ||
| 513 | .tables = {&pd_drud_sym16_HTM}, | 506 | .tables = {&pd_drud_sym16_HTM}, |
| 514 | .ntables = 1, | 507 | .ntables = 1, |
| @@ -1003,31 +996,12 @@ check_centers(Cube cube) | |||
| 1003 | } | 996 | } |
| 1004 | 997 | ||
| 1005 | static bool | 998 | static bool |
| 1006 | check_coany_HTM(Cube cube) | ||
| 1007 | { | ||
| 1008 | return cube.cofb == 0 || cube.corl == 0 || cube.coud == 0; | ||
| 1009 | } | ||
| 1010 | |||
| 1011 | static bool | ||
| 1012 | check_coud_HTM(Cube cube) | 999 | check_coud_HTM(Cube cube) |
| 1013 | { | 1000 | { |
| 1014 | return cube.coud == 0; | 1001 | return cube.coud == 0; |
| 1015 | } | 1002 | } |
| 1016 | 1003 | ||
| 1017 | static bool | 1004 | static bool |
| 1018 | check_coany_URF(Cube cube) | ||
| 1019 | { | ||
| 1020 | Cube c2, c3; | ||
| 1021 | |||
| 1022 | c2 = apply_move(y, apply_move(z, cube)); | ||
| 1023 | c3 = apply_move(y, apply_move(x, cube)); | ||
| 1024 | |||
| 1025 | return check_coany_HTM(cube) || | ||
| 1026 | check_coany_HTM(c2) || | ||
| 1027 | check_coany_HTM(c3); | ||
| 1028 | } | ||
| 1029 | |||
| 1030 | static bool | ||
| 1031 | check_coud_URF(Cube cube) | 1005 | check_coud_URF(Cube cube) |
| 1032 | { | 1006 | { |
| 1033 | Cube c2, c3; | 1007 | Cube c2, c3; |
| @@ -1066,26 +1040,12 @@ check_cornershtr(Cube cube) | |||
| 1066 | } | 1040 | } |
| 1067 | 1041 | ||
| 1068 | static bool | 1042 | static bool |
| 1069 | check_eoany(Cube cube) | ||
| 1070 | { | ||
| 1071 | return cube.eofb == 0 || cube.eorl == 0 || cube.eoud == 0; | ||
| 1072 | } | ||
| 1073 | |||
| 1074 | static bool | ||
| 1075 | check_eofb(Cube cube) | 1043 | check_eofb(Cube cube) |
| 1076 | { | 1044 | { |
| 1077 | return cube.eofb == 0; | 1045 | return cube.eofb == 0; |
| 1078 | } | 1046 | } |
| 1079 | 1047 | ||
| 1080 | static bool | 1048 | static bool |
| 1081 | check_drany(Cube cube) | ||
| 1082 | { | ||
| 1083 | return (cube.eofb == 0 && cube.eorl == 0 && cube.coud == 0) || | ||
| 1084 | (cube.eorl == 0 && cube.eoud == 0 && cube.cofb == 0) || | ||
| 1085 | (cube.eoud == 0 && cube.eofb == 0 && cube.corl == 0); | ||
| 1086 | } | ||
| 1087 | |||
| 1088 | static bool | ||
| 1089 | check_drud(Cube cube) | 1049 | check_drud(Cube cube) |
| 1090 | { | 1050 | { |
| 1091 | return cube.eofb == 0 && cube.eorl == 0 && cube.coud == 0; | 1051 | return cube.eofb == 0 && cube.eorl == 0 && cube.coud == 0; |
| @@ -1098,61 +1058,18 @@ check_htr(Cube cube) | |||
| 1098 | } | 1058 | } |
| 1099 | 1059 | ||
| 1100 | static int | 1060 | static int |
| 1101 | estimate_eoany_HTM(DfsArg *arg) | ||
| 1102 | { | ||
| 1103 | int r1, r2, r3; | ||
| 1104 | |||
| 1105 | r1 = ptableval(&pd_eofb_HTM, arg->cube); | ||
| 1106 | r2 = ptableval(&pd_eofb_HTM, apply_trans(ur, arg->cube)); | ||
| 1107 | r3 = ptableval(&pd_eofb_HTM, apply_trans(fd, arg->cube)); | ||
| 1108 | |||
| 1109 | return MIN(r1, MIN(r2, r3)); | ||
| 1110 | } | ||
| 1111 | |||
| 1112 | static int | ||
| 1113 | estimate_eofb_HTM(DfsArg *arg) | 1061 | estimate_eofb_HTM(DfsArg *arg) |
| 1114 | { | 1062 | { |
| 1115 | return ptableval(&pd_eofb_HTM, arg->cube); | 1063 | return ptableval(&pd_eofb_HTM, arg->cube); |
| 1116 | } | 1064 | } |
| 1117 | 1065 | ||
| 1118 | static int | 1066 | static int |
| 1119 | estimate_coany_HTM(DfsArg *arg) | ||
| 1120 | { | ||
| 1121 | int r1, r2, r3; | ||
| 1122 | |||
| 1123 | r1 = ptableval(&pd_coud_HTM, arg->cube); | ||
| 1124 | r2 = ptableval(&pd_coud_HTM, apply_trans(rf, arg->cube)); | ||
| 1125 | r3 = ptableval(&pd_coud_HTM, apply_trans(fd, arg->cube)); | ||
| 1126 | |||
| 1127 | return MIN(r1, MIN(r2, r3)); | ||
| 1128 | } | ||
| 1129 | |||
| 1130 | static int | ||
| 1131 | estimate_coud_HTM(DfsArg *arg) | 1067 | estimate_coud_HTM(DfsArg *arg) |
| 1132 | { | 1068 | { |
| 1133 | return ptableval(&pd_coud_HTM, arg->cube); | 1069 | return ptableval(&pd_coud_HTM, arg->cube); |
| 1134 | } | 1070 | } |
| 1135 | 1071 | ||
| 1136 | static int | 1072 | static int |
| 1137 | estimate_coany_URF(DfsArg *arg) | ||
| 1138 | { | ||
| 1139 | int r1, r2, r3; | ||
| 1140 | Cube c; | ||
| 1141 | |||
| 1142 | c = arg->cube; | ||
| 1143 | |||
| 1144 | r1 = estimate_coud_URF(arg); | ||
| 1145 | arg->cube = apply_trans(rf, c); | ||
| 1146 | r2 = estimate_coud_URF(arg); | ||
| 1147 | arg->cube = apply_trans(fd, c); | ||
| 1148 | r3 = estimate_coud_URF(arg); | ||
| 1149 | |||
| 1150 | arg->cube = c; | ||
| 1151 | |||
| 1152 | return MIN(r1, MIN(r2, r3)); | ||
| 1153 | } | ||
| 1154 | |||
| 1155 | static int | ||
| 1156 | estimate_coud_URF(DfsArg *arg) | 1073 | estimate_coud_URF(DfsArg *arg) |
| 1157 | { | 1074 | { |
| 1158 | /* TODO: I can improve this by checking first the orientation of | 1075 | /* TODO: I can improve this by checking first the orientation of |
| @@ -1232,18 +1149,6 @@ estimate_corners_URF(DfsArg *arg) | |||
| 1232 | } | 1149 | } |
| 1233 | 1150 | ||
| 1234 | static int | 1151 | static int |
| 1235 | estimate_drany_HTM(DfsArg *arg) | ||
| 1236 | { | ||
| 1237 | int r1, r2, r3; | ||
| 1238 | |||
| 1239 | r1 = ptableval(&pd_drud_sym16_HTM, arg->cube); | ||
| 1240 | r2 = ptableval(&pd_drud_sym16_HTM, apply_trans(rf, arg->cube)); | ||
| 1241 | r3 = ptableval(&pd_drud_sym16_HTM, apply_trans(fd, arg->cube)); | ||
| 1242 | |||
| 1243 | return MIN(r1, MIN(r2, r3)); | ||
| 1244 | } | ||
| 1245 | |||
| 1246 | static int | ||
| 1247 | estimate_drud_HTM(DfsArg *arg) | 1152 | estimate_drud_HTM(DfsArg *arg) |
| 1248 | { | 1153 | { |
| 1249 | return ptableval(&pd_drud_sym16_HTM, arg->cube); | 1154 | return ptableval(&pd_drud_sym16_HTM, arg->cube); |
| @@ -1515,28 +1420,40 @@ validate_singlecw_ending(Alg *alg) | |||
| 1515 | 1420 | ||
| 1516 | /* Pre-transformation detectors **********************************************/ | 1421 | /* Pre-transformation detectors **********************************************/ |
| 1517 | 1422 | ||
| 1518 | static Trans | 1423 | static int |
| 1519 | detect_pretrans_eofb(Cube cube) | 1424 | detect_pretrans_eofb(Cube cube, Trans *ret) |
| 1520 | { | 1425 | { |
| 1521 | Trans i; | 1426 | int i, n; |
| 1427 | static Trans tt[3] = {uf, ur, fd}; | ||
| 1522 | 1428 | ||
| 1523 | for (i = 0; i < NROTATIONS; i++) | 1429 | for (i = 0, n = 0; i < 3; i++) |
| 1524 | if (check_eofb(apply_trans(i, cube))) | 1430 | if (check_eofb(apply_trans(tt[i], cube))) |
| 1525 | return i; | 1431 | ret[n++] = tt[i]; |
| 1526 | 1432 | ||
| 1527 | return 0; | 1433 | return n; |
| 1528 | } | 1434 | } |
| 1529 | 1435 | ||
| 1530 | static Trans | 1436 | static int |
| 1531 | detect_pretrans_drud(Cube cube) | 1437 | detect_pretrans_drud(Cube cube, Trans *ret) |
| 1532 | { | 1438 | { |
| 1533 | Trans i; | 1439 | int i, n; |
| 1440 | static Trans tt[3] = {uf, ur, fd}; | ||
| 1441 | |||
| 1442 | for (i = 0, n = 0; i < 3; i++) | ||
| 1443 | if (check_drud(apply_trans(tt[i], cube))) | ||
| 1444 | ret[n++] = tt[i]; | ||
| 1534 | 1445 | ||
| 1535 | for (i = 0; i < NROTATIONS; i++) | 1446 | return n; |
| 1536 | if (check_drud(apply_trans(i, cube))) | 1447 | } |
| 1537 | return i; | 1448 | |
| 1449 | static int | ||
| 1450 | detect_pretrans_void_3axis(Cube cube, Trans *ret) | ||
| 1451 | { | ||
| 1452 | ret[0] = uf; | ||
| 1453 | ret[1] = fr; | ||
| 1454 | ret[2] = rd; | ||
| 1538 | 1455 | ||
| 1539 | return 0; | 1456 | return 3; |
| 1540 | } | 1457 | } |
| 1541 | 1458 | ||
| 1542 | /* Public functions **********************************************************/ | 1459 | /* Public functions **********************************************************/ |
