- /* printf("expanding blob of (%d, %d)\n", i % w, i / w); */
-
- j = dsf_canonify(dsf, i);
-
- /* (but only for each connected component) */
- if (i != j) continue;
-
- /* (and not if it's already complete) */
- if (dsf_size(dsf, j) == board[j]) continue;
-
- /* for each square j _in_ the connected component */
- do {
- int k;
- /* printf(" looking at (%d, %d)\n", j % w, j / w); */
-
- /* for each neighbouring square (idx) */
- for (k = 0; k < 4; ++k) {
- const int x = (j % w) + dx[k];
- const int y = (j / w) + dy[k];
- const int idx = w*y + x;
- int size;
- /* int l;
- int nhits = 0;
- int hits[4]; */
- if (x < 0 || x >= w || y < 0 || y >= h) continue;
- if (board[idx] != EMPTY) continue;
- if (exp == idx) continue;
- /* printf("\ttrying to expand onto (%d, %d)\n", x, y); */
-
- /* find out the would-be size of the new connected
- * component if we actually expanded into idx */
- /*
- size = 1;
- for (l = 0; l < 4; ++l) {
- const int lx = x + dx[l];
- const int ly = y + dy[l];
- const int idxl = w*ly + lx;
- int root;
- int m;
- if (lx < 0 || lx >= w || ly < 0 || ly >= h) continue;
- if (board[idxl] != board[j]) continue;
- root = dsf_canonify(dsf, idxl);
- for (m = 0; m < nhits && root != hits[m]; ++m);
- if (m != nhits) continue;
- // printf("\t (%d, %d) contributed %d to size\n", lx, ly, dsf[root] >> 2);
- size += dsf_size(dsf, root);
- assert(dsf_size(dsf, root) >= 1);
- hits[nhits++] = root;
- }
- */
-
- size = expandsize(board, dsf, w, h, idx, board[j]);
-
- /* ... and see if that size is too big, or if we
- * have other expansion candidates. Otherwise
- * remember the (so far) only candidate. */
-
- /* printf("\tthat would give a size of %d\n", size); */
- if (size > board[j]) continue;
- /* printf("\tnow knowing %d expansions\n", nexpand + 1); */
- if (exp != SENTINEL) goto next_i;
- assert(exp != idx);
- exp = idx;
- }