aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/alg.c26
-rw-r--r--src/alg.h3
-rw-r--r--src/commands.c7
-rw-r--r--src/solve.c2
4 files changed, 24 insertions, 14 deletions
diff --git a/src/alg.c b/src/alg.c
index 4f5079a..52bebc0 100644
--- a/src/alg.c
+++ b/src/alg.c
@@ -219,6 +219,16 @@ free_alglistnode(AlgListNode *aln)
219 free(aln); 219 free(aln);
220} 220}
221 221
222void
223inplace(Alg * (*f)(Alg *), Alg *alg)
224{
225 Alg *aux;
226
227 aux = f(alg);
228 copy_alg(aux, alg);
229 free(aux);
230}
231
222Alg * 232Alg *
223inverse_alg(Alg *alg) 233inverse_alg(Alg *alg)
224{ 234{
@@ -459,27 +469,23 @@ swapmove(Move *m1, Move *m2)
459 *m2 = aux; 469 *m2 = aux;
460} 470}
461 471
462void 472Alg *
463unniss(Alg *alg) 473unniss(Alg *alg)
464{ 474{
465 int i; 475 int i;
466 Alg *aux; 476 Alg *ret;
467 477
468 aux = new_alg(""); 478 ret = new_alg("");
469 479
470 for (i = 0; i < alg->len; i++) 480 for (i = 0; i < alg->len; i++)
471 if (!alg->inv[i]) 481 if (!alg->inv[i])
472 append_move(aux, alg->move[i], false); 482 append_move(ret, alg->move[i], false);
473 483
474 for (i = alg->len-1; i >= 0; i--) 484 for (i = alg->len-1; i >= 0; i--)
475 if (alg->inv[i]) 485 if (alg->inv[i])
476 append_move(aux, inverse_move(alg->move[i]), false); 486 append_move(ret, inverse_move(alg->move[i]), false);
477 487
478 for (i = 0; i < alg->len; i++) { 488 return ret;
479 alg->move[i] = aux->move[i];
480 alg->inv[i] = false;
481 }
482 free(aux);
483} 489}
484 490
485void 491void
diff --git a/src/alg.h b/src/alg.h
index d32c8bf..6bee26b 100644
--- a/src/alg.h
+++ b/src/alg.h
@@ -22,6 +22,7 @@ bool commute(Move m1, Move m2);
22void copy_alg(Alg *src, Alg *dst); 22void copy_alg(Alg *src, Alg *dst);
23void free_alg(Alg *alg); 23void free_alg(Alg *alg);
24void free_alglist(AlgList *l); 24void free_alglist(AlgList *l);
25void inplace(Alg * (*f)(Alg *), Alg *alg);
25Alg * inverse_alg(Alg *alg); 26Alg * inverse_alg(Alg *alg);
26Move inverse_move(Move m); 27Move inverse_move(Move m);
27char * move_string(Move m); 28char * move_string(Move m);
@@ -33,7 +34,7 @@ Alg * on_inverse(Alg *alg);
33void print_alg(Alg *alg, bool l); 34void print_alg(Alg *alg, bool l);
34void print_alglist(AlgList *al, bool l); 35void print_alglist(AlgList *al, bool l);
35void swapmove(Move *m1, Move *m2); 36void swapmove(Move *m1, Move *m2);
36void unniss(Alg *alg); 37Alg * unniss(Alg *alg);
37 38
38void init_moveset(Moveset *ms); 39void init_moveset(Moveset *ms);
39void init_all_movesets(); 40void init_all_movesets();
diff --git a/src/commands.c b/src/commands.c
index 13405b7..8666278 100644
--- a/src/commands.c
+++ b/src/commands.c
@@ -525,8 +525,11 @@ cleanup_exec(CommandArgs *args)
525static void 525static void
526unniss_exec(CommandArgs *args) 526unniss_exec(CommandArgs *args)
527{ 527{
528 unniss(args->scramble); 528 Alg *aux;
529 print_alg(args->scramble, false); 529
530 aux = unniss(args->scramble);
531 print_alg(aux, false);
532 free(aux);
530} 533}
531 534
532static void 535static void
diff --git a/src/solve.c b/src/solve.c
index 915c909..587bbc8 100644
--- a/src/solve.c
+++ b/src/solve.c
@@ -153,7 +153,7 @@ dfs_check_solved(DfsArg *arg)
153 arg->sols->last->alg 153 arg->sols->last->alg
154 ); 154 );
155 if (arg->step->final) 155 if (arg->step->final)
156 unniss(arg->sols->last->alg); 156 inplace(unniss, arg->sols->last->alg);
157 157
158 if (arg->opts->verbose) 158 if (arg->opts->verbose)
159 print_alg(arg->sols->last->alg, false); 159 print_alg(arg->sols->last->alg, false);

Generated with cgit - Back to sebastiano.tronto.net