X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?a=blobdiff_plain;f=singles.c;h=5fe054c6638ecdc2fa1a19a09b42742ed09b08f4;hb=a0a581c8b5422bf0c5ed3fde6aa25811e4eb89fc;hp=2aa9a69b7cf82ce8d4a328f218e73811a320fa02;hpb=251b21c41813055d9c416378508b1ee038bc3dac;p=sgt-puzzles.git diff --git a/singles.c b/singles.c index 2aa9a69..5fe054c 100644 --- a/singles.c +++ b/singles.c @@ -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; + } } } @@ -1802,7 +1814,7 @@ static void game_print(drawing *dr, const game_state *state, int tilesize) const struct game thegame = { "Singles", "games.singles", "singles", default_params, - game_fetch_preset, + game_fetch_preset, NULL, decode_params, encode_params, free_params,