private void Initialize() { this.Failed = false; for (int x = 0; x < 9; x++) { for (int y = 0; y < 9; y++) { int boxX = (int)Math.Floor(x / 3.0); int boxY = (int)Math.Floor(y / 3.0); int boxIndex = 18 + boxX + (boxY * 3); if (x == 0) { cellsets[y] = new SudokuRow(); } if (y == 0) { cellsets[9 + x] = new SudokuColumn(); } if (null == cellsets[boxIndex]) { cellsets[boxIndex] = new SudokuBox(); } SudokuCell cell = new SudokuCell(x, y); cell.FailedEvent += cell_FailedEvent; cellsets[y].Add(cell); cellsets[9 + x].Add(cell); cellsets[boxIndex].Add(cell); allCells[x, y] = cell; } } }
private void ReduceBySoloBox() { lock (reduceLocker) { List <SudokuCell> checkSet = new List <SudokuCell>(); foreach (int i in Enumerable.Range(1, 9)) { checkSet.Clear(); SudokuBox box = null; bool isUniqueBox = true; foreach (SudokuCell possCell in GetPossibleCellsByValue(i)) { if (possCell.IsSolved) { isUniqueBox = false; break; } if (null == box) { box = possCell.box; } else { if (box != possCell.box) { isUniqueBox = false; break; } } checkSet.Add(possCell); } if (isUniqueBox && checkSet.Count > 1) { lock (setLocker) { // remove these values from other cells in the set checkSet[0].box.RemoveValuesFromSet(i, checkSet); } } } } }