From b5a692702643c8f3e77765ca38677e076bce2b59 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Wed, 2 Mar 2022 19:48:10 +0100 Subject: Added dr and htr scrambles --- src/commands.c | 73 +++++++++++++++++++++++++++++++++++++++------------------- src/cube.c | 2 ++ src/solve.c | 8 ++++++- 3 files changed, 58 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/commands.c b/src/commands.c index 03eded0..6bfc7b7 100644 --- a/src/commands.c +++ b/src/commands.c @@ -169,7 +169,7 @@ Command *commands[] = { /* Other constants ***********************************************************/ -char *scrtypes[20] = { "eo", "corners", "edges", "fmc", NULL }; +char *scrtypes[20] = { "eo", "corners", "edges", "fmc", "dr", "htr", NULL }; /* Arg parsing functions implementation **************************************/ @@ -401,6 +401,7 @@ scramble_exec(CommandArgs *args) Cube cube; Alg *scr, *ruf, *aux; int i, j, eo, ep, co, cp, a[12]; + uint64_t ui, uj; init_all_movesets(); init_symcoord(); @@ -408,32 +409,56 @@ scramble_exec(CommandArgs *args) srand(time(NULL)); for (i = 0; i < args->n; i++) { - eo = rand() % POW2TO11; - ep = rand() % FACTORIAL12; - co = rand() % POW3TO7; - cp = rand() % FACTORIAL8; - - if (!strcmp(args->scrtype, "eo")) { - eo = 0; - } else if (!strcmp(args->scrtype, "corners")) { - eo = 0; - ep = 0; - index_to_perm(cp, 8, a); - if (perm_sign(a, 8) == 1) { - swap(&a[0], &a[1]); - cp = perm_to_index(a, 8); - } - } else if (!strcmp(args->scrtype, "edges")) { - co = 0; - cp = 0; - index_to_perm(ep, 12, a); - if (perm_sign(a, 12) == 1) { - swap(&a[0], &a[1]); - ep = perm_to_index(a, 12); + + if (!strcmp(args->scrtype, "dr")) { + /* Warning: cube is inconsistent because of side CO * + * and EO on U/D. But solve_2phase only solves drfin * + * in this case, so it should be ok. * + * TODO: check this properly * + * Moreover we again need to fix parity after * + * generating epose manually */ + do { + ui = rand() % coord_drudfin_noE_sym16.max; + uj = rand() % FACTORIAL4; + cube = coord_drudfin_noE_sym16.cube(ui); + cube.epose += uj; + } while (!is_admissible(cube)); + } else if (!strcmp(args->scrtype, "htr")) { + /* antindex_htrfin() returns a consistent * + * cube, except possibly for parity */ + do { + ui = rand() % coord_htrfin.max; + cube = coord_htrfin.cube(ui); + } while (!is_admissible(cube)); + } else { + eo = rand() % POW2TO11; + ep = rand() % FACTORIAL12; + co = rand() % POW3TO7; + cp = rand() % FACTORIAL8; + + if (!strcmp(args->scrtype, "eo")) { + eo = 0; + } else if (!strcmp(args->scrtype, "corners")) { + eo = 0; + ep = 0; + index_to_perm(cp, 8, a); + if (perm_sign(a, 8) == 1) { + swap(&a[0], &a[1]); + cp = perm_to_index(a, 8); + } + } else if (!strcmp(args->scrtype, "edges")) { + co = 0; + cp = 0; + index_to_perm(ep, 12, a); + if (perm_sign(a, 12) == 1) { + swap(&a[0], &a[1]); + ep = perm_to_index(a, 12); + } } + cube = fourval_to_cube(eo, ep, co, cp); } - cube = fourval_to_cube(eo, ep, co, cp); + /* TODO: can be optimized for htr and dr using htrfin, drfin */ scr = solve_2phase(cube, 1); if (!strcmp(args->scrtype, "fmc")) { diff --git a/src/cube.c b/src/cube.c index 803fefd..0ed862f 100644 --- a/src/cube.c +++ b/src/cube.c @@ -413,6 +413,8 @@ is_admissible(Cube cube) { perm_sign(a->cp, 8) + perm_sign(a->cpos, 6); + free_cubearray(a, pf_all); + return perm && parity % 2 == 0; } diff --git a/src/solve.c b/src/solve.c index 587bbc8..d4c0f18 100644 --- a/src/solve.c +++ b/src/solve.c @@ -466,7 +466,13 @@ solve_2phase(Cube cube, int nthreads) opts2.can_niss = false; opts2.verbose = false; - sols1 = solve(cube, &drany_HTM, &opts1); + /* We skip step1 if it is solved on any axis */ + if (drany_HTM.is_done(cube)) { + sols1 = new_alglist(); + append_alg(sols1, new_alg("")); + } else { + sols1 = solve(cube, &drany_HTM, &opts1); + } bestalg = new_alg(""); bestlen = 999; for (i = sols1->first; i != NULL; i = i->next) { -- cgit v1.3