summaryrefslogtreecommitdiff
path: root/19.c
diff options
context:
space:
mode:
authorAdam Spragg <adam@spra.gg>2023-01-29 16:03:37 +0000
committerAdam Spragg <adam@spra.gg>2023-01-30 19:07:53 +0000
commitb43bdf75540c9daab5c94317bf910d0eba3755ab (patch)
tree8aa9db06e82a3e3981eb6468d4c365bf73326b63 /19.c
parent0fcf120446f29f4715a422744ad70eb06247c500 (diff)
Puzzle 19: Add option for debug output
Diffstat (limited to '19.c')
-rw-r--r--19.c40
1 files 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) {