diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2022-02-27 12:11:07 +0100 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2022-02-27 12:11:07 +0100 |
| commit | de0352a2926b0708400a9629c1da813455a6f442 (patch) | |
| tree | b0bab5511cea4d9c2910e144d1ebf53c984f786b | |
| parent | 75bd848e9e0cd9a14ca82018edac0b414fa4db44 (diff) | |
| download | nissy-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.md | 3 | ||||
| -rwxr-xr-x | nissy | bin | 326784 -> 0 bytes | |||
| -rw-r--r-- | src/alg.c | 26 | ||||
| -rw-r--r-- | src/alg.h | 3 | ||||
| -rw-r--r-- | src/commands.c | 7 | ||||
| -rw-r--r-- | src/solve.c | 2 |
6 files changed, 24 insertions, 17 deletions
| @@ -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) |
| Binary files differ | |||
| @@ -219,6 +219,16 @@ free_alglistnode(AlgListNode *aln) | |||
| 219 | free(aln); | 219 | free(aln); |
| 220 | } | 220 | } |
| 221 | 221 | ||
| 222 | void | ||
| 223 | inplace(Alg * (*f)(Alg *), Alg *alg) | ||
| 224 | { | ||
| 225 | Alg *aux; | ||
| 226 | |||
| 227 | aux = f(alg); | ||
| 228 | copy_alg(aux, alg); | ||
| 229 | free(aux); | ||
| 230 | } | ||
| 231 | |||
| 222 | Alg * | 232 | Alg * |
| 223 | inverse_alg(Alg *alg) | 233 | inverse_alg(Alg *alg) |
| 224 | { | 234 | { |
| @@ -459,27 +469,23 @@ swapmove(Move *m1, Move *m2) | |||
| 459 | *m2 = aux; | 469 | *m2 = aux; |
| 460 | } | 470 | } |
| 461 | 471 | ||
| 462 | void | 472 | Alg * |
| 463 | unniss(Alg *alg) | 473 | unniss(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 | ||
| 485 | void | 491 | void |
| @@ -22,6 +22,7 @@ bool commute(Move m1, Move m2); | |||
| 22 | void copy_alg(Alg *src, Alg *dst); | 22 | void copy_alg(Alg *src, Alg *dst); |
| 23 | void free_alg(Alg *alg); | 23 | void free_alg(Alg *alg); |
| 24 | void free_alglist(AlgList *l); | 24 | void free_alglist(AlgList *l); |
| 25 | void inplace(Alg * (*f)(Alg *), Alg *alg); | ||
| 25 | Alg * inverse_alg(Alg *alg); | 26 | Alg * inverse_alg(Alg *alg); |
| 26 | Move inverse_move(Move m); | 27 | Move inverse_move(Move m); |
| 27 | char * move_string(Move m); | 28 | char * move_string(Move m); |
| @@ -33,7 +34,7 @@ Alg * on_inverse(Alg *alg); | |||
| 33 | void print_alg(Alg *alg, bool l); | 34 | void print_alg(Alg *alg, bool l); |
| 34 | void print_alglist(AlgList *al, bool l); | 35 | void print_alglist(AlgList *al, bool l); |
| 35 | void swapmove(Move *m1, Move *m2); | 36 | void swapmove(Move *m1, Move *m2); |
| 36 | void unniss(Alg *alg); | 37 | Alg * unniss(Alg *alg); |
| 37 | 38 | ||
| 38 | void init_moveset(Moveset *ms); | 39 | void init_moveset(Moveset *ms); |
| 39 | void init_all_movesets(); | 40 | void 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) | |||
| 525 | static void | 525 | static void |
| 526 | unniss_exec(CommandArgs *args) | 526 | unniss_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 | ||
| 532 | static void | 535 | static 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); |
