From b43bdf75540c9daab5c94317bf910d0eba3755ab Mon Sep 17 00:00:00 2001 From: Adam Spragg Date: Sun, 29 Jan 2023 16:03:37 +0000 Subject: Puzzle 19: Add option for debug output --- 19.c | 40 ++++++++++++++-------------------------- 1 file changed, 14 insertions(+), 26 deletions(-) diff --git a/19.c b/19.c index 0f13c0c..f44f46c 100644 --- a/19.c +++ b/19.c @@ -203,20 +203,10 @@ inventory_build_basic(struct inventory * i, struct blueprint const * b, int rema ; inventory_tick(i); - - fprintf(stderr, "Blueprint %d tick %d, ore: %d/%d, clay %d/%d, bsdn %d/%d, geod %d/%d\n", - b->id, t + 1, - i->ore.amount, i->ore.robots, - i->clay.amount, i->clay.robots, - i->bsdn.amount, i->bsdn.robots, - i->geod.amount, i->geod.robots); } } -long exhaustive_iter; - - // Exhastive(ish) build strategy // // Try all^Wmost combinations of building different robots at different times @@ -251,8 +241,6 @@ inventory_build_exhaustive(struct inventory * i, struct blueprint const * b, int // No time to do anything! return; - ++exhaustive_iter; - best = *i; test = *i; @@ -331,15 +319,19 @@ inventory_build_exhaustive(struct inventory * i, struct blueprint const * b, int int main(int argc, char ** argv) { - int rounds = 24; + int debug = 0, rounds = 24; char const * build = "exhaustive", * output = "quality"; int quality = 0, i; long product = 1; regex_t reblueprint; char buf[BUFSIZ]; - while ((i = getopt(argc, argv, "p:b:o:r:")) != -1) { + while ((i = getopt(argc, argv, "dp:b:o:r:")) != -1) { switch (i) { + case 'd': + debug = 1; + break; + case 'p': switch (atoi(optarg)) { case 1: @@ -411,16 +403,7 @@ main(int argc, char ** argv) inventory_build_basic(&i, &b, rounds); } else if (strcmp(build, "exhaustive") == 0) { - exhaustive_iter = 0; inventory_build_exhaustive(&i, &b, rounds); -#if 0 - fprintf(stderr, "Blueprint %d, iterations %ld, ore %d/%d, clay %d/%d, bsdn %d/%d, geod %d/%d\n", - b.id, exhaustive_iter, - i.ore.amount, i.ore.robots, - i.clay.amount, i.clay.robots, - i.bsdn.amount, i.bsdn.robots, - i.geod.amount, i.geod.robots); -#endif } else { fprintf(stderr, "Unknown build strategy: %s\n", build); @@ -430,9 +413,14 @@ main(int argc, char ** argv) quality += b.id * i.geod.amount; product *= i.geod.amount; -#if 0 - fprintf(stderr, "Blueprint %d geodes = %d\n", b.id, i.geod.amount); -#endif + + if (debug) + fprintf(stderr, "Blueprint %d, ore %d/%d, clay %d/%d, bsdn %d/%d, geod %d/%d\n", + b.id, + i.ore.robots, i.ore.amount, + i.clay.robots, i.clay.amount, + i.bsdn.robots, i.bsdn.amount, + i.geod.robots, i.geod.amount); } if (strcmp(output, "quality") == 0) { -- cgit v1.2.1