nissy

Where is nissy?
git clone https://git.tronto.net/nissy
Download | Log | Files | Refs | README

commit de0352a2926b0708400a9629c1da813455a6f442
parent 75bd848e9e0cd9a14ca82018edac0b414fa4db44
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date:   Sun, 27 Feb 2022 12:11:07 +0100

Changed unniss() to return an Alg*. Addedd inplace() to run a function on an alg in place.

Diffstat:
MTODO.md | 3---
Dnissy | 0
Msrc/alg.c | 26++++++++++++++++----------
Msrc/alg.h | 3++-
Msrc/commands.c | 7+++++--
Msrc/solve.c | 2+-
6 files changed, 24 insertions(+), 17 deletions(-)

diff --git a/TODO.md b/TODO.md @@ -16,7 +16,6 @@ It's more of a personal reminder than anything else. possible to make table generation at least 3x faster? * make 8 threads default for gen? ### Documentation -* Instructions on how to update on the website * Write an examples.md file * More screenshots! ### More @@ -92,7 +91,5 @@ including e.g. solutions that were not shown because -c) * sort again functions alphabetically in their files * more stuff to load at start (or when suitable command is called) rather than when called directly, to avoid nasty problems with threading -* unniss and inverse_alg work differently (one in place, the other makes - a copy and returns) changing inverse_alg seems the best option. * parse command args: one function per arg type, then each command has a list of options that it accepts (as a string) diff --git a/nissy b/nissy Binary files differ. diff --git a/src/alg.c b/src/alg.c @@ -219,6 +219,16 @@ free_alglistnode(AlgListNode *aln) free(aln); } +void +inplace(Alg * (*f)(Alg *), Alg *alg) +{ + Alg *aux; + + aux = f(alg); + copy_alg(aux, alg); + free(aux); +} + Alg * inverse_alg(Alg *alg) { @@ -459,27 +469,23 @@ swapmove(Move *m1, Move *m2) *m2 = aux; } -void +Alg * unniss(Alg *alg) { int i; - Alg *aux; + Alg *ret; - aux = new_alg(""); + ret = new_alg(""); for (i = 0; i < alg->len; i++) if (!alg->inv[i]) - append_move(aux, alg->move[i], false); + append_move(ret, alg->move[i], false); for (i = alg->len-1; i >= 0; i--) if (alg->inv[i]) - append_move(aux, inverse_move(alg->move[i]), false); + append_move(ret, inverse_move(alg->move[i]), false); - for (i = 0; i < alg->len; i++) { - alg->move[i] = aux->move[i]; - alg->inv[i] = false; - } - free(aux); + return ret; } void diff --git a/src/alg.h b/src/alg.h @@ -22,6 +22,7 @@ bool commute(Move m1, Move m2); void copy_alg(Alg *src, Alg *dst); void free_alg(Alg *alg); void free_alglist(AlgList *l); +void inplace(Alg * (*f)(Alg *), Alg *alg); Alg * inverse_alg(Alg *alg); Move inverse_move(Move m); char * move_string(Move m); @@ -33,7 +34,7 @@ Alg * on_inverse(Alg *alg); void print_alg(Alg *alg, bool l); void print_alglist(AlgList *al, bool l); void swapmove(Move *m1, Move *m2); -void unniss(Alg *alg); +Alg * unniss(Alg *alg); void init_moveset(Moveset *ms); void init_all_movesets(); diff --git a/src/commands.c b/src/commands.c @@ -525,8 +525,11 @@ cleanup_exec(CommandArgs *args) static void unniss_exec(CommandArgs *args) { - unniss(args->scramble); - print_alg(args->scramble, false); + Alg *aux; + + aux = unniss(args->scramble); + print_alg(aux, false); + free(aux); } static void diff --git a/src/solve.c b/src/solve.c @@ -153,7 +153,7 @@ dfs_check_solved(DfsArg *arg) arg->sols->last->alg ); if (arg->step->final) - unniss(arg->sols->last->alg); + inplace(unniss, arg->sols->last->alg); if (arg->opts->verbose) print_alg(arg->sols->last->alg, false);