From 110e079f81277b40ec76be0b86b074a632496109 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Sat, 8 Mar 2025 06:26:12 +0100 Subject: renamed some files --- src/solvers/coord/common.h | 48 -------- src/solvers/coord/coord.h | 5 + src/solvers/coord/coord_common.h | 46 ++++++++ src/solvers/coord/coord_solve.h | 228 -------------------------------------- src/solvers/coord/gendata.h | 136 +++++++++++++++++++++++ src/solvers/coord/gendata_coord.h | 136 ----------------------- src/solvers/coord/solve.h | 224 +++++++++++++++++++++++++++++++++++++ src/solvers/solvers.h | 2 +- 8 files changed, 412 insertions(+), 413 deletions(-) delete mode 100644 src/solvers/coord/common.h create mode 100644 src/solvers/coord/coord.h create mode 100644 src/solvers/coord/coord_common.h delete mode 100644 src/solvers/coord/coord_solve.h create mode 100644 src/solvers/coord/gendata.h delete mode 100644 src/solvers/coord/gendata_coord.h create mode 100644 src/solvers/coord/solve.h (limited to 'src/solvers') diff --git a/src/solvers/coord/common.h b/src/solvers/coord/common.h deleted file mode 100644 index 1d6e622..0000000 --- a/src/solvers/coord/common.h +++ /dev/null @@ -1,48 +0,0 @@ -#include "eo.h" - -coord_t *all_coordinates[] = { - &coordinate_eo, - NULL -}; - -STATIC void append_coord_name(const coord_t *, char *); -STATIC coord_t *parse_coord(const char *, int); -STATIC uint8_t parse_axis(const char *, int); - -STATIC void -append_coord_name(const coord_t *coord, char *str) -{ - int i, j; - - i = 0; - j = strlen(str); - while (coord->name[i]) str[j++] = coord->name[i++]; - - str[j] = '\0'; -} - -STATIC coord_t * -parse_coord(const char *coord, int n) -{ - int i; - - for (i = 0; all_coordinates[i] != NULL; i++) - if (!strncmp(all_coordinates[i]->name, coord, n)) - return all_coordinates[i]; - - return NULL; -} - -STATIC uint8_t -parse_axis(const char *axis, int n) -{ - if (!strncmp(axis, "UD", n) || !strncmp(axis, "DU", n)) { - return AXIS_UD; - } else if (!strncmp(axis, "RL", n) || !strncmp(axis, "LR", n)) { - return AXIS_RL; - } else if (!strncmp(axis, "FB", n) || !strncmp(axis, "BF", n)) { - return AXIS_FB; - } - - return UINT8_ERROR; -} diff --git a/src/solvers/coord/coord.h b/src/solvers/coord/coord.h new file mode 100644 index 0000000..fc241cb --- /dev/null +++ b/src/solvers/coord/coord.h @@ -0,0 +1,5 @@ +#include "coord_types_macros.h" +#include "eo.h" +#include "coord_common.h" +#include "gendata.h" +#include "solve.h" diff --git a/src/solvers/coord/coord_common.h b/src/solvers/coord/coord_common.h new file mode 100644 index 0000000..d827665 --- /dev/null +++ b/src/solvers/coord/coord_common.h @@ -0,0 +1,46 @@ +coord_t *all_coordinates[] = { + &coordinate_eo, + NULL +}; + +STATIC void append_coord_name(const coord_t *, char *); +STATIC coord_t *parse_coord(const char *, int); +STATIC uint8_t parse_axis(const char *, int); + +STATIC void +append_coord_name(const coord_t *coord, char *str) +{ + int i, j; + + i = 0; + j = strlen(str); + while (coord->name[i]) str[j++] = coord->name[i++]; + + str[j] = '\0'; +} + +STATIC coord_t * +parse_coord(const char *coord, int n) +{ + int i; + + for (i = 0; all_coordinates[i] != NULL; i++) + if (!strncmp(all_coordinates[i]->name, coord, n)) + return all_coordinates[i]; + + return NULL; +} + +STATIC uint8_t +parse_axis(const char *axis, int n) +{ + if (!strncmp(axis, "UD", n) || !strncmp(axis, "DU", n)) { + return AXIS_UD; + } else if (!strncmp(axis, "RL", n) || !strncmp(axis, "LR", n)) { + return AXIS_RL; + } else if (!strncmp(axis, "FB", n) || !strncmp(axis, "BF", n)) { + return AXIS_FB; + } + + return UINT8_ERROR; +} diff --git a/src/solvers/coord/coord_solve.h b/src/solvers/coord/coord_solve.h deleted file mode 100644 index ff6f497..0000000 --- a/src/solvers/coord/coord_solve.h +++ /dev/null @@ -1,228 +0,0 @@ -#include "coord_types_macros.h" -#include "common.h" -#include "gendata_coord.h" - -#define MAXLEN_COORDSOL 20 - -typedef struct { - cube_t cube; - uint8_t depth; - uint8_t nmoves; - uint8_t moves[MAXLEN_COORDSOL]; - coord_t *coord; - const void *coord_data; - const uint8_t *ptable; - uint8_t trans; - int64_t *nsols; - int64_t maxsolutions; - int optimal; - uint8_t *shortest_sol; - uint64_t solutions_size; - uint64_t *solutions_used; - char **solutions; -} dfsarg_solve_coord_t; - -STATIC int64_t solve_coord(cube_t, coord_t *, uint8_t, uint8_t, uint8_t, - uint8_t, uint64_t, int, int, uint64_t, const void *, uint64_t, char *); -STATIC int64_t solve_coord_dispatch(cube_t, const char *, uint8_t, uint8_t, - uint8_t, uint64_t, int, int, uint64_t, const void *, uint64_t, char *); -STATIC bool solve_coord_appendchar(char *, uint64_t, uint64_t *, char); -STATIC int64_t solve_coord_appendsolution(dfsarg_solve_coord_t *); -STATIC int64_t solve_coord_dfs(dfsarg_solve_coord_t *); - -STATIC int64_t -solve_coord_appendsolution(dfsarg_solve_coord_t *arg) -{ - uint8_t i, t, tmoves[MAXLEN_COORDSOL]; - - if (*arg->nsols >= arg->maxsolutions || - arg->nmoves > *arg->shortest_sol + arg->optimal) - return 0; - - sortparallel(arg->moves, arg->nmoves); - - t = inverse_trans(arg->trans); - for (i = 0; i < arg->nmoves; i++) - tmoves[i] = transform_move(arg->moves[i], t); - - /* TODO append tmoves[] */ - - return 1; -} - -STATIC bool -solve_coord_appendchar(char *s, uint64_t s_size, uint64_t *s_used, char c) -{ - if (s_size == *s_used) - return false; - - s[*s_used] = c; - (*s_used)++; - - return true; -} - -STATIC int64_t -solve_coord_dfs(dfsarg_solve_coord_t *arg) -{ - uint64_t coord; - uint8_t pval; - - coord = arg->coord->coord(arg->cube, arg->coord_data); - - if (coord == 0) { - if (arg->nmoves != arg->depth) - return 0; - return solve_coord_appendsolution(arg); - } - - pval = get_coord_pval(arg->coord, arg->ptable, coord); - if (arg->nmoves + pval > arg->depth) - return 0; - - /* TODO recursive call */ - /* Is allowednextmove available here? */ - - return 0; -} - -STATIC int64_t -solve_coord_dispatch( - cube_t cube, - const char *coord_axis, - uint8_t nissflag, - uint8_t minmoves, - uint8_t maxmoves, - uint64_t maxsolutions, - int optimal, - int threads, - uint64_t data_size, - const void *data, - uint64_t sols_size, - char *sols -) -{ - int i, n; - coord_t *coord; - uint8_t axis; - - n = strlen(coord_axis); - for (i = 0; coord_axis[i] != ' ' && coord_axis[i] != '\0'; i++) ; - - coord = parse_coord(coord_axis, i); - axis = parse_axis(coord_axis + i + 1, n - i - 1); - - if (coord == NULL) { - LOG("Could not parse coordinate '%s'\n", coord_axis); - return NISSY_ERROR_INVALID_SOLVER; - } - - if (axis == UINT8_ERROR) { - LOG("Could not parse axis from '%s'\n", coord_axis); - return NISSY_ERROR_INVALID_SOLVER; - } - - return solve_coord(cube, coord, axis, nissflag, minmoves, maxmoves, - maxsolutions, optimal, threads, data_size, data, sols_size, sols); -} - -STATIC int64_t -solve_coord( - cube_t cube, - coord_t *coord, - uint8_t axis, - uint8_t nissflag, - uint8_t minmoves, - uint8_t maxmoves, - uint64_t maxsolutions, - int optimal, - int threads, - uint64_t data_size, - const void *data, - uint64_t sols_size, - char *sols -) -{ - int8_t d; - uint8_t t, shortest_sol; - int64_t nsols; - uint64_t sols_used; - cube_t c; - const void *coord_data; - const uint8_t *ptable; - dfsarg_solve_coord_t arg; - tableinfo_t info; - - if (readtableinfo(data_size, data, &info) != NISSY_OK) - goto solve_coord_error_data; - - if (info.type == TABLETYPE_PRUNING) { - /* Only the pruning table */ - coord_data = NULL; - ptable = (uint8_t *)data + INFOSIZE; - } else { - /* Coordinate has extra data */ - coord_data = (uint8_t *)data + INFOSIZE; - ptable = (uint8_t *)data + info.next + INFOSIZE; - } - - nsols = 0; - sols_used = 0; - shortest_sol = MAXLEN_COORDSOL + 1; - c = transform(cube, t); - t = coord->axistrans[axis]; - - arg = (dfsarg_solve_coord_t) { - .cube = c, - .coord = coord, - .coord_data = coord_data, - .ptable = ptable, - .trans = t, - .nsols = &nsols, - .maxsolutions = (int64_t)maxsolutions, - .optimal = optimal, - .shortest_sol = &shortest_sol, - .solutions_size = sols_size, - .solutions_used = &sols_used, - .solutions = &sols, - }; - - if (coord->coord(c, coord_data) == 0) { - if (minmoves == 0) { - nsols = 1; - if (!solve_coord_appendchar( - sols, sols_size, &sols_used, '\n')) - goto solve_coord_error_buffer; - } - goto solve_coord_done; - } - - for ( - d = MAX(minmoves, 1); - d <= maxmoves && nsols < (int64_t)maxsolutions - && !(nsols != 0 && d > shortest_sol + optimal); - d++ - ) { - if (d >= 10) - LOG("Found %" PRId64 " solutions, searching at depth %" - PRId8 "\n", nsols, d); - - arg.depth = d; - arg.nmoves = 0; - nsols += solve_coord_dfs(&arg); - } - -solve_coord_done: - if (!solve_coord_appendchar(sols, sols_size, &sols_used, '\0')) - goto solve_coord_error_buffer; - - return nsols; - -solve_coord_error_data: - LOG("solve_coord: error reading table\n"); - return NISSY_ERROR_DATA; - -solve_coord_error_buffer: - LOG("Could not append solution to buffer: size too small\n"); - return NISSY_ERROR_BUFFER_SIZE; -} diff --git a/src/solvers/coord/gendata.h b/src/solvers/coord/gendata.h new file mode 100644 index 0000000..3d385e9 --- /dev/null +++ b/src/solvers/coord/gendata.h @@ -0,0 +1,136 @@ +STATIC size_t gendata_coordinate(const coord_t *, void *); +STATIC size_t gendata_coordinate_name(const char *, void *); +STATIC tableinfo_t genptable_coordinate(const coord_t *, const void *, uint8_t *); +STATIC uint8_t get_coord_pval(const coord_t *, const uint8_t *, uint64_t); +STATIC void set_coord_pval(const coord_t *, uint8_t *, uint64_t, uint8_t); + +STATIC size_t +gendata_coordinate_name(const char *name, void *buf) +{ + coord_t *coord; + + coord = parse_coord(name, strlen(name)); + if (coord == NULL) { + LOG("Cannot generate data for coordinate '%s': not found\n", + name); + return 0; + } + + return gendata_coordinate(coord, buf); +} + +STATIC size_t +gendata_coordinate(const coord_t *coord, void *buf) +{ + uint64_t coord_dsize, tablesize, ninfo; + void *pruningbuf, *coord_data; + uint8_t *table; + tableinfo_t coord_data_info, pruning_info; + + coord_data = buf == NULL ? NULL : ((uint8_t *)buf) + INFOSIZE; + coord_dsize = coord->gendata(coord_data); + ninfo = coord_dsize == 0 ? 1 : 2; + tablesize = DIV_ROUND_UP(coord->max, 2); + + if (buf == NULL) + goto gendata_coordinate_return_size; + + if (ninfo == 2) { + coord_data_info = (tableinfo_t) { + .solver = "coord helper table for ", + .type = TABLETYPE_SPECIAL, + .infosize = INFOSIZE, + .fullsize = INFOSIZE + coord_dsize, + .hash = 0, /* TODO */ + .next = INFOSIZE + coord_dsize, + + /* Unknown / non-applicable values */ + .entries = 0, + .classes = 0, + .bits = 0, + .base = 0, + .maxvalue = 0, + }; + + append_coord_name(coord, coord_data_info.solver); + + writetableinfo(&coord_data_info, INFOSIZE + coord_dsize, buf); + + pruningbuf = ((uint8_t *)buf) + INFOSIZE + coord_dsize; + } else { + pruningbuf = buf; + } + + table = ((uint8_t *)pruningbuf) + INFOSIZE; + pruning_info = genptable_coordinate(coord, coord_data, table); + writetableinfo(&pruning_info, INFOSIZE + tablesize, pruningbuf); + +gendata_coordinate_return_size: + return ninfo * INFOSIZE + coord_dsize + tablesize; +} + +STATIC tableinfo_t +genptable_coordinate(const coord_t *coord, const void *data, uint8_t *table) +{ + uint64_t tablesize, i, j, d, tot; + tableinfo_t info; + uint8_t m; + cube_t c, cc; + + tablesize = DIV_ROUND_UP(coord->max, 2); + + memset(table, 0xFF, tablesize); + + info = (tableinfo_t) { + .solver = "coordinate solver for ", + .type = TABLETYPE_PRUNING, + .infosize = INFOSIZE, + .fullsize = INFOSIZE + tablesize, + .hash = 0, /* TODO */ + .entries = coord->max, + .classes = 0, + .bits = 4, + .base = 0, + .maxvalue = 0, + .next = 0 + }; + + memset(info.distribution, 0, INFO_DISTRIBUTION_LEN * sizeof(uint64_t)); + append_coord_name(coord, info.solver); + + i = coord->coord(SOLVED_CUBE, data); + set_coord_pval(coord, table, i, 0); + info.distribution[0] = 1; + for (d = 1, tot = 1; tot < coord->max; d++) { + for (i = 0; i < coord->max; i++) { + if (get_coord_pval(coord, table, i) == d-1) { + c = coord->cube(i, data); + for (m = 0; m < 18; m++) { + cc = move(c, m); + j = coord->coord(cc, data); + if (get_coord_pval(coord, table, j) > d) { + set_coord_pval(coord, table, j, d); + tot++; + info.distribution[d]++; + } + } + } + } + } + info.maxvalue = d-1; + + return info; +} + +STATIC uint8_t +get_coord_pval(const coord_t *coord, const uint8_t *table, uint64_t i) +{ + return (table[COORD_INDEX(i)] & COORD_MASK(i)) >> COORD_SHIFT(i); +} + +STATIC void +set_coord_pval(const coord_t *coord, uint8_t *table, uint64_t i, uint8_t val) +{ + table[COORD_INDEX(i)] = (table[COORD_INDEX(i)] & (~COORD_MASK(i))) + | (val << COORD_SHIFT(i)); +} diff --git a/src/solvers/coord/gendata_coord.h b/src/solvers/coord/gendata_coord.h deleted file mode 100644 index 3d385e9..0000000 --- a/src/solvers/coord/gendata_coord.h +++ /dev/null @@ -1,136 +0,0 @@ -STATIC size_t gendata_coordinate(const coord_t *, void *); -STATIC size_t gendata_coordinate_name(const char *, void *); -STATIC tableinfo_t genptable_coordinate(const coord_t *, const void *, uint8_t *); -STATIC uint8_t get_coord_pval(const coord_t *, const uint8_t *, uint64_t); -STATIC void set_coord_pval(const coord_t *, uint8_t *, uint64_t, uint8_t); - -STATIC size_t -gendata_coordinate_name(const char *name, void *buf) -{ - coord_t *coord; - - coord = parse_coord(name, strlen(name)); - if (coord == NULL) { - LOG("Cannot generate data for coordinate '%s': not found\n", - name); - return 0; - } - - return gendata_coordinate(coord, buf); -} - -STATIC size_t -gendata_coordinate(const coord_t *coord, void *buf) -{ - uint64_t coord_dsize, tablesize, ninfo; - void *pruningbuf, *coord_data; - uint8_t *table; - tableinfo_t coord_data_info, pruning_info; - - coord_data = buf == NULL ? NULL : ((uint8_t *)buf) + INFOSIZE; - coord_dsize = coord->gendata(coord_data); - ninfo = coord_dsize == 0 ? 1 : 2; - tablesize = DIV_ROUND_UP(coord->max, 2); - - if (buf == NULL) - goto gendata_coordinate_return_size; - - if (ninfo == 2) { - coord_data_info = (tableinfo_t) { - .solver = "coord helper table for ", - .type = TABLETYPE_SPECIAL, - .infosize = INFOSIZE, - .fullsize = INFOSIZE + coord_dsize, - .hash = 0, /* TODO */ - .next = INFOSIZE + coord_dsize, - - /* Unknown / non-applicable values */ - .entries = 0, - .classes = 0, - .bits = 0, - .base = 0, - .maxvalue = 0, - }; - - append_coord_name(coord, coord_data_info.solver); - - writetableinfo(&coord_data_info, INFOSIZE + coord_dsize, buf); - - pruningbuf = ((uint8_t *)buf) + INFOSIZE + coord_dsize; - } else { - pruningbuf = buf; - } - - table = ((uint8_t *)pruningbuf) + INFOSIZE; - pruning_info = genptable_coordinate(coord, coord_data, table); - writetableinfo(&pruning_info, INFOSIZE + tablesize, pruningbuf); - -gendata_coordinate_return_size: - return ninfo * INFOSIZE + coord_dsize + tablesize; -} - -STATIC tableinfo_t -genptable_coordinate(const coord_t *coord, const void *data, uint8_t *table) -{ - uint64_t tablesize, i, j, d, tot; - tableinfo_t info; - uint8_t m; - cube_t c, cc; - - tablesize = DIV_ROUND_UP(coord->max, 2); - - memset(table, 0xFF, tablesize); - - info = (tableinfo_t) { - .solver = "coordinate solver for ", - .type = TABLETYPE_PRUNING, - .infosize = INFOSIZE, - .fullsize = INFOSIZE + tablesize, - .hash = 0, /* TODO */ - .entries = coord->max, - .classes = 0, - .bits = 4, - .base = 0, - .maxvalue = 0, - .next = 0 - }; - - memset(info.distribution, 0, INFO_DISTRIBUTION_LEN * sizeof(uint64_t)); - append_coord_name(coord, info.solver); - - i = coord->coord(SOLVED_CUBE, data); - set_coord_pval(coord, table, i, 0); - info.distribution[0] = 1; - for (d = 1, tot = 1; tot < coord->max; d++) { - for (i = 0; i < coord->max; i++) { - if (get_coord_pval(coord, table, i) == d-1) { - c = coord->cube(i, data); - for (m = 0; m < 18; m++) { - cc = move(c, m); - j = coord->coord(cc, data); - if (get_coord_pval(coord, table, j) > d) { - set_coord_pval(coord, table, j, d); - tot++; - info.distribution[d]++; - } - } - } - } - } - info.maxvalue = d-1; - - return info; -} - -STATIC uint8_t -get_coord_pval(const coord_t *coord, const uint8_t *table, uint64_t i) -{ - return (table[COORD_INDEX(i)] & COORD_MASK(i)) >> COORD_SHIFT(i); -} - -STATIC void -set_coord_pval(const coord_t *coord, uint8_t *table, uint64_t i, uint8_t val) -{ - table[COORD_INDEX(i)] = (table[COORD_INDEX(i)] & (~COORD_MASK(i))) - | (val << COORD_SHIFT(i)); -} diff --git a/src/solvers/coord/solve.h b/src/solvers/coord/solve.h new file mode 100644 index 0000000..e954aac --- /dev/null +++ b/src/solvers/coord/solve.h @@ -0,0 +1,224 @@ +#define MAXLEN_COORDSOL 20 + +typedef struct { + cube_t cube; + uint8_t depth; + uint8_t nmoves; + uint8_t moves[MAXLEN_COORDSOL]; + coord_t *coord; + const void *coord_data; + const uint8_t *ptable; + uint8_t trans; + int64_t *nsols; + int64_t maxsolutions; + int optimal; + uint8_t *shortest_sol; + uint64_t solutions_size; + uint64_t *solutions_used; + char **solutions; +} dfsarg_solve_coord_t; + +STATIC int64_t solve_coord(cube_t, coord_t *, uint8_t, uint8_t, uint8_t, + uint8_t, uint64_t, int, int, uint64_t, const void *, uint64_t, char *); +STATIC int64_t solve_coord_dispatch(cube_t, const char *, uint8_t, uint8_t, + uint8_t, uint64_t, int, int, uint64_t, const void *, uint64_t, char *); +STATIC bool solve_coord_appendchar(char *, uint64_t, uint64_t *, char); +STATIC int64_t solve_coord_appendsolution(dfsarg_solve_coord_t *); +STATIC int64_t solve_coord_dfs(dfsarg_solve_coord_t *); + +STATIC int64_t +solve_coord_appendsolution(dfsarg_solve_coord_t *arg) +{ + uint8_t i, t, tmoves[MAXLEN_COORDSOL]; + + if (*arg->nsols >= arg->maxsolutions || + arg->nmoves > *arg->shortest_sol + arg->optimal) + return 0; + + sortparallel(arg->moves, arg->nmoves); + + t = inverse_trans(arg->trans); + for (i = 0; i < arg->nmoves; i++) + tmoves[i] = transform_move(arg->moves[i], t); + + /* TODO append tmoves[] */ + + return 1; +} + +STATIC bool +solve_coord_appendchar(char *s, uint64_t s_size, uint64_t *s_used, char c) +{ + if (s_size == *s_used) + return false; + + s[*s_used] = c; + (*s_used)++; + + return true; +} + +STATIC int64_t +solve_coord_dfs(dfsarg_solve_coord_t *arg) +{ + uint64_t coord; + uint8_t pval; + + coord = arg->coord->coord(arg->cube, arg->coord_data); + + if (coord == 0) { + if (arg->nmoves != arg->depth) + return 0; + return solve_coord_appendsolution(arg); + } + + pval = get_coord_pval(arg->coord, arg->ptable, coord); + if (arg->nmoves + pval > arg->depth) + return 0; + + /* TODO recursive call */ + /* Is allowednextmove available here? */ + + return 0; +} + +STATIC int64_t +solve_coord_dispatch( + cube_t cube, + const char *coord_axis, + uint8_t nissflag, + uint8_t minmoves, + uint8_t maxmoves, + uint64_t maxsolutions, + int optimal, + int threads, + uint64_t data_size, + const void *data, + uint64_t sols_size, + char *sols +) +{ + int i, n; + coord_t *coord; + uint8_t axis; + + n = strlen(coord_axis); + for (i = 0; coord_axis[i] != ' ' && coord_axis[i] != '\0'; i++) ; + + coord = parse_coord(coord_axis, i); + axis = parse_axis(coord_axis + i + 1, n - i - 1); + + if (coord == NULL) { + LOG("Could not parse coordinate '%s'\n", coord_axis); + return NISSY_ERROR_INVALID_SOLVER; + } + + if (axis == UINT8_ERROR) { + LOG("Could not parse axis from '%s'\n", coord_axis); + return NISSY_ERROR_INVALID_SOLVER; + } + + return solve_coord(cube, coord, axis, nissflag, minmoves, maxmoves, + maxsolutions, optimal, threads, data_size, data, sols_size, sols); +} + +STATIC int64_t +solve_coord( + cube_t cube, + coord_t *coord, + uint8_t axis, + uint8_t nissflag, + uint8_t minmoves, + uint8_t maxmoves, + uint64_t maxsolutions, + int optimal, + int threads, + uint64_t data_size, + const void *data, + uint64_t sols_size, + char *sols +) +{ + int8_t d; + uint8_t t, shortest_sol; + int64_t nsols; + uint64_t sols_used; + cube_t c; + const void *coord_data; + const uint8_t *ptable; + dfsarg_solve_coord_t arg; + tableinfo_t info; + + if (readtableinfo(data_size, data, &info) != NISSY_OK) + goto solve_coord_error_data; + + if (info.type == TABLETYPE_PRUNING) { + /* Only the pruning table */ + coord_data = NULL; + ptable = (uint8_t *)data + INFOSIZE; + } else { + /* Coordinate has extra data */ + coord_data = (uint8_t *)data + INFOSIZE; + ptable = (uint8_t *)data + info.next + INFOSIZE; + } + + nsols = 0; + sols_used = 0; + shortest_sol = MAXLEN_COORDSOL + 1; + c = transform(cube, t); + t = coord->axistrans[axis]; + + arg = (dfsarg_solve_coord_t) { + .cube = c, + .coord = coord, + .coord_data = coord_data, + .ptable = ptable, + .trans = t, + .nsols = &nsols, + .maxsolutions = (int64_t)maxsolutions, + .optimal = optimal, + .shortest_sol = &shortest_sol, + .solutions_size = sols_size, + .solutions_used = &sols_used, + .solutions = &sols, + }; + + if (coord->coord(c, coord_data) == 0) { + if (minmoves == 0) { + nsols = 1; + if (!solve_coord_appendchar( + sols, sols_size, &sols_used, '\n')) + goto solve_coord_error_buffer; + } + goto solve_coord_done; + } + + for ( + d = MAX(minmoves, 1); + d <= maxmoves && nsols < (int64_t)maxsolutions + && !(nsols != 0 && d > shortest_sol + optimal); + d++ + ) { + if (d >= 10) + LOG("Found %" PRId64 " solutions, searching at depth %" + PRId8 "\n", nsols, d); + + arg.depth = d; + arg.nmoves = 0; + nsols += solve_coord_dfs(&arg); + } + +solve_coord_done: + if (!solve_coord_appendchar(sols, sols_size, &sols_used, '\0')) + goto solve_coord_error_buffer; + + return nsols; + +solve_coord_error_data: + LOG("solve_coord: error reading table\n"); + return NISSY_ERROR_DATA; + +solve_coord_error_buffer: + LOG("Could not append solution to buffer: size too small\n"); + return NISSY_ERROR_BUFFER_SIZE; +} diff --git a/src/solvers/solvers.h b/src/solvers/solvers.h index 154f8cc..7ef1746 100644 --- a/src/solvers/solvers.h +++ b/src/solvers/solvers.h @@ -1,3 +1,3 @@ #include "tables.h" #include "h48/h48.h" -#include "coord/coord_solve.h" +#include "coord/coord.h" -- cgit v1.3