~ubuntu-branches/ubuntu/vivid/sgt-puzzles/vivid

« back to all changes in this revision

Viewing changes to singles.c

  • Committer: Package Import Robot
  • Author(s): Ben Hutchings
  • Date: 2014-10-01 22:10:50 UTC
  • mto: This revision was merged to the branch mainline in revision 21.
  • Revision ID: package-import@ubuntu.com-20141001221050-h63oyzudv90umb3t
Tags: upstream-20140928.r10274
ImportĀ upstreamĀ versionĀ 20140928.r10274

Show diffs side-by-side

added added

removed removed

Lines of Context:
535
535
    for (y = 0; y < h; y++) /* check rows from (0,y) */
536
536
        error += check_rowcol(state, y*w, 1, w, flags);
537
537
 
538
 
    /* mark (all) white regions as an error if there is more than one.
539
 
     * may want to make this less in-your-face (by only marking
540
 
     * the smallest region as an error, for example -- but what if we
541
 
     * have two regions of identical size?) */
542
 
    for (i = 0; i < state->n; i++) {
543
 
        if (!(state->flags[i] & F_BLACK) &&
544
 
            dsf_size(dsf, i) < nwhite) {
545
 
            error += 1;
546
 
            if (flags & CC_MARK_ERRORS)
547
 
                state->flags[i] |= F_ERROR;
 
538
    /* If there's more than one white region, pick the largest one to
 
539
     * be the canonical one (arbitrarily tie-breaking towards lower
 
540
     * array indices), and mark all the others as erroneous. */
 
541
    {
 
542
        int largest = 0, canonical = -1;
 
543
        for (i = 0; i < state->n; i++)
 
544
            if (!(state->flags[i] & F_BLACK)) {
 
545
                int size = dsf_size(dsf, i);
 
546
                if (largest < size) {
 
547
                    largest = size;
 
548
                    canonical = i;
 
549
                }
 
550
            }
 
551
 
 
552
        if (largest < nwhite) {
 
553
            for (i = 0; i < state->n; i++)
 
554
                if (!(state->flags[i] & F_BLACK) &&
 
555
                    dsf_canonify(dsf, i) != canonical) {
 
556
                    error += 1;
 
557
                    if (flags & CC_MARK_ERRORS)
 
558
                        state->flags[i] |= F_ERROR;
 
559
                }
548
560
        }
549
561
    }
550
562