public static SudokuModel SolveCell(CellModel cellmodel, SudokuModel sudokumodel) { var row = sudokumodel.Sudoku[cellmodel.row]; List <CellModel> columns = new List <CellModel>(); for (int i = 0; i < 9; i++) { columns.Add(DeepCloning.DeepCloner(sudokumodel.Sudoku[i][cellmodel.column])); } List <CellModel> square = new List <CellModel>(); for (int x = 0; x < 9; x++) { List <CellModel> squarerow = sudokumodel.Sudoku[x].Where(a => a.square == cellmodel.square).ToList(); square.AddRange(DeepCloning.DeepCloner(squarerow)); } for (int ab = 1; ab < 10; ab++) { if (row.Where(a => a.value == ab).Any()) { continue; } if (columns.Where(a => a.value == ab).Any()) { continue; } if (square.Where(a => a.value == ab).Any()) { continue; } sudokumodel.Sudoku[cellmodel.row][cellmodel.column].value = ab; } if (sudokumodel.Sudoku[cellmodel.row][cellmodel.column].value == 0) { sudokumodel.FaultyBoard = true; } return(sudokumodel); }
public static CellModel CountOptionsCellHierarchical(CellModel cellmodel, SudokuModel sudokumodel) { var row = sudokumodel.Sudoku[cellmodel.row]; List <CellModel> columns = new List <CellModel>(); for (int i = 0; i < 9; i++) { columns.Add(DeepCloning.DeepCloner(sudokumodel.Sudoku[i][cellmodel.column])); } List <CellModel> square = new List <CellModel>(); for (int x = 0; x < 9; x++) { List <CellModel> squarerow = sudokumodel.Sudoku[x].Where(a => a.square == cellmodel.square).ToList(); square.AddRange(DeepCloning.DeepCloner(squarerow)); } for (int ab = 1; ab < 10; ab++) { if (row.Where(a => a.value == ab).Any()) { continue; } if (columns.Where(a => a.value == ab).Any()) { continue; } if (square.Where(a => a.value == ab).Any()) { continue; } cellmodel.amountofoptions++; } //if (sudokumodel.Sudoku[cellmodel.row][cellmodel.column].value == 0) //{ // sudokumodel.FaultyBoard = true; //} return(cellmodel); }