Merge branch 'master' of grond.iut-fbleau.fr:teissier/SAE21_2024
t# the commit.
This commit is contained in:
commit
fcb204cb2c
50
Grid.java
50
Grid.java
@ -9,15 +9,14 @@ import java.io.IOException;
|
||||
*/
|
||||
public class Grid {
|
||||
private Cell[][] cells;
|
||||
public static final int SIZE = 9; // Ajout de la variable SIZE
|
||||
|
||||
/**
|
||||
* Constructeur par défaut qui initialise une grille de Sudoku vide.
|
||||
*/
|
||||
public Grid() {
|
||||
cells = new Cell[SIZE][SIZE]; // Utilisation de la variable SIZE
|
||||
for (int ligne = 0; ligne < SIZE; ligne++) {
|
||||
for (int column = 0; column < SIZE; column++) {
|
||||
cells = new Cell[9][9];
|
||||
for (int ligne = 0; ligne < 9; ligne++) {
|
||||
for (int column = 0; column < 9; column++) {
|
||||
cells[ligne][column] = new Cell();
|
||||
}
|
||||
}
|
||||
@ -25,18 +24,17 @@ public class Grid {
|
||||
|
||||
/**
|
||||
* Charge une grille de Sudoku à partir d'un fichier.
|
||||
*
|
||||
* @param fileName Le nom du fichier à partir duquel charger la grille avec extension ".gri".
|
||||
*/
|
||||
public void loadGridFromFile(String fileName) {
|
||||
try (DataInputStream input = new DataInputStream(new FileInputStream(fileName))) {
|
||||
for (int ligne = 0; ligne < SIZE; ligne++) {
|
||||
for (int ligne = 0; ligne < 9; ligne++) {
|
||||
String line = String.valueOf(input.readInt());
|
||||
int length = line.length();
|
||||
if (length < SIZE) {
|
||||
if (length < 9) {
|
||||
line = "000000000".substring(length) + line; // Ajoute les zéros au début si nécessaire
|
||||
}
|
||||
for (int column = 0; column < SIZE; column++) {
|
||||
for (int column = 0; column < 9; column++) {
|
||||
char number = line.charAt(column);
|
||||
int value = Character.getNumericValue(number);
|
||||
cells[ligne][column].setValue(value);
|
||||
@ -47,17 +45,16 @@ public class Grid {
|
||||
System.err.println("Error: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sauvegarde la grille de Sudoku dans un fichier ".gri".
|
||||
*
|
||||
* @param fileName Le nom du fichier dans lequel sauvegarder la grille.
|
||||
*/
|
||||
public void saveGridToFile(String fileName) {
|
||||
try (DataOutputStream output = new DataOutputStream(new FileOutputStream(fileName))) {
|
||||
for (int ligne = 0; ligne < SIZE; ligne++) {
|
||||
for (int ligne = 0; ligne < 9; ligne++) {
|
||||
StringBuilder line = new StringBuilder();
|
||||
for (int column = 0; column < SIZE; column++) {
|
||||
for (int column = 0; column < 9; column++) {
|
||||
int value = cells[ligne][column].getValue();
|
||||
line.append(value);
|
||||
}
|
||||
@ -71,9 +68,8 @@ public class Grid {
|
||||
|
||||
/**
|
||||
* Obtient la cellule à la position spécifiée dans la grille.
|
||||
*
|
||||
* @param ligne L'indice de ligne de la cellule.
|
||||
* @param col L'indice de colonne de la cellule.
|
||||
* @param col L'indice de colonne de la cellule.
|
||||
* @return La cellule à la position spécifiée.
|
||||
*/
|
||||
public Cell getCell(int ligne, int col) {
|
||||
@ -82,40 +78,22 @@ public class Grid {
|
||||
|
||||
/**
|
||||
* Copie le contenu d'une autre grille dans cette grille.
|
||||
*
|
||||
* @param second_grid La grille à partir de laquelle copier les valeurs.
|
||||
*/
|
||||
public void copyFrom(Grid second_grid) {
|
||||
for (int row = 0; row < SIZE; row++) {
|
||||
for (int col = 0; col < SIZE; col++) {
|
||||
for (int row = 0; row < 9; row++) {
|
||||
for (int col = 0; col < 9; col++) {
|
||||
this.cells[row][col].setValue(second_grid.cells[row][col].getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Vérifie si la grille est complètement remplie.
|
||||
*
|
||||
* @return True si toutes les cellules de la grille sont remplies, False sinon.
|
||||
*/
|
||||
public boolean isFull() {
|
||||
for (int row = 0; row < SIZE; row++) {
|
||||
for (int col = 0; col < SIZE; col++) {
|
||||
if (getCell(row, col).getValue() == 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Affiche la grille de Sudoku dans la console.
|
||||
*/
|
||||
public void printGrid() {
|
||||
for (int row = 0; row < SIZE; row++) {
|
||||
for (int col = 0; col < SIZE; col++) {
|
||||
for (int row = 0; row < 9; row++) {
|
||||
for (int col = 0; col < 9; col++) {
|
||||
System.out.print(cells[row][col].getValue() + " ");
|
||||
}
|
||||
System.out.println();
|
||||
|
5
Makefile
5
Makefile
@ -4,8 +4,7 @@ JC = javac
|
||||
JCFLAGS = -encoding UTF-8 -implicit:none
|
||||
|
||||
JVM = java
|
||||
JVMFLAGS =
|
||||
|
||||
JVMFLAGS =
|
||||
### REGLES ESSENTIELLES ###
|
||||
|
||||
|
||||
@ -21,7 +20,7 @@ SudokuUI.class : SudokuUI.java Sudoku.class Sudoku.class Grid.class Cell.class
|
||||
SudokuButtonListener.class : SudokuButtonListener.java Sudoku.class Grid.class Cell.class
|
||||
${JC} ${JCFLAGS} SudokuButtonListener.java
|
||||
|
||||
Sudoku.class : Sudoku.java Grid.class
|
||||
Sudoku.class : Sudoku.java Grid.class Cell.java
|
||||
${JC} ${JCFLAGS} Sudoku.java
|
||||
|
||||
SudokuSolver.class : SudokuSolver.java Grid.class Cell.java
|
||||
|
Loading…
x
Reference in New Issue
Block a user