From e6ff0ce6926fa921a13055c9c35d8e60b691e776 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Wed, 11 Sep 2024 17:01:49 +0200 Subject: Finished table refactor --- tools/001_gendata_h48h0k4/gendata_h48h0k4.c | 22 ++++++---------------- tools/002_gendata_h48h0k2/gendata_h48h0k2.c | 21 ++++++--------------- tools/020_solve_small/solve_small.c | 16 +++++++++------- tools/run_tool.sh | 2 +- tools/tool.h | 10 ++++++++++ 5 files changed, 32 insertions(+), 39 deletions(-) (limited to 'tools') diff --git a/tools/001_gendata_h48h0k4/gendata_h48h0k4.c b/tools/001_gendata_h48h0k4/gendata_h48h0k4.c index 0e3deb1..a9993b8 100644 --- a/tools/001_gendata_h48h0k4/gendata_h48h0k4.c +++ b/tools/001_gendata_h48h0k4/gendata_h48h0k4.c @@ -27,8 +27,6 @@ uint32_t expected[21] = { char *buf; void run(void) { - uint32_t *h48info, x; - int i; int64_t s; s = nissy_gendata("h48", OPTIONS, buf); @@ -36,20 +34,12 @@ void run(void) { if (s == -1) { printf("Error generating table\n"); } else { - printf("Table is probably ok\n"); -/* -TODO: adapt to new tables - printf("Succesfully generated %" PRId64 " bytes. Table:\n", s); - h48info = (uint32_t *)buf + 1 + (ETABLESIZE(HVALUE) + COCSEPSIZE) / 4; - for (i = 0; i < MAXDEPTH+1 && h48info[i+1]; i++) { - x = h48info[i+1]; - printf("%d:\t%" PRIu32, i, x); - if (x != expected[i]) - printf(" <--- Error! Expected: %" PRIu32, - expected[i]); - printf("\n"); - } -*/ + nissy_datainfo(buf, write_stdout); + printf("\n"); + printf("Succesfully generated %" PRId64 " bytes. " + "See above for details on the tables.\n", s); + + /* TODO: check that the table is correct */ } } diff --git a/tools/002_gendata_h48h0k2/gendata_h48h0k2.c b/tools/002_gendata_h48h0k2/gendata_h48h0k2.c index 2754f80..271d339 100644 --- a/tools/002_gendata_h48h0k2/gendata_h48h0k2.c +++ b/tools/002_gendata_h48h0k2/gendata_h48h0k2.c @@ -5,9 +5,6 @@ #define OPTIONS "0;2;20" #define LONGOPTIONS "h = 0, k = 2, max depth = 20" -#define COCSEPSIZE 1119792 -#define ETABLESIZE(h) (((3393 * 495 * 70) >> 2) << (size_t)(h)) - uint32_t expected[21] = { /* Base value is 8 */ [0] = 5473562, @@ -19,8 +16,6 @@ uint32_t expected[21] = { char *buf; void run(void) { - uint32_t *h48info, x; - int i; int64_t s; s = nissy_gendata("h48", OPTIONS, buf); @@ -28,16 +23,12 @@ void run(void) { if (s == -1) { printf("Error generating table\n"); } else { - printf("Succesfully generated %" PRId64 " bytes. Table:\n", s); - h48info = (uint32_t *)buf + 1 + (ETABLESIZE(HVALUE) + COCSEPSIZE) / 4; - for (i = 0; i < 4; i++) { - x = h48info[i+1]; - printf("%d:\t%" PRIu32, i, x); - if (x != expected[i]) - printf(" <--- Error! Expected: %" PRIu32, - expected[i]); - printf("\n"); - } + nissy_datainfo(buf, write_stdout); + printf("\n"); + printf("Succesfully generated %" PRId64 " bytes. " + "See above for details on the tables.\n", s); + + /* TODO: check that the table is correct */ } } diff --git a/tools/020_solve_small/solve_small.c b/tools/020_solve_small/solve_small.c index dee2b55..4d07728 100644 --- a/tools/020_solve_small/solve_small.c +++ b/tools/020_solve_small/solve_small.c @@ -20,20 +20,22 @@ void run(void) { printf("Solved the following scrambles:\n\n"); for (i = 0; scrambles[i] != NULL; i++) { - printf("%s\n", scrambles[i]); + printf("%d. %s\n", i+1, scrambles[i]); fprintf(stderr, "Solving scramble %s\n", scrambles[i]); if (nissy_frommoves(scrambles[i], cube) == -1) { - fprintf(stderr, "Invalid scramble, " - "continuing with next scramble\n"); + fprintf(stderr, "Invalid scramble\n"); + printf("Invalid\n"); continue; } n = nissy_solve( cube, "h48", options, "", 0, 20, 1, -1, buf, sol); - if (n == 0) - fprintf(stderr, "No solution found, " - "continuing with next scramble\n"); + if (n == 0) { + printf("No solution\n"); + fprintf(stderr, "No solution found\n"); + } else { + printf("Solutions:\n%s\n", sol); + } } - printf("\n"); } int main(void) { diff --git a/tools/run_tool.sh b/tools/run_tool.sh index 2462b2d..cec7630 100755 --- a/tools/run_tool.sh +++ b/tools/run_tool.sh @@ -16,7 +16,7 @@ for t in tools/*; do fi toolname="$(basename "$t" .c)" $CC -o $BIN $t/*.c $CUBEOBJ || exit 1; - $BIN | tee "tools/results/$toolname-$d.txt" + $BIN | tee "tools/results/$toolname-$d.txt" "tools/results/last.out" break done diff --git a/tools/tool.h b/tools/tool.h index d75342d..7995621 100644 --- a/tools/tool.h +++ b/tools/tool.h @@ -18,6 +18,16 @@ log_stderr(const char *str, ...) va_end(args); } +static void +write_stdout(const char *str, ...) +{ + va_list args; + + va_start(args, str); + vfprintf(stdout, str, args); + va_end(args); +} + static double timerun(void (*run)(void), char *name) { -- cgit v1.3