nissy-fmc

A Rubik's cube FMC assistant
git clone https://git.tronto.net/nissy-fmc
Download | Log | Files | Refs | README | LICENSE

commit 4b5a5796f23a41086356891c4860898b0da5e3c8
parent 4b7931caff4d04fa8e89c1fe1c8fcfbf3514285c
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date:   Fri, 21 Apr 2023 23:54:43 +0200

cleanup

Diffstat:
Msrc/coord.c | 87+++++++++++++++++++++++--------------------------------------------------------
Msrc/coord.h | 55+++++++++++++++++++++++++------------------------------
Msrc/cube.c | 10+++++++---
Msrc/cube.h | 52++++++++++++++++++++++++++--------------------------
Msrc/nissy.c | 4++++
Msrc/solve.c | 18+++++++++---------
Msrc/solve.h | 32++++++++++++++++----------------
Msrc/steps.c | 19+++++++++++++++----
8 files changed, 127 insertions(+), 150 deletions(-)

diff --git a/src/coord.c b/src/coord.c @@ -6,31 +6,31 @@ #include "cube.h" #include "coord.h" -#define ENTRIES_PER_GROUP (2*sizeof(entry_group_t)) -#define ENTRIES_PER_GROUP_COMPACT (4*sizeof(entry_group_t)) - -static uint64_t indexers_getind(Indexer **is, Cube *c); -static uint64_t indexers_getmax(Indexer **is); -static void indexers_makecube(Indexer **is, uint64_t ind, Cube *c); -static int coord_base_number(Coordinate *coord); -static void gen_coord_comp(Coordinate *coord); -static void gen_coord_sym(Coordinate *coord); -static bool read_coord_mtable(Coordinate *coord); -static bool read_coord_sd(Coordinate *coord); -static bool read_coord_ttable(Coordinate *coord); -static bool write_coord_mtable(Coordinate *coord); -static bool write_coord_sd(Coordinate *coord); -static bool write_coord_ttable(Coordinate *coord); - -static void genptable(Coordinate *coord); -static void genptable_bfs(Coordinate *coord, int d); -static void fixnasty(Coordinate *coord, uint64_t i, int d); -static void genptable_compress(Coordinate *coord); -static void genptable_setbase(Coordinate *coord); -static uint64_t ptablesize(Coordinate *coord); -static void ptable_update(Coordinate *coord, uint64_t ind, int m); -static bool read_ptable_file(Coordinate *coord); -static bool write_ptable_file(Coordinate *coord); +#define ENTRIES_PER_GROUP (2*sizeof(entry_group_t)) +#define ENTRIES_PER_GROUP_COMPACT (4*sizeof(entry_group_t)) + +static uint64_t indexers_getind(Indexer **, Cube *); +static uint64_t indexers_getmax(Indexer **); +static void indexers_makecube(Indexer **, uint64_t, Cube *); +static int coord_base_number(Coordinate *); +static void gen_coord_comp(Coordinate *); +static void gen_coord_sym(Coordinate *); +static bool read_coord_mtable(Coordinate *); +static bool read_coord_sd(Coordinate *); +static bool read_coord_ttable(Coordinate *); +static bool write_coord_mtable(Coordinate *); +static bool write_coord_sd(Coordinate *); +static bool write_coord_ttable(Coordinate *); + +static void genptable(Coordinate *); +static void genptable_bfs(Coordinate *, int); +static void fixnasty(Coordinate *, uint64_t, int); +static void genptable_compress(Coordinate *); +static void genptable_setbase(Coordinate *); +static uint64_t ptablesize(Coordinate *); +static void ptable_update(Coordinate *, uint64_t, int); +static bool read_ptable_file(Coordinate *); +static bool write_ptable_file(Coordinate *); static uint64_t indexers_getmax(Indexer **is) @@ -498,32 +498,6 @@ move_coord(Coordinate *coord, Move m, uint64_t ind, Trans *offtrans) return coord->max; /* Only reached in case of error */ } -bool -test_coord(Coordinate *coord) -{ - uint64_t ui, uj; - Cube c; - - if (coord->type != COMP_COORD) { - fprintf(stderr, "Can only test COMP_COORD\n"); - return false; - } - - gen_coord(coord); - for (ui = 0; ui < coord->max; ui++) { - indexers_makecube(coord->i, ui, &c); - uj = indexers_getind(coord->i, &c); - if (ui != uj) { - fprintf(stderr, "%s: error: %" PRIu64 " different" - " from %" PRIu64 "\n", coord->name, uj, ui); - return false; - } - } - - fprintf(stderr, "%s: test passed\n", coord->name); - return true; -} - uint64_t trans_coord(Coordinate *coord, Trans t, uint64_t ind) { @@ -688,17 +662,6 @@ genptable_setbase(Coordinate *coord) } } -void -print_ptable(Coordinate *coord) -{ - uint64_t i; - - printf("Table %s\n", coord->name); - printf("Base value: %d\n", coord->ptablebase); - for (i = 0; i < 16; i++) - printf("%2" PRIu64 "\t%10" PRIu64 "\n", i, coord->count[i]); -} - static uint64_t ptablesize(Coordinate *coord) { diff --git a/src/coord.h b/src/coord.h @@ -8,37 +8,32 @@ typedef struct { void (*to_cube)(uint64_t, Cube *); } Indexer; typedef struct coordinate { - char * name; - CoordType type; - uint64_t max; - uint64_t * mtable[NMOVES]; - uint64_t * ttable[NTRANS]; - TransGroup * tgrp; - struct coordinate * base[2]; - uint64_t * symclass; - uint64_t * symrep; - Trans * transtorep; - Trans * ttrep_move[NMOVES]; + char *name; + CoordType type; + uint64_t max; + uint64_t *mtable[NMOVES]; + uint64_t *ttable[NTRANS]; + TransGroup *tgrp; + struct coordinate *base[2]; + uint64_t *symclass; + uint64_t *symrep; + Trans *transtorep; + Trans *ttrep_move[NMOVES]; - bool generated; - Indexer * i[99]; - uint64_t * selfsim; /* used only in fixnasty */ + bool generated; + Indexer *i[99]; + uint64_t *selfsim; /* used only in fixnasty */ - Moveset * moveset; /* for pruning, mt and compressing */ - uint64_t updated; - entry_group_t * ptable; - int ptablebase; /* Renamed */ - bool compact; /* Only needed for generation, maybe keep */ - uint64_t count[16]; /* Only needed for generation and print */ + Moveset *moveset; /* for pruning, mt and compressing */ + uint64_t updated; + entry_group_t *ptable; + int ptablebase; /* Renamed */ + bool compact; /* Only needed for generation, maybe keep */ + uint64_t count[16]; /* Only needed for generation and print */ } Coordinate; -void gen_coord(Coordinate *coord); -uint64_t index_coord(Coordinate *coord, Cube *cube, - Trans *offtrans); -uint64_t move_coord(Coordinate *coord, Move m, - uint64_t ind, Trans *offtrans); -bool test_coord(Coordinate *coord); -uint64_t trans_coord(Coordinate *coord, Trans t, uint64_t ind); - -void print_ptable(Coordinate *coord); -int ptableval(Coordinate *coord, uint64_t ind); +void gen_coord(Coordinate *); +uint64_t index_coord(Coordinate *, Cube *, Trans *); +uint64_t move_coord(Coordinate *, Move, uint64_t, Trans *); +uint64_t trans_coord(Coordinate *, Trans, uint64_t); +int ptableval(Coordinate *, uint64_t); diff --git a/src/cube.c b/src/cube.c @@ -1,7 +1,13 @@ #include "cube.h" +static void apply_permutation(int *, int *, int, int *); +static void sum_arrays_mod(int *, int *, int, int); +static Move read_move(char *, int *); +static void init_moves(); +static void init_trans(); + static Cube move_array[NMOVES]; -Move moves_ttable[NTRANS][NMOVES]; +Move moves_ttable[NTRANS][NMOVES]; Trans trans_ttable[NTRANS][NTRANS]; Trans trans_itable[NTRANS]; @@ -393,8 +399,6 @@ transform_trans(Trans t, Trans m) return trans_ttable[t][m]; } -/* Initialization ************************************************************/ - static void init_moves() { Move m; diff --git a/src/cube.h b/src/cube.h @@ -1,10 +1,10 @@ -#define false 0 -#define true 1 -#define NMOVES 55 -#define NTRANS 48 -#define MAX_ALG_LEN 22 -#define MIN(a,b) (((a) < (b)) ? (a) : (b)) -#define MAX(a,b) (((a) > (b)) ? (a) : (b)) +#define false 0 +#define true 1 +#define NMOVES 55 +#define NTRANS 48 +#define MAX_ALG_LEN 22 +#define MIN(a,b) (((a) < (b)) ? (a) : (b)) +#define MAX(a,b) (((a) > (b)) ? (a) : (b)) typedef int bool; typedef enum edge { UF, UL, UB, UR, DF, DL, DB, DR, FR, FL, BL, BR } Edge; @@ -41,27 +41,27 @@ typedef struct { int n; Trans t[NTRANS]; } TransGroup; extern TransGroup tgrp_udfix; -void compose(Cube *c2, Cube *c1); /* Use c2 as an alg on c1 */ -void copy_cube(Cube *src, Cube *dst); -void invert_cube(Cube *cube); -bool is_solved(Cube *cube); -void make_solved(Cube *cube); +void compose(Cube *, Cube *); +void copy_cube(Cube *, Cube *); +void invert_cube(Cube *); +bool is_solved(Cube *); +void make_solved(Cube *); -Move base_move(Move m); -bool commute(Move m1, Move m2); -Move inverse_move(Move m); +Move base_move(Move); +bool commute(Move, Move); +Move inverse_move(Move); -void copy_alg(Alg *src, Alg *dst); -void append_move(Alg *alg, Move m, bool inverse); -void apply_move(Move m, Cube *cube); -void apply_alg(Alg *alg, Cube *cube); -bool apply_scramble(char *str, Cube *c); -int alg_string(Alg *alg, char *str); +void copy_alg(Alg *, Alg *); +void append_move(Alg *, Move, bool); +void apply_move(Move, Cube *); +void apply_alg(Alg *, Cube *); +bool apply_scramble(char *, Cube *); +int alg_string(Alg *, char *); -void apply_trans(Trans t, Cube *cube); -Trans inverse_trans(Trans t); -void transform_alg(Trans t, Alg *alg); -Move transform_move(Trans t, Move m); -Trans transform_trans(Trans t, Trans m); +void apply_trans(Trans, Cube *); +Trans inverse_trans(Trans); +void transform_alg(Trans, Alg *); +Move transform_move(Trans, Move); +Trans transform_trans(Trans, Trans); void init_cube(); diff --git a/src/nissy.c b/src/nissy.c @@ -6,6 +6,10 @@ #include "solve.h" #include "steps.h" +static bool set_step(char *, Step **); +static bool set_solutiontype(char *, SolutionType *); +static bool set_trans(char *, Trans *); + static bool set_step(char *str, Step **step) { diff --git a/src/solve.c b/src/solve.c @@ -5,15 +5,15 @@ #include "coord.h" #include "solve.h" -static void append_sol(DfsArg *arg); -static bool allowed_next(Move move, Move l0, Move l1); -static void get_state(Coordinate *coord[], Cube *cube, CubeState *state); -static void copy_dfsarg(DfsArg *src, DfsArg *dst); -static int lower_bound(Coordinate *coord[], CubeState *state); -static void dfs(DfsArg *arg); -static void dfs_niss(DfsArg *arg); -static bool dfs_move_checkstop(DfsArg *arg); -static bool niss_makes_sense(DfsArg *arg); +static void append_sol(DfsArg *); +static bool allowed_next(Move m, Move l0, Move l1); +static void get_state(Coordinate *[], Cube *, CubeState *); +static void copy_dfsarg(DfsArg *src, DfsArg *dst); /* TODO: remove */ +static int lower_bound(Coordinate *[], CubeState *); +static void dfs(DfsArg *); +static void dfs_niss(DfsArg *); +static bool dfs_move_checkstop(DfsArg *); +static bool niss_makes_sense(DfsArg *); static void append_sol(DfsArg *arg) diff --git a/src/solve.h b/src/solve.h @@ -3,24 +3,24 @@ typedef enum { NORMAL, INVERSE, NISS } SolutionType; typedef struct { uint64_t val; Trans t; } CubeState; typedef struct { - char * shortname; - Moveset * moveset; - Coordinate * coord[MAX_N_COORD]; + char *shortname; + Moveset *moveset; + Coordinate *coord[MAX_N_COORD]; } Step; typedef struct { - Cube * cube; - CubeState state[MAX_N_COORD]; - Step * s; - Trans t; - SolutionType st; - char ** sol; - int d; - int bound; - bool niss; - bool has_nissed; - Move last[2]; - Move lastinv[2]; - Alg * current_alg; + Cube *cube; + CubeState state[MAX_N_COORD]; + Step *s; + Trans t; + SolutionType st; + char **sol; + int d; + int bound; + bool niss; + bool has_nissed; + Move last[2]; + Move lastinv[2]; + Alg *current_alg; } DfsArg; int solve(Step *, Trans, int, SolutionType, Cube *, char *); diff --git a/src/steps.c b/src/steps.c @@ -12,10 +12,21 @@ #define BINOM12ON4 495ULL #define BINOM8ON4 70ULL -static bool moveset_HTM(Move m); -static bool moveset_eofb(Move m); -static bool moveset_drud(Move m); -static bool moveset_htr(Move m); +static bool moveset_HTM(Move); +static bool moveset_eofb(Move); +static bool moveset_drud(Move); +static bool moveset_htr(Move); + +static int factorial(int); +static int perm_to_index(int *, int); +static void index_to_perm(int, int, int *); +static int binomial(int, int); +static int subset_to_index(int *, int, int); +static void index_to_subset(int, int, int, int *); +static int digit_array_to_int(int *, int, int); +static void int_to_digit_array(int, int, int, int *); +static void int_to_sum_zero_array(int, int, int, int *); +static int perm_sign(int *, int); static uint64_t index_eofb(Cube *cube); static void invindex_eofb(uint64_t ind, Cube *ret);