shithub: puzzles

Download patch

ref: 5cac6a09c4db2b7e05c3e8dfd8920e2cdd1b8b03
parent: 806ae71ca45f913ebfd4aa18c8f0c80a67738a13
author: Simon Tatham <[email protected]>
date: Sun Jan 22 03:54:06 EST 2023

Black Box: reject negative ball counts in game_params.

You can inject one via a game desc string such as "10x10M5m-1", and
it's clearly silly.

_Zero_ balls, on the other hand, are a perfectly fine number: there's
nothing incoherent about a BB puzzle in which the possible numbers of
balls vary from (say) 0 to 5 inclusive, so that part of the challenge
is to work out as efficiently as possible whether there are even any
balls at all.

(We only need to check minballs, because once we know minballs >= 0,
the subsequent check ensures that maxballs >= minballs, and hence, by
transitivity, maxballs >= 0 too.)

--- a/blackbox.c
+++ b/blackbox.c
@@ -192,6 +192,8 @@
      * types, and could be worked around if required. */
     if (params->w > 255 || params->h > 255)
         return "Widths and heights greater than 255 are not supported";
+    if (params->minballs < 0)
+        return "Negative number of balls";
     if (params->minballs > params->maxballs)
         return "Minimum number of balls may not be greater than maximum";
     if (params->minballs >= params->w * params->h)