aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2022-02-27 12:11:07 +0100
committerSebastiano Tronto <sebastiano@tronto.net>2022-02-27 12:11:07 +0100
commitde0352a2926b0708400a9629c1da813455a6f442 (patch)
treeb0bab5511cea4d9c2910e144d1ebf53c984f786b
parent75bd848e9e0cd9a14ca82018edac0b414fa4db44 (diff)
downloadnissy-de0352a2926b0708400a9629c1da813455a6f442.tar.gz
nissy-de0352a2926b0708400a9629c1da813455a6f442.zip
Changed unniss() to return an Alg*. Addedd inplace() to run a function on an alg in place.
-rw-r--r--TODO.md3
-rwxr-xr-xnissybin326784 -> 0 bytes
-rw-r--r--src/alg.c26
-rw-r--r--src/alg.h3
-rw-r--r--src/commands.c7
-rw-r--r--src/solve.c2
6 files changed, 24 insertions, 17 deletions
diff --git a/TODO.md b/TODO.md
index c848caf..4eaa051 100644
--- a/TODO.md
+++ b/TODO.md
@@ -16,7 +16,6 @@ It's more of a personal reminder than anything else.
16 possible to make table generation at least 3x faster? 16 possible to make table generation at least 3x faster?
17* make 8 threads default for gen? 17* make 8 threads default for gen?
18### Documentation 18### Documentation
19* Instructions on how to update on the website
20* Write an examples.md file 19* Write an examples.md file
21* More screenshots! 20* More screenshots!
22### More 21### More
@@ -92,7 +91,5 @@ including e.g. solutions that were not shown because -c)
92* sort again functions alphabetically in their files 91* sort again functions alphabetically in their files
93* more stuff to load at start (or when suitable command is called) rather 92* more stuff to load at start (or when suitable command is called) rather
94 than when called directly, to avoid nasty problems with threading 93 than when called directly, to avoid nasty problems with threading
95* unniss and inverse_alg work differently (one in place, the other makes
96 a copy and returns) changing inverse_alg seems the best option.
97* parse command args: one function per arg type, then each command has 94* parse command args: one function per arg type, then each command has
98 a list of options that it accepts (as a string) 95 a list of options that it accepts (as a string)
diff --git a/nissy b/nissy
deleted file mode 100755
index 6f39985..0000000
--- a/nissy
+++ /dev/null
Binary files differ
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