|
/* Program: JSudokuResolver | Class: SudokuResolver
Copyright (C) 2014 Ruggiero Altini
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.ithsoft.sudoku;
import java.io.*;
/**
* <b>Classe</b> JSudokuResolver. <br>
* <p>Questa e' la classe principale del programma. Si occupa di prendere in input la directory di un file,
* di creare un oggetto {@code Board}, un oggetto {@code Solver} e di mandare in outut la soluzione (se c'è ne una).</p>
* Manda inoltre in input tutti i push e i pops utilizzati nello stack per arrivare alla soluzione, utile per vedere
* quanto è complesso il problema.
* @author Ruggiero Altini
* @version 1.0
*/
public class JSudokuResolver
{
/**
* Indica la posizione del Sudoku presa in input
*/
static int[] pos;
/**
* Indica la directory del file di testo da leggere
*/
/**
* La procedura {@code readFile} si occupa di leggere il file da testo preso in input nel {@code main} e di assegnarlo alla variabile pos.
* Per fare cio', legge riga per riga il file, lo spezza in char e li converte in integer, assegnandoli man mano a ogni elemento
* dell'array.
* @since 1.0
*/
private static void readFile()
{
try
{
int count = 0;
while ((line = reader.readLine()) != null) {
char[] cArray = line.toCharArray();
for(char e : cArray)
{
if(e == '-') e = '0';
count++;
}// ...
}
{
System. out. println("File non trovato");
return;
}
{
System. out. println("Errore nella lettura del file");
return;
{
System. out. println("Errore nella lettura del file");
return;
}
}
/**
* La procedura {@code outputLicense} manda un breve accenno alla licenza del programma.
* @since 1.0
*/
public static void outputLicense()
{
System. out. println("\nSudokuResolver Copyright (C) 2014 Ruggiero Altini");
System. out. println("This program comes with ABSOLUTELY NO WARRANTY. ");
System. out. println("This is free software, and you are welcome to redistribute it");
System. out. println("under certain conditions (see GNU GPL v3). \n");
}
/**
* Viene eseguita come prima procedura all'avvio del programma.
* @param args Non utilizzato
* @since 1.0
*/
public static void main (String[] args )
{
outputLicense();
pos = new int[81];
// Hard-coded board
/*int[] pos = {0,6,0,4,0,0,0,0,7,
5,0,0,0,0,0,0,0,1,
0,9,0,0,0,3,0,0,0,
6,0,5,3,2,1,4,8,0,
0,1,0,6,0,7,0,2,0,
0,2,3,5,9,4,1,0,6,
0,0,0,8,0,0,0,3,0,
7,0,0,0,0,0,0,0,5,
1,0,0,0,0,2,0,6,0};*/
System. out. println("Inserisci la directory del file (quit per uscire): ");
try{
filePath = bufferRead.readLine();
if(filePath.equals("quit")) return;
}
{
e.printStackTrace();
}
readFile();
Board b = new Board(pos);
// Dichiara un oggetto di tipo resolver e assegnagli la classe anonima di Board con la posizione caricata
// Il parametro false simboleggia la vmode. Se vero, verrà mandata in output la situazione dello stack in ogni momento
System. out. println("Griglia di partenza");
if(r.Solve())
{ System. out. println("Griglia risolta");
System. out. println("Pushes: " + b. getPushes());
System. out. println("Pops: " + b. getPops());
}else
{
System. out. println("Griglia non risolta");
}
}
}
|
|