我正在用Java编写一个用于9x9网格的数独求解器.
我有方法:
打印网格
用给定的值初始化电路板
测试冲突(如果相同的数字在同一行或3x3子网格中)
一种逐个放置数字的方法,这需要最多的工作.
在我详细介绍该方法之前,请记住我必须使用递归来解决它,以及回溯(在这里观看applet作为示例http://www.heimetli.ch/ffh/simplifiedsudoku.html)
此外,我正在通过垂直向下移动来解决这个数独,从左上角开始,到第一列,然后到第二列,等等.
到目前为止,我有以下内容:
public boolean placeNumber(int column){
if (column == SUDOKU_SIZE){ // we have went through all the columns, game is over
return true;
}
else
{
int row=0; //takes you to the top of the row each time
while (row < SUDOKU_SIZE) loops through the column downwards, one by one
{
if (puzzle[row][column]==0){ //skips any entries already in there (the given values)
puzzle[row][column]=1; //starts with one
while(conflictsTest(row,column)){ //conflictsTest is the method …
Run Code Online (Sandbox Code Playgroud)