Sudoku Backtracking non abley sudokuJAVA

Программисты JAVA общаются здесь
Anonymous
Sudoku Backtracking non abley sudoku

Сообщение Anonymous »

Я создал решатель Backtracking Sudoku, и он работает очень хорошо,
Но теперь я хочу выдать ошибку, если судоку нельзя решить, потому что он не действителен
, например, если этот судоку дан:

http:/img5.imageShack.us/img5/22241/sudkugurgugrecregbec. />
Что я могу сделать, чтобы мой метод решения выдал ошибку, если он не может быть принят? 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 ;
}

}

//Ruft solve für das nächste Feld auf
public void next( int row, int col ) throws Exception
{
if( col < 8 )
solve( row, col + 1 ) ;
else
solve( row + 1, 0 ) ;
}


Подробнее здесь: https://stackoverflow.com/questions/151 ... lid-sudoku

Вернуться в «JAVA»