diff options
| author | Franklin Wei <git@fwei.tk> | 2017-09-30 17:47:13 -0400 |
|---|---|---|
| committer | Franklin Wei <git@fwei.tk> | 2017-09-30 20:06:50 -0400 |
| commit | b9386109e8f0cf346037b72464577fe19bba2d43 (patch) | |
| tree | f0c15f6c80043376ec94d23cb1b681324eb3df3d /apps/plugins/puzzles/src/pattern.c | |
| parent | ea679de8371e4e74fe4e78fb8df8e5df19efffdc (diff) | |
| download | rockbox-b9386109e8f0cf346037b72464577fe19bba2d43.zip rockbox-b9386109e8f0cf346037b72464577fe19bba2d43.tar.gz rockbox-b9386109e8f0cf346037b72464577fe19bba2d43.tar.bz2 rockbox-b9386109e8f0cf346037b72464577fe19bba2d43.tar.xz | |
puzzles: resync with upstream
This brings puzzles to upstream commit 84d3fd2.
Change-Id: I808a197f868032d771fc101a15666c5ec4b9f94b
Diffstat (limited to 'apps/plugins/puzzles/src/pattern.c')
| -rw-r--r-- | apps/plugins/puzzles/src/pattern.c | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/apps/plugins/puzzles/src/pattern.c b/apps/plugins/puzzles/src/pattern.c index 15cdd28..270b558 100644 --- a/apps/plugins/puzzles/src/pattern.c +++ b/apps/plugins/puzzles/src/pattern.c @@ -310,7 +310,18 @@ static void generate(random_state *rs, int w, int h, unsigned char *retgrid) 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++) { @@ -448,6 +459,8 @@ static int do_row(unsigned char *known, unsigned char *deduced, 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); |