Ciao cerco disperatamente aiuto
Sono impegnato in un progetto in java per la risoluzione del sudoku.
Partendo da uno schema con un suggerimento iniziale salvato in un file in formato txt il mio programma java deve riuscire ad aprirlo, analizzarlo e risolverlo. Tramite un ciclo bisogna esplorare tutte le righe, tutte le colonne e tutti i blocchi 3x3, eliminando dalle caselle i numeri che non possono stare in quelle caselle (con un ciclo che esplora i numeri da 1 a 9). Ho iniziato a scrivere qualche riga di codice ma sono totalmente bloccato. Vi riporto qualche riga di codice, mi date una dritta?
import java.io.*;
import javax.swing.*;
class Sudoku {
public static void main(String[] args) throws IOException {
char risposta;
try {
String stringaInput = JOptionPane.showInputDialog("Come si
chiama il file sudoku(file testo)");
File Sudoku = new File(stringaInput);
FileReader FileSudoku = new FileReader(Sudoku);
FileSudoku.close();
}
catch (IOException e)
{ e.printStackTrace();}
}
}
public boolean solve(int[][] initBoard); {
schema = new Cell[9][9];
celleRimanenti= new ArrayList();
ContenutiQuadrato = new Cell[9][9];
int[] ContaQuadrato = new int[9];
for(int x = 0; x < 9; x++) {
for(int y = 0; y < 9; y++) {
Cell c = new Cell(x,y);
schema[x][y] = c;
ContenutiQuadrato[c.inQuadrato][ContaQuadrato[c.inQuadrato]++] = board[x][y];
}
}
for(int x = 0; x < 9; x++) {
for(int y = 0; y < 9; y++) {
if(initBoard[x][y] > 0) {
board[x][y].setValue(initBoard[x][y], 100);
}
else {
celleRimanenti.add(board[x][y]);
}
}
}
Collections.sort(celleRimanenti, comp);
return backtrack(1);
}
public boolean backtrack(int depth) {
if(remainingCells.isEmpty()) { return true; }
if(depth == lastSort + 5 || depth == lastSort - 5) {
Collections.sort(remainingCells, comp);
lastSort = depth;
}
Cell current = (Cell)remainingCells.remove(remainingCells.size()-1);
for(int v = 1; v <= 9; v++) {
if(current.digitRuledOut[v] != 0) continue;
if(current.setValue(v, depth)) {
current.eraseValue(depth);
}
else {
if(backtrack(depth + 1)) return true;
current.eraseValue(depth);
}
}
remainingCells.add(current);
return false;
}