/* * Several cases considered here. * First, note that we don't care about any pattern where * The central square is already clear. * Rules: * 1) If clearing the central square increases the number of set regions, * we cannot thin. * 2) A "tail" is seen when there are two set flags, including the center. * Thinning tails would cause paths to shorten so this is disallowed. * 3) When the cell is surrounded by set cells, it cannot be unset. In this * case un-setting the cell would not change the number of regions but would * break topology. There are several such types: * * a) @@@ b) @@o c) o@o d) o@o * @@@ @@@ @@@ @@@ * @@@ @@@ o@o @@o * * Type a) is trivial, since it is the case where all cells are set. * Type b) includes any case where 8 cells are set. * Type c) is 0 + 2 + 0 * 8 + 16 + 32 * 0 + 128 + 0 = 186 but there are extensions of c) such * as d) which at the time of writing I do not clearly capture with a * single rule. d) has 6 set cells so a trial rule for this might be, * if there are 6 cells or more don't clear (therefore including a,b,c,d) * but there are several patterns we do want to clear, for example: * * o@@ * o@@ * o@@ * */ static bool CanThin(bool[,] p, int code) { Pattern pattern = new Pattern(p); int C = pattern.CountSetCells(); if (C == 2) { //Debug.Log ("Tail found:\n" + pattern); return(false); } if (C >= 6) { //ebug.Log ("6:\n" + pattern); return(false); } //if (C > 6) { // //Debug.Log ("7 or more:\n" + pattern); // return false; //} //ebug.Log ("PATTERN: "+code+"\n"+pattern); int n0 = CountRegions(pattern); pattern.cells [4].value = false; pattern.ClearLabels(); int n1 = CountRegions(pattern); //ebug.Log("region count "+n0+" => "+n1); bool canThin = (n0 == n1); //ebug.Log ("=> " + canThin); return(canThin); }