From 48cd8b6b1779f34ba0507cb697492de83c4e9da8 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Sun, 27 Feb 2022 15:36:02 +0100 Subject: Moved random_cube() from cube.c to commands.c and fixed a bug in corners only and edges only scrambles. Added fmc scrambles (with R'U'F). Updated manpage for scramble and cleanup. --- src/commands.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++-------- src/commands.h | 2 ++ src/cube.c | 28 +---------------------- src/cube.h | 7 +----- src/cubetypes.h | 2 +- 5 files changed, 67 insertions(+), 43 deletions(-) (limited to 'src') diff --git a/src/commands.c b/src/commands.c index 8666278..b397878 100644 --- a/src/commands.c +++ b/src/commands.c @@ -166,6 +166,10 @@ Command *commands[NCOMMANDS] = { &version_cmd, }; +/* Other constants ***********************************************************/ + +char *scrtypes[20] = { "eo", "corners", "edges", "fmc", NULL }; + /* Arg parsing functions implementation **************************************/ CommandArgs * @@ -277,7 +281,6 @@ scramble_parse_args(int c, char **v) a->success = true; a->n = 1; - a->scrt = -1; for (i = 0; i < c; i++) { if (!strcmp(v[i], "-n") && i+1 < c) { @@ -396,8 +399,8 @@ static void scramble_exec(CommandArgs *args) { Cube cube; - Alg *scr; - int i; + Alg *scr, *ruf, *aux; + int i, j, eo, ep, co, cp, a[12]; init_all_movesets(); init_symcoord(); @@ -405,8 +408,56 @@ scramble_exec(CommandArgs *args) srand(time(NULL)); for (i = 0; i < args->n; i++) { - cube = random_cube(args->scrt); + 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); scr = solve_2phase(cube, 1); + + if (!strcmp(args->scrtype, "fmc")) { + aux = new_alg(""); + copy_alg(scr, aux); + /* Trick to rufify for free: rotate the scramble * + * so that it does not start with F or end with R */ + for (j = 0; j < NROTATIONS; j++) { + if (base_move(scr->move[0]) != F && + base_move(scr->move[0]) != B && + base_move(scr->move[scr->len-1]) != R && + base_move(scr->move[scr->len-1]) != L) + break; + copy_alg(aux, scr); + transform_alg(j, scr); + } + copy_alg(scr, aux); + ruf = new_alg("R' U' F"); + copy_alg(ruf, scr); + compose_alg(scr, aux); + compose_alg(scr, ruf); + free_alg(aux); + free_alg(ruf); + } print_alg(scr, false); free_alg(scr); } @@ -576,12 +627,14 @@ read_scrtype(CommandArgs *args, char *str) { int i; - args->scrt = -1; - for (i = 0; i < NSCRTYPES; i++) - if (!strcmp(scrtypes[i], str)) - args->scrt = i; + for (i = 0; scrtypes[i] != NULL; i++) { + if (!strcmp(scrtypes[i], str)) { + strcpy(args->scrtype, scrtypes[i]); + return true; + } + } - return args->scrt != -1; + return false; } static bool diff --git a/src/commands.h b/src/commands.h index 7773827..bac71f1 100644 --- a/src/commands.h +++ b/src/commands.h @@ -1,6 +1,8 @@ #ifndef COMMANDS_H #define COMMANDS_H +#include + #include "solve.h" #include "steps.h" diff --git a/src/cube.c b/src/cube.c index 3a6234d..803fefd 100644 --- a/src/cube.c +++ b/src/cube.c @@ -4,7 +4,6 @@ static void fix_eorleoud(CubeArray *arr); static void fix_cofbcorl(CubeArray *arr); -static Cube fourval_to_cube(int eofb, int ep, int coud, int cp); static void init_inverse(); static bool read_invtables_file(); static bool write_invtables_file(); @@ -18,8 +17,6 @@ static uint16_t co_invtable[POW3TO7][FACTORIAL8]; static uint16_t cp_invtable[FACTORIAL8]; static uint16_t cpos_invtable[FACTORIAL6]; -char *scrtypes[NSCRTYPES] = { "eo", "corners", "edges" }; - /* Functions implementation **************************************************/ int @@ -187,7 +184,7 @@ fix_cofbcorl(CubeArray *arr) } } -static Cube +Cube fourval_to_cube(int eofb, int ep, int coud, int cp) { CubeArray *arr; @@ -544,29 +541,6 @@ print_cube(Cube cube) printf("\n"); } -Cube -random_cube(int scrt) -{ - int ep, cp, eo, co; - - ep = rand() % FACTORIAL12; - cp = rand() % FACTORIAL8; - eo = rand() % POW2TO11; - co = rand() % POW3TO7; - - if (scrt == 0) { /* EO */ - eo = 0; - } else if (scrt == 1) { /* corners */ - eo = 0; - ep = 0; - } else if (scrt == 2) { /* edges */ - co = 0; - cp = 0; - } - - return fourval_to_cube(eo, ep, co, cp); -} - Center what_center_at(Cube cube, Center c) { diff --git a/src/cube.h b/src/cube.h index 82f6d10..8e04839 100644 --- a/src/cube.h +++ b/src/cube.h @@ -2,16 +2,11 @@ #define CUBE_H #include -#include #include "env.h" #include "pf.h" #include "utils.h" -#define NSCRTYPES 3 - -extern char *scrtypes[NSCRTYPES]; - Cube admissible_ep(Cube cube, PieceFilter f); int array_ep_to_epos(int *ep, int *eps_solved); Cube arrays_to_cube(CubeArray *arr, PieceFilter f); @@ -28,11 +23,11 @@ bool is_solved_center(Cube cube, Center c); bool is_solved_corner(Cube cube, Corner c); bool is_solved_edge(Cube cube, Edge e); void epos_to_partial_ep(int epos, int *ep, int *ss); +Cube fourval_to_cube(int eofb, int ep, int coud, int cp); void free_cubearray(CubeArray *arr, PieceFilter f); Cube move_via_arrays(CubeArray *arr, Cube c, PieceFilter pf); CubeArray * new_cubearray(Cube cube, PieceFilter f); void print_cube(Cube cube); -Cube random_cube(int scrt); Center what_center_at(Cube cube, Center c); Corner what_corner_at(Cube cube, Corner c); Edge what_edge_at(Cube cube, Edge e); diff --git a/src/cubetypes.h b/src/cubetypes.h index 8ba1341..14e490a 100644 --- a/src/cubetypes.h +++ b/src/cubetypes.h @@ -157,7 +157,7 @@ commandargs Step * step; Command * command; /* For help */ int n; - int scrt; + char scrtype[20]; bool scrstdin; bool header; }; -- cgit v1.3