public static bool ValidateCol(int?[,] grid, int col, bool allowNull = false, bool ignoreBlock = false, int?allowedRow = null) { Log.Add("Validating Col " + col, Importance.NotImportant); NumberTracker tracker = new NumberTracker(); for (int i = 0; i < Sudoku.Cols; i++) { if (ignoreBlock) { int blockStart = (int)(col / 3) * 3; int blockEnd = blockStart + 3; if (i != allowedRow && i < blockEnd && i > blockStart) { continue; } } if (allowNull) { if (grid[col, i] == null) { continue; } } tracker.addValue(grid[col, i], i); if (!tracker.IsValid) { return(false); } } return(true); }
public static bool ValidateGroup(int?[,] grid, int row, int col, bool allowNull = false) { Log.Add("Validating Group " + row + ":" + col, Importance.NotImportant); int groupStartX, groupStartY = 0; groupStartX = (row / 3) * 3; groupStartY = (col / 3) * 3; NumberTracker tracker = new NumberTracker(); for (int i = groupStartX; i < groupStartX + 3; i++) { for (int j = groupStartY; j < groupStartY + 3; j++) { if (allowNull) { if (grid[i, j] == null) { continue; } } int index = (i * 3) + j; tracker.addValue(grid[i, j], index); if (!tracker.IsValid) { return(false); } } } return(true); }