Hello, I created a Sudoku with a working Backtracking solving method, but i want the method to show if the
given sudoku can be solved or not. if the sudoku can not be solved it always gets into a loop and doesnt get out.
for example if the given sudoku isnt possible to solve because there are already two even numbers in the same row
this is my method:
given sudoku can be solved or not. if the sudoku can not be solved it always gets into a loop and doesnt get out.
for example if the given sudoku isnt possible to solve because there are already two even numbers in the same row
this is my method:
public void solve( int row, int col ) throws Exception
{
// Throw an exception to stop the process if the puzzle is solved
if( row > 8 ){
//Gelöst
}
// If the cell is not empty, continue with the next cell
if( sudo[row][col] != 0 ){
next( row, col ) ;
}
else
{
// Find a valid number for the empty cell
for( int num = 1; num < 10; num++ )
{
if( checkHorizontal(row,num) == false && checkVertikal(col,num)== false&& checkBox(row,col,num)== false )
{
sudo[row][col] = num ;
// Delegate work on the next cell to a resudosive call
next( row, col ) ;
}
}
// No valid number was found, clean up and return to caller
sudo[row][col] = 0 ;
}
}
public void next( int row, int col ) throws Exception
{
if( col < 8 )
solve( row, col + 1 ) ;
else
solve( row + 1, 0 ) ;
}