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.)
This commit is contained in:
Simon Tatham
2023-01-22 08:54:06 +00:00
parent 806ae71ca4
commit 5cac6a09c4

View File

@ -192,6 +192,8 @@ static const char *validate_params(const game_params *params, bool full)
* 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)