h48

A prototype for an optimal Rubik's cube solver, work in progress.
git clone https://git.tronto.net/h48
Download | Log | Files | Refs | README | LICENSE

commit 9e6465bcc8f0d9bd1d78ad357a623452358ba7f2
parent 1e1fd628207034b0412c50e289f146d34c5baf71
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date:   Fri, 14 Mar 2025 16:46:50 +0100

Added checkdata for coord EO

Diffstat:
MTODO_COORDINATES | 4----
Msrc/nissy.c | 5+++++
Msrc/solvers/coord/gendata.h | 24++++++++++++++++++++++++
Msrc/solvers/h48/gendata_h48.h | 1+
Mtools/expected_distributions.h | 45+++++++++++++++++++++++++++++++++++++--------
5 files changed, 67 insertions(+), 12 deletions(-)

diff --git a/TODO_COORDINATES b/TODO_COORDINATES @@ -1,8 +1,4 @@ - coord solver - - add checkdata for coord - - return to fully qualified solver name - x undo chnages to API - - add a parameter to gendata to get a shortname (filename) for the table - there is an error (try R B2 as scramble, EO on RL) - debug - fix diff --git a/src/nissy.c b/src/nissy.c @@ -80,8 +80,13 @@ checkdata(const char *buf, const tableinfo_t *info) } else if (!strncmp(info->solver, "h48", 3)) { getdistribution_h48((uint8_t *)buf + INFOSIZE, distr, info->h48h, info->bits); + } else if (!strncmp(info->solver, "coordinate solver for ", 22)) { + getdistribution_coord((uint8_t *)buf + INFOSIZE, + info->solver + 22, distr); } else if (!strncmp(info->solver, "eoesep data for h48", 19)) { return true; + } else if (!strncmp(info->solver, "coord helper table for ", 23)) { + return true; } else { LOG("checkdata: unknown solver %s\n", info->solver); return false; diff --git a/src/solvers/coord/gendata.h b/src/solvers/coord/gendata.h @@ -1,6 +1,8 @@ STATIC size_t gendata_coord(const coord_t *, void *); STATIC int64_t gendata_coord_dispatch(const char *, void *); STATIC tableinfo_t genptable_coord(const coord_t *, const void *, uint8_t *); +STATIC void getdistribution_coord( + const uint8_t *, const char *, uint64_t [static INFO_DISTRIBUTION_LEN]); 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); @@ -122,6 +124,28 @@ genptable_coord(const coord_t *coord, const void *data, uint8_t *table) return info; } +STATIC void +getdistribution_coord( + const uint8_t *table, + const char *coord, + uint64_t distr[static INFO_DISTRIBUTION_LEN] +) +{ + uint8_t v; + uint64_t i; + coord_t *c; + + memset(distr, 0, INFO_DISTRIBUTION_LEN * sizeof(uint64_t)); + + if((c = parse_coord(coord, strlen(coord))) == NULL) + return; + + for (i = 0; i < c->max; i++) { + v = get_coord_pval(c, table, i); + distr[v]++; + } +} + STATIC uint8_t get_coord_pval(const coord_t *coord, const uint8_t *table, uint64_t i) { diff --git a/src/solvers/h48/gendata_h48.h b/src/solvers/h48/gendata_h48.h @@ -682,6 +682,7 @@ getdistribution_h48( distr[val]++; } } + STATIC const uint32_t * get_cocsepdata_constptr(const void *data) { diff --git a/tools/expected_distributions.h b/tools/expected_distributions.h @@ -58,7 +58,6 @@ uint64_t expected_h48[12][9][21] = { [2] = 392789689, [3] = 477195231, }, - }, [4] = { [2] = { @@ -126,6 +125,17 @@ uint64_t expected_h48[12][9][21] = { }, }; +uint64_t expected_eo[21] = { + [0] = 1, + [1] = 2, + [2] = 25, + [3] = 202, + [4] = 620, + [5] = 900, + [6] = 285, + [7] = 13, +}; + static bool distribution_equal(const uint64_t *expected, const uint64_t *actual, int n) { @@ -144,6 +154,18 @@ distribution_equal(const uint64_t *expected, const uint64_t *actual, int n) return equal; } +STATIC bool +check_table(uint64_t *exp, tableinfo_t *info) +{ + if (!distribution_equal(exp, info->distribution, info->maxvalue)) { + printf("ERROR! Distribution is incorrect\n"); + return false; + } + + printf("Distribution is correct\n"); + return true; +} + static bool check_cocsep(uint64_t data_size, const void *data) { @@ -169,6 +191,7 @@ unknown_h48(uint8_t h, uint8_t k) STATIC bool check_distribution(const char *solver, uint64_t data_size, const void *data) { + const char *str; tableinfo_t info = {0}; if (!strncmp(solver, "h48", 3)) { @@ -184,14 +207,20 @@ check_distribution(const char *solver, uint64_t data_size, const void *data) if (unknown_h48(info.h48h, info.bits)) goto check_distribution_unknown; - if (!distribution_equal(expected_h48[info.h48h][info.bits], - info.distribution, info.maxvalue)) { - printf("ERROR! h48 distribution is incorrect\n"); - return false; - } + return check_table(expected_h48[info.h48h][info.bits], &info); + } - printf("h48 distribution is correct\n"); - return true; + if (!strncmp(solver, "coord_", 6)) { + readtableinfo(data_size, data, &info); + if (!strncmp(info.solver, "coord helper table for ", 23)) + readtableinfo_n(data_size, data, 2, &info); + + str = info.solver + 22; /* "coordinate solver for COORD" */ + if (!strcmp(str, "EO")) { + return check_table(expected_eo, &info); + } else { + goto check_distribution_unknown; + } } check_distribution_unknown: