private boolean solve(int pos){
if (pos == positions){
//we have guessed all positions in the puzzle
return Util.checkSolution(this.puzzle);
}
int row = pos/squares;
int col = pos%squares;
boolean solved = false;
if(!puzzle.fixed(row, col)){
int i = 1;
while(!solved & i <=squares){
// for(int i = 1; i <= squares; i++){
try
{
puzzle.setCellValue(row, col, i);
} catch (FixedCellException e)
{
// TODO Auto-generated catch block
return solve(pos+1);
}
solved = solve(pos+1);
i++;
}
return solved;
}
return solve(pos+1);
}
sorry new to the forum, pardon me if im posting in the wrong place.
im creating a brute forced sudoku solver with recursion
because debugger in my eclipse isnt working, i cant really debug this, and im not really good at tracing by hand. but no matter how i trace it i can find the problem with it. a main method calls this with return solve(0);


Sign In
Create Account

Back to top









