diff options
| author | Simon Tatham <anakin@pobox.com> | 2014-09-21 15:33:01 +0000 |
|---|---|---|
| committer | Simon Tatham <anakin@pobox.com> | 2014-09-21 15:33:01 +0000 |
| commit | bc930a121466e0e33b46ff01db0153f5cfb79054 (patch) | |
| tree | 7234a610d57f5147863eaf7572887c29199483a4 /singles.c | |
| parent | ac6fd11ddad3cc52adeeb16a49f71666549fa547 (diff) | |
| download | puzzles-bc930a121466e0e33b46ff01db0153f5cfb79054.zip puzzles-bc930a121466e0e33b46ff01db0153f5cfb79054.tar.gz puzzles-bc930a121466e0e33b46ff01db0153f5cfb79054.tar.bz2 puzzles-bc930a121466e0e33b46ff01db0153f5cfb79054.tar.xz | |
Improve connectedness-error highlighting in Singles.
Using exactly the same policy as I did for Range the other day: if
multiple regions exist, then one is taken to be canonical and all the
others are marked as errors.
[originally from svn r10233]
Diffstat (limited to 'singles.c')
| -rw-r--r-- | singles.c | 32 |
1 files changed, 22 insertions, 10 deletions
@@ -535,16 +535,28 @@ static int check_complete(game_state *state, unsigned flags) for (y = 0; y < h; y++) /* check rows from (0,y) */ error += check_rowcol(state, y*w, 1, w, flags); - /* mark (all) white regions as an error if there is more than one. - * may want to make this less in-your-face (by only marking - * the smallest region as an error, for example -- but what if we - * have two regions of identical size?) */ - for (i = 0; i < state->n; i++) { - if (!(state->flags[i] & F_BLACK) && - dsf_size(dsf, i) < nwhite) { - error += 1; - if (flags & CC_MARK_ERRORS) - state->flags[i] |= F_ERROR; + /* If there's more than one white region, pick the largest one to + * be the canonical one (arbitrarily tie-breaking towards lower + * array indices), and mark all the others as erroneous. */ + { + int largest = 0, canonical = -1; + for (i = 0; i < state->n; i++) + if (!(state->flags[i] & F_BLACK)) { + int size = dsf_size(dsf, i); + if (largest < size) { + largest = size; + canonical = i; + } + } + + if (largest < nwhite) { + for (i = 0; i < state->n; i++) + if (!(state->flags[i] & F_BLACK) && + dsf_canonify(dsf, i) != canonical) { + error += 1; + if (flags & CC_MARK_ERRORS) + state->flags[i] |= F_ERROR; + } } } |