aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2023-09-21 22:36:36 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2023-09-21 22:36:36 +0200
commitdb4d88428a1bf20652f11d4cf9b31b7114fdacfb (patch)
treed4594c18e5427033ec44a01dad35252987a06566
parent9c78331ef2ebe2f1dcef886b0043431469bc1a29 (diff)
downloadnissy-classic-db4d88428a1bf20652f11d4cf9b31b7114fdacfb.tar.gz
nissy-classic-db4d88428a1bf20652f11d4cf9b31b7114fdacfb.zip
Added ptable command
-rw-r--r--.gitignore1
-rw-r--r--doc/nissy.17
-rw-r--r--src/commands.c48
-rw-r--r--src/cubetypes.h1
-rw-r--r--src/pruning.c5
5 files changed, 61 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore
index 2ea98c6..8779936 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
1doc/*.html 1doc/*.html
2doc/*.pdf 2doc/*.pdf
3experiments
3nissy 4nissy
4nissy-* 5nissy-*
diff --git a/doc/nissy.1 b/doc/nissy.1
index 138d6ae..c467a2b 100644
--- a/doc/nissy.1
+++ b/doc/nissy.1
@@ -81,6 +81,13 @@ Invert the given scramble.
81Display a text-only description of the cube obtained after applying 81Display a text-only description of the cube obtained after applying
82.Ar scramble . 82.Ar scramble .
83. 83.
84.It Nm ptable Op Ar table
85Display information, such as the table distribution, on a pruning table.
86If no
87.Ar table
88is given, the available pruning tables are listed.
89This command is intended for advanced use only.
90.
84.It Nm quit 91.It Nm quit
85Quit nissy. 92Quit nissy.
86. 93.
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);
6CommandArgs * help_parse_args(int c, char **v); 6CommandArgs * help_parse_args(int c, char **v);
7CommandArgs * parse_only_scramble(int c, char **v); 7CommandArgs * parse_only_scramble(int c, char **v);
8CommandArgs * parse_no_arg(int c, char **v); 8CommandArgs * parse_no_arg(int c, char **v);
9CommandArgs * ptable_parse_args(int c, char **v);
9CommandArgs * solve_parse_args(int c, char **v); 10CommandArgs * solve_parse_args(int c, char **v);
10CommandArgs * scramble_parse_args(int c, char **v); 11CommandArgs * scramble_parse_args(int c, char **v);
11 12
@@ -20,6 +21,7 @@ static void steps_exec(CommandArgs *args);
20static void commands_exec(CommandArgs *args); 21static void commands_exec(CommandArgs *args);
21static void freemem_exec(CommandArgs *args); 22static void freemem_exec(CommandArgs *args);
22static void print_exec(CommandArgs *args); 23static void print_exec(CommandArgs *args);
24static void ptable_exec(CommandArgs *args);
23static void twophase_exec(CommandArgs *args); 25static void twophase_exec(CommandArgs *args);
24static void help_exec(CommandArgs *args); 26static void help_exec(CommandArgs *args);
25static void quit_exec(CommandArgs *args); 27static void quit_exec(CommandArgs *args);
@@ -107,6 +109,15 @@ print_cmd = {
107}; 109};
108 110
109Command 111Command
112ptable_cmd = {
113 .name = "ptable",
114 .usage = "ptable [TABLE]",
115 .description = "Print information on pruning tables",
116 .parse_args = ptable_parse_args,
117 .exec = ptable_exec,
118};
119
120Command
110help_cmd = { 121help_cmd = {
111 .name = "help", 122 .name = "help",
112 .usage = "help [COMMAND]", 123 .usage = "help [COMMAND]",
@@ -167,6 +178,7 @@ Command *commands[] = {
167 &help_cmd, 178 &help_cmd,
168 &invert_cmd, 179 &invert_cmd,
169 &print_cmd, 180 &print_cmd,
181 &ptable_cmd,
170 &quit_cmd, 182 &quit_cmd,
171 &solve_cmd, 183 &solve_cmd,
172 &scramble_cmd, 184 &scramble_cmd,
@@ -384,6 +396,24 @@ parse_no_arg(int c, char **v)
384 return a; 396 return a;
385} 397}
386 398
399CommandArgs *
400ptable_parse_args(int c, char **v)
401{
402 int i;
403 CommandArgs *a = new_args();
404
405 if (c == 1) {
406 for (i = 0; all_pd[i] != NULL; i++)
407 if (!strcmp(v[0], all_pd[i]->filename))
408 a->pd = all_pd[i];
409 if (a->pd == NULL)
410 fprintf(stderr, "%s: pruning table not found\n", v[0]);
411 }
412
413 a->success = c == 0 || (c == 1 && a->pd != NULL);
414 return a;
415}
416
387/* Exec functions implementation *********************************************/ 417/* Exec functions implementation *********************************************/
388 418
389static void 419static void
@@ -584,6 +614,23 @@ print_exec(CommandArgs *args)
584} 614}
585 615
586static void 616static void
617ptable_exec(CommandArgs *args)
618{
619 int i = 0;
620 if (args->pd == NULL) {
621 printf("Available pruning tables:\n");
622 for (i = 0; all_pd[i] != NULL; i++)
623 printf("\t%s\n", all_pd[i]->filename);
624 printf("Use ptable [TABLE] to see the table distribution"
625 " and other information\n");
626 } else {
627 genptable(args->pd, args->opts->nthreads);
628 print_ptable(args->pd);
629 }
630}
631
632
633static void
587twophase_exec(CommandArgs *args) 634twophase_exec(CommandArgs *args)
588{ 635{
589 Cube c; 636 Cube c;
@@ -750,6 +797,7 @@ new_args(void)
750 /* step and command are static */ 797 /* step and command are static */
751 args->step = steps[0]; /* default: first step in list */ 798 args->step = steps[0]; /* default: first step in list */
752 args->command = NULL; 799 args->command = NULL;
800 args->pd = NULL;
753 801
754 return args; 802 return args;
755} 803}
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
162 char scrtype[20]; 162 char scrtype[20];
163 bool scrstdin; 163 bool scrstdin;
164 bool header; 164 bool header;
165 PruneData * pd;
165}; 166};
166 167
167struct 168struct
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)
405 printf("Table %s\n", pd->filename); 405 printf("Table %s\n", pd->filename);
406 printf("Base value: %d\n", pd->base); 406 printf("Base value: %d\n", pd->base);
407 for (i = 0; i < 16; i++) 407 for (i = 0; i < 16; i++)
408 printf("%2" PRIu64 "\t%10" PRIu64 "\n", i, pd->count[i]); 408 if (pd->count[i] != 0)
409 printf("%2" PRIu64 "\t%10" PRIu64 "\n",
410 i, pd->count[i]);
411 printf("Total: %" PRIu64 "\n", pd->coord->max);
409} 412}
410 413
411uint64_t 414uint64_t

Generated with cgit - Back to sebastiano.tronto.net