fgrid2 = snewn(w*h, float);
memcpy(fgrid2, fgrid, w*h*sizeof(float));
qsort(fgrid2, w*h, sizeof(float), float_compare);
- threshold = fgrid2[w*h/2];
+ /* Choose a threshold that makes half the pixels black. In case of
+ * an odd number of pixels, select randomly between just under and
+ * just over half. */
+ {
+ int index = w * h / 2;
+ if (w & h & 1)
+ index += random_upto(rs, 2);
+ if (index < w*h)
+ threshold = fgrid2[index];
+ else
+ threshold = fgrid2[w*h-1] + 1;
+ }
sfree(fgrid2);
for (i = 0; i < h; i++) {
if (rowlen == 0) {
memset(deduced, DOT, len);
+ } else if (rowlen == 1 && data[0] == len) {
+ memset(deduced, BLOCK, len);
} else {
do_recurse(known, deduced, row, minpos_done, maxpos_done, minpos_ok,
maxpos_ok, data, len, freespace, 0, 0);
const struct game thegame = {
"Pattern", "games.pattern", "pattern",
default_params,
- game_fetch_preset,
+ game_fetch_preset, NULL,
decode_params,
encode_params,
free_params,