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 91f912176045fd2f95fd45a0e12354e390dff219
parent bc2cba8529a163d129dec91b5ec448a29a14591a
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date:   Thu, 26 Sep 2024 17:07:02 +0200

Added checkdata tool

Diffstat:
Msrc/nissy.c | 7+++++--
Mtools/000_gendata/gendata.c | 29++---------------------------
Atools/100_checkdata/checkdata.c | 52++++++++++++++++++++++++++++++++++++++++++++++++++++
Atools/expected_distributions.h | 25+++++++++++++++++++++++++
4 files changed, 84 insertions(+), 29 deletions(-)

diff --git a/src/nissy.c b/src/nissy.c @@ -102,8 +102,11 @@ distribution_equal( } } - if (wrong > 0) - LOG("chekdata: %d wrong values\n", wrong); + if (wrong > 0) { + LOG("checkdata: %d wrong values\n", wrong); + } else { + LOG("checkdata: table is consistent with info\n"); + } return wrong > 0; } diff --git a/tools/000_gendata/gendata.c b/tools/000_gendata/gendata.c @@ -1,34 +1,9 @@ #include "../tool.h" +#include "../expected_distributions.h" char *solver, *options; uint64_t *expected; -uint64_t expected_h48[12][9][21] = { - [0] = { - [2] = { - [0] = 5473562, - [1] = 34776317, - [2] = 68566704, - [3] = 8750867, - }, - [4] = { - [0] = 1, - [1] = 1, - [2] = 4, - [3] = 34, - [4] = 331, - [5] = 3612, - [6] = 41605, - [7] = 474128, - [8] = 4953846, - [9] = 34776317, - [10] = 68566704, - [11] = 8749194, - [12] = 1673, - }, - }, -}; - static void run(void) { int64_t size; @@ -60,7 +35,7 @@ int main(int argc, char **argv) { char description[256]; if (argc < 3) { - fprintf(stderr, "Error: not enough arguments." + fprintf(stderr, "Error: not enough arguments. " "A solver and its options must be given.\n"); return 1; } diff --git a/tools/100_checkdata/checkdata.c b/tools/100_checkdata/checkdata.c @@ -0,0 +1,52 @@ +#include "../tool.h" +#include "../expected_distributions.h" + +char *solver, *options, *filename; + +static void +run(void) { + int64_t size; + char *buf; + FILE *f; + + size = nissy_datasize(solver, options); + + if (size <= 0) { + fprintf(stderr, "Error in datasize\n"); + return; + } + + if ((f = fopen(filename, "rb")) == NULL) { + fprintf(stderr, "Error reading file %s\n", filename); + return; + } + + buf = malloc(size); + fread(buf, size, 1, f); + fclose(f); + nissy_checkdata(solver, options, buf); + free(buf); + + /* TODO: cross-check with expected distributions? */ +} + +int main(int argc, char **argv) { + char description[256]; + + if (argc < 4) { + fprintf(stderr, "Error: not enough arguments. " + "A solver, its options and a file name must be given.\n"); + return 1; + } + + solver = argv[1]; + options = argv[2]; + filename = argv[3]; + sprintf(description, "checking data for solver %s" + "with options %s from file %s", solver, options, filename); + nissy_setlogger(log_stderr); + + timerun(run, description); + + return 0; +} diff --git a/tools/expected_distributions.h b/tools/expected_distributions.h @@ -0,0 +1,25 @@ +uint64_t expected_h48[12][9][21] = { + [0] = { + [2] = { + [0] = 5473562, + [1] = 34776317, + [2] = 68566704, + [3] = 8750867, + }, + [4] = { + [0] = 1, + [1] = 1, + [2] = 4, + [3] = 34, + [4] = 331, + [5] = 3612, + [6] = 41605, + [7] = 474128, + [8] = 4953846, + [9] = 34776317, + [10] = 68566704, + [11] = 8749194, + [12] = 1673, + }, + }, +};