private void digHole() { char ch; int i, j, k, m; for (i = 0; i < 81; i++) { hasTryed[i] = false; } bool flag; for (i = 0; i < 81; i++) { do { m = MWC.random() >> 8 & 127; }while (m >= 81 || hasTryed[m]); hasTryed[m] = true; ch = data[m]; flag = false; for (j = 0; j < 9; j++) { if (ch != map[j]) { for (k = 0; k < 81; k++) { tmp[k] = data[k]; } tmp[m] = map[j]; solver.load(tmp); solver.dfs(0); if (solver.hasResult()) { flag = true; break; } } } if (!flag) { data[m] = '.'; } else { data[m] = ch; } } }
private void randomFill() { int x; MWC.setSeed((int)GetCurrentTimeUnix()); for (int i = 0; i < 81; i++) { data[i] = '.'; } for (int i = 0; i < 9; i++) { do { x = MWC.random() >> 9 & 15; }while (x > 8); data[i * 9 + x] = map[i]; } solver.load(data); solver.dfs(0); }
public void handle(char[] data) { int i, j, k, r, sum; for (i = 0; i < 81; i++) { res[i] = data[i]; } for (i = 0; i < 9; i++) { hintsAtCloumn[i] = 0; for (j = 0; j < 9; j++) { if (data[j * 9 + i] != '.') { hintsAtCloumn[i]++; } } } solver.load(res); solver.dfs(0); sum = 0; for (i = 0; i < 9; i++) { k = 0; for (j = 0; j < 9; j++) { if (data[i * 9 + j] != '.') { k++; } } while (k < LowerBound) { // do r = MWC.random() >> 9 & 15; while(r > 8 || data[i * 9 + r] != '.'); int minColumn = 0, minCells; minCells = 9; for (int m = 0; m < 9; m++) { if (data[i * 9 + m] == '.' && hintsAtCloumn[m] < minCells) { minCells = hintsAtCloumn[m]; minColumn = m; } } data[i * 9 + minColumn] = res[i * 9 + minColumn]; hintsAtCloumn[minColumn]++; k++; } sum += k; } if (sum > Total_UperBound) { isInvalid = true; return; } isInvalid = false; k = random.Next(Total_UperBound - Total); for (; sum < Total + k; sum++) { do { r = MWC.random() >> 8 & 127; } while (r > 80 || data[r] != '.'); data[r] = res[r]; } Debug.Log("" + sum); }