From db4d88428a1bf20652f11d4cf9b31b7114fdacfb Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Thu, 21 Sep 2023 22:36:36 +0200 Subject: Added ptable command --- src/commands.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ src/cubetypes.h | 1 + src/pruning.c | 5 ++++- 3 files changed, 53 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/commands.c b/src/commands.c index 78d7583..f01edfd 100644 --- a/src/commands.c +++ b/src/commands.c @@ -6,6 +6,7 @@ CommandArgs * gen_parse_args(int c, char **v); CommandArgs * help_parse_args(int c, char **v); CommandArgs * parse_only_scramble(int c, char **v); CommandArgs * parse_no_arg(int c, char **v); +CommandArgs * ptable_parse_args(int c, char **v); CommandArgs * solve_parse_args(int c, char **v); CommandArgs * scramble_parse_args(int c, char **v); @@ -20,6 +21,7 @@ static void steps_exec(CommandArgs *args); static void commands_exec(CommandArgs *args); static void freemem_exec(CommandArgs *args); static void print_exec(CommandArgs *args); +static void ptable_exec(CommandArgs *args); static void twophase_exec(CommandArgs *args); static void help_exec(CommandArgs *args); static void quit_exec(CommandArgs *args); @@ -106,6 +108,15 @@ print_cmd = { .exec = print_exec, }; +Command +ptable_cmd = { + .name = "ptable", + .usage = "ptable [TABLE]", + .description = "Print information on pruning tables", + .parse_args = ptable_parse_args, + .exec = ptable_exec, +}; + Command help_cmd = { .name = "help", @@ -167,6 +178,7 @@ Command *commands[] = { &help_cmd, &invert_cmd, &print_cmd, + &ptable_cmd, &quit_cmd, &solve_cmd, &scramble_cmd, @@ -384,6 +396,24 @@ parse_no_arg(int c, char **v) return a; } +CommandArgs * +ptable_parse_args(int c, char **v) +{ + int i; + CommandArgs *a = new_args(); + + if (c == 1) { + for (i = 0; all_pd[i] != NULL; i++) + if (!strcmp(v[0], all_pd[i]->filename)) + a->pd = all_pd[i]; + if (a->pd == NULL) + fprintf(stderr, "%s: pruning table not found\n", v[0]); + } + + a->success = c == 0 || (c == 1 && a->pd != NULL); + return a; +} + /* Exec functions implementation *********************************************/ static void @@ -583,6 +613,23 @@ print_exec(CommandArgs *args) print_cube(apply_alg(args->scramble, (Cube){0})); } +static void +ptable_exec(CommandArgs *args) +{ + int i = 0; + if (args->pd == NULL) { + printf("Available pruning tables:\n"); + for (i = 0; all_pd[i] != NULL; i++) + printf("\t%s\n", all_pd[i]->filename); + printf("Use ptable [TABLE] to see the table distribution" + " and other information\n"); + } else { + genptable(args->pd, args->opts->nthreads); + print_ptable(args->pd); + } +} + + static void twophase_exec(CommandArgs *args) { @@ -750,6 +797,7 @@ new_args(void) /* step and command are static */ args->step = steps[0]; /* default: first step in list */ args->command = NULL; + args->pd = NULL; return args; } diff --git a/src/cubetypes.h b/src/cubetypes.h index ad9c627..66839ca 100644 --- a/src/cubetypes.h +++ b/src/cubetypes.h @@ -162,6 +162,7 @@ commandargs char scrtype[20]; bool scrstdin; bool header; + PruneData * pd; }; struct diff --git a/src/pruning.c b/src/pruning.c index aeeac21..fcb27e5 100644 --- a/src/pruning.c +++ b/src/pruning.c @@ -405,7 +405,10 @@ print_ptable(PruneData *pd) printf("Table %s\n", pd->filename); printf("Base value: %d\n", pd->base); for (i = 0; i < 16; i++) - printf("%2" PRIu64 "\t%10" PRIu64 "\n", i, pd->count[i]); + if (pd->count[i] != 0) + printf("%2" PRIu64 "\t%10" PRIu64 "\n", + i, pd->count[i]); + printf("Total: %" PRIu64 "\n", pd->coord->max); } uint64_t -- cgit v1.3