From 6df92db4d23dd6e2c3aba48caf1e0ea30265abb2 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Fri, 17 Dec 2021 22:03:33 +0100 Subject: some progress --- src/alg.c | 37 +++++++++++++------------------------ src/cube.c | 7 ++++--- src/solve.c | 5 +++-- src/steps.c | 30 ++++++++++-------------------- src/steps.h | 3 +-- src/symcoord.c | 9 --------- src/trans.c | 2 -- 7 files changed, 31 insertions(+), 62 deletions(-) (limited to 'src') diff --git a/src/alg.c b/src/alg.c index ffe1679..d9317ab 100644 --- a/src/alg.c +++ b/src/alg.c @@ -110,36 +110,25 @@ allowed_next_HTM(Move l2, Move l1, Move m) static int axis(Move m) { - Move i; - - static bool initialized = false; - static int aux[NMOVES]; - - if (!initialized) { - for (i = 0; i < NMOVES; i++) { - if (i == NULLMOVE) - aux[i] = 0; + if (m == NULLMOVE) + return 0; - if (i >= U && i <= B3) - aux[i] = (i-1)/6 + 1; + if (m >= U && m <= B3) + return (m-1)/6 + 1; - if (i >= Uw && i <= Bw3) - aux[i] = (i-1)/6 - 2; + if (m >= Uw && m <= Bw3) + return (m-1)/6 - 2; - if (base_move(i) == E || base_move(i) == y) - aux[i] = 1; + if (base_move(m) == E || base_move(m) == y) + return 1; - if (base_move(i) == M || base_move(i) == x) - aux[i] = 2; + if (base_move(m) == M || base_move(m) == x) + return 2; - if (base_move(i) == S || base_move(i) == z) - aux[i] = 3; - } - - initialized = true; - } + if (base_move(m) == S || base_move(m) == z) + return 3; - return aux[m]; + return -1; } bool diff --git a/src/cube.c b/src/cube.c index 5babe28..b9653ce 100644 --- a/src/cube.c +++ b/src/cube.c @@ -526,11 +526,12 @@ what_center_at(Cube cube, Center c) Corner what_corner_at(Cube cube, Corner c) { + int i; + unsigned int ui; + CubeArray *arr; + static bool initialized = false; static Corner aux[FACTORIAL8][8]; - static int i; - static unsigned int ui; - static CubeArray *arr; if (!initialized) { for (ui = 0; ui < FACTORIAL8; ui++) { diff --git a/src/solve.c b/src/solve.c index a8f9001..ac7a22e 100644 --- a/src/solve.c +++ b/src/solve.c @@ -264,14 +264,15 @@ instance_thread(void *arg) darg.current_alg = new_alg(""); append_move(darg.current_alg, node->alg->move[0], node->alg->inv[0]); - darg.ed = new_estimatedata(); + darg.ed = malloc(sizeof(EstimateData)); + reset_estimatedata(darg.ed); darg.badmoves = 0; darg.badmovesinv = 0; dfs(&darg); free_alg(darg.current_alg); - free_estimatedata(darg.ed); + free(darg.ed); } return NULL; diff --git a/src/steps.c b/src/steps.c index 014b206..933d823 100644 --- a/src/steps.c +++ b/src/steps.c @@ -1466,12 +1466,6 @@ copy_estimatedata(EstimateData *src, EstimateData *dst) dst->oldret = src->oldret; } -void -free_estimatedata(EstimateData *ed) -{ - free(ed); -} - void invert_estimatedata(EstimateData *ed) { @@ -1480,21 +1474,17 @@ invert_estimatedata(EstimateData *ed) swap(&(ed->normal_rl), &(ed->inverse_rl)); } -EstimateData * -new_estimatedata() +void +reset_estimatedata(EstimateData *ed) { - EstimateData *ret = malloc(sizeof(EstimateData)); - - ret->corners = -1; - ret->normal_ud = -1; - ret->normal_fb = -1; - ret->normal_rl = -1; - ret->inverse_ud = -1; - ret->inverse_fb = -1; - ret->inverse_rl = -1; - ret->oldret = -1; - - return ret; + ed->corners = -1; + ed->normal_ud = -1; + ed->normal_fb = -1; + ed->normal_rl = -1; + ed->inverse_ud = -1; + ed->inverse_fb = -1; + ed->inverse_rl = -1; + ed->oldret = -1; } void diff --git a/src/steps.h b/src/steps.h index a55a101..5744e48 100644 --- a/src/steps.h +++ b/src/steps.h @@ -8,9 +8,8 @@ extern Step * steps[NSTEPS]; void copy_estimatedata(EstimateData *s, EstimateData *d); -void free_estimatedata(EstimateData *ed); void invert_estimatedata(EstimateData *ed); -EstimateData * new_estimatedata(); +void reset_estimatedata(EstimateData *ed); void prepare_step(Step *step, SolveOptions *opts); #endif diff --git a/src/symcoord.c b/src/symcoord.c index 707a84e..8b0eeb4 100644 --- a/src/symcoord.c +++ b/src/symcoord.c @@ -352,16 +352,7 @@ gensym(SymData *sd) for (i = 0; i < sd->coord->max; i++) { if (sd->class[i] == sd->coord->max + 1) { - - /* - * TODO: this is the only unavoidable use of - * antindexes. I also use them in genptable() (see - * pruning.c), but there I can do without (see - * commented functions in that file. - * Removing this would allow for a great simplification - */ c = sd->coord->cube(i); - sd->rep[nreps] = c; for (j = 0; j < sd->ntrans; j++) { d = apply_trans(sd->trans[j], c); diff --git a/src/trans.c b/src/trans.c index 2946c58..72f8dd2 100644 --- a/src/trans.c +++ b/src/trans.c @@ -25,7 +25,6 @@ static int cpos_mirror[6] = { [F_center] = F_center, [B_center] = B_center }; -/* TODO Is there a more elegant way? */ static char rotation_alg_string[100][NROTATIONS] = { [uf] = "", [ur] = "y", [ub] = "y2", [ul] = "y3", [df] = "z2", [dr] = "y z2", [db] = "x2", [dl] = "y3 z2", @@ -208,7 +207,6 @@ apply_trans(Trans t, Cube cube) Trans inverse_trans(Trans t) { - /* TODO is there a more elegant way? */ static Trans inverse_trans_aux[NTRANS] = { [uf] = uf, [ur] = ul, [ul] = ur, [ub] = ub, [df] = df, [dr] = dr, [dl] = dl, [db] = db, -- cgit v1.3