我有一个课堂作业(已经过去了),我必须写一个数独求解器。我能够创建一种可以解决每个缺失数字的方法。但是我无法创建一种方法来查找我需要解决的单元格。我应该采用二维数组并填写缺失的数字(由 0 表示)。我把我的一些代码放在下面,但不是全部(即使任务已经通过,我尊重教授的意愿)。
public class SolveSudoku {
private static int[][] grid = new int[9][9];
public static int[][] getSolution(int[][] grid) {
for (int i = 0; i < 9; i++) {
System.arraycopy(grid[i], 0, SolveSudoku.grid[i], 0, 9);
}
int n = getZero();
return getSolution(n);
}
private static int[][] getSolution(int n) {
if (n == 0) {
return grid;
}
Cell cell = getZero();
int row = cell.row;
int column = cell.column;
for (int number = 1; number <= 9; number++) {
//checks cell using another method
//I have booleans that return true if the number works
}
return null;
}
private static int getZero() {
return 0;
}
private static class Cell {
int cell = 0;
int row = 0;
int column = 0;
int number;
}
}
我有 getZero 方法,它必须在网格中找到每个零(0 代表一个缺失的数字),这样我就可以解决它。我应该在 getZero 中做什么来找到我需要更换的单元格?