feat: resolver backtrace simple
This commit is contained in:
6
.idea/compiler.xml
generated
Normal file
6
.idea/compiler.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<bytecodeTargetLevel target="21" />
|
||||
</component>
|
||||
</project>
|
||||
16
.idea/gradle.xml
generated
Normal file
16
.idea/gradle.xml
generated
Normal file
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="GradleSettings">
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
<option value="$PROJECT_DIR$/app" />
|
||||
</set>
|
||||
</option>
|
||||
</GradleProjectSettings>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
||||
5
.idea/misc.xml
generated
Normal file
5
.idea/misc.xml
generated
Normal file
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="21" project-jdk-type="JavaSDK" />
|
||||
</project>
|
||||
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
88
.idea/workspace.xml
generated
Normal file
88
.idea/workspace.xml
generated
Normal file
@@ -0,0 +1,88 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="AutoImportSettings">
|
||||
<option name="autoReloadType" value="SELECTIVE" />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="78fccc4f-112b-4fb4-8f59-c375aeac8595" name="Changes" comment="">
|
||||
<change beforePath="$PROJECT_DIR$/app/src/main/java/sudoku/Symbole.java" beforeDir="false" afterPath="$PROJECT_DIR$/app/src/main/java/sudoku/Symbole.java" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||
<option name="LAST_RESOLUTION" value="IGNORE" />
|
||||
</component>
|
||||
<component name="ExternalProjectsData">
|
||||
<projectState path="$PROJECT_DIR$">
|
||||
<ProjectState />
|
||||
</projectState>
|
||||
</component>
|
||||
<component name="Git.Settings">
|
||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
||||
</component>
|
||||
<component name="ProjectColorInfo"><![CDATA[{
|
||||
"associatedIndex": 6
|
||||
}]]></component>
|
||||
<component name="ProjectId" id="2rwHskpjH0QskAu0G8vmtPc1Ozz" />
|
||||
<component name="ProjectViewState">
|
||||
<option name="hideEmptyMiddlePackages" value="true" />
|
||||
<option name="showLibraryContents" value="true" />
|
||||
</component>
|
||||
<component name="PropertiesComponent"><![CDATA[{
|
||||
"keyToString": {
|
||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||
"RunOnceActivity.git.unshallow": "true",
|
||||
"git-widget-placeholder": "feature/solveur",
|
||||
"kotlin-language-version-configured": "true",
|
||||
"last_opened_file_path": "/usr/lib/jvm/java-21-openjdk",
|
||||
"node.js.detected.package.eslint": "true",
|
||||
"node.js.detected.package.tslint": "true",
|
||||
"node.js.selected.package.eslint": "(autodetect)",
|
||||
"node.js.selected.package.tslint": "(autodetect)",
|
||||
"nodejs_package_manager_path": "npm",
|
||||
"project.structure.last.edited": "Project",
|
||||
"project.structure.proportion": "0.0",
|
||||
"project.structure.side.proportion": "0.0",
|
||||
"settings.editor.selected.configurable": "reference.projectsettings.compiler.javacompiler",
|
||||
"vue.rearranger.settings.migration": "true"
|
||||
}
|
||||
}]]></component>
|
||||
<component name="RunManager">
|
||||
<configuration default="true" type="JetRunConfigurationType">
|
||||
<method v="2">
|
||||
<option name="Make" enabled="true" />
|
||||
</method>
|
||||
</configuration>
|
||||
<configuration default="true" type="KotlinStandaloneScriptRunConfigurationType">
|
||||
<option name="filePath" />
|
||||
<method v="2" />
|
||||
</configuration>
|
||||
</component>
|
||||
<component name="SharedIndexes">
|
||||
<attachedChunks>
|
||||
<set>
|
||||
<option value="bundled-jdk-9823dce3aa75-125ca727e0f0-intellij.indexing.shared.core-IU-243.23654.117" />
|
||||
<option value="bundled-js-predefined-d6986cc7102b-822845ee3bb5-JavaScript-IU-243.23654.117" />
|
||||
</set>
|
||||
</attachedChunks>
|
||||
</component>
|
||||
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
|
||||
<component name="TaskManager">
|
||||
<task active="true" id="Default" summary="Default task">
|
||||
<changelist id="78fccc4f-112b-4fb4-8f59-c375aeac8595" name="Changes" comment="" />
|
||||
<created>1737463425999</created>
|
||||
<option name="number" value="Default" />
|
||||
<option name="presentableId" value="Default" />
|
||||
<updated>1737463425999</updated>
|
||||
<workItem from="1737463427147" duration="1086000" />
|
||||
</task>
|
||||
<servers />
|
||||
</component>
|
||||
<component name="TypeScriptGeneratedFilesManager">
|
||||
<option name="version" value="3" />
|
||||
</component>
|
||||
<component name="XSLT-Support.FileAssociations.UIState">
|
||||
<expand />
|
||||
<select />
|
||||
</component>
|
||||
</project>
|
||||
@@ -1,7 +1,5 @@
|
||||
package sudoku;
|
||||
|
||||
import sudoku.core.Console;
|
||||
|
||||
public class ContrainteBloc implements Contrainte {
|
||||
@Override
|
||||
public boolean estRespectee(Grille grille, Case c) {
|
||||
@@ -14,7 +12,6 @@ public class ContrainteBloc implements Contrainte {
|
||||
for (int j = 0; j < blocSize; j++) {
|
||||
Case currentCase = grille.getCase(startRow + i, startCol + j);
|
||||
if (currentCase != c && currentCase.getSymbole() != null && currentCase.getSymbole().equals(symbole)) {
|
||||
Console.errorln("La contrainte de bloc n'est pas respectee: ligne=" + (startRow + i) + ", col=" + (startCol + j) + ", symbole=" + symbole);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package sudoku;
|
||||
|
||||
import sudoku.core.Console;
|
||||
|
||||
public class ContrainteColonne implements Contrainte {
|
||||
@Override
|
||||
public boolean estRespectee(Grille grille, Case c) {
|
||||
@@ -10,7 +8,6 @@ public class ContrainteColonne implements Contrainte {
|
||||
for (int ligne = 0; ligne < grille.getTaille(); ligne++) {
|
||||
Case currentCase = grille.getCase(ligne, colonne);
|
||||
if (currentCase != c && currentCase.getSymbole() != null && currentCase.getSymbole().equals(symbole)) {
|
||||
Console.errorln("La contrainte de colonne n'est pas respectee: ligne=" + ligne + ", col=" + colonne + ", symbole=" + symbole);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package sudoku;
|
||||
|
||||
import sudoku.core.Console;
|
||||
|
||||
public class ContrainteLigne implements Contrainte {
|
||||
@Override
|
||||
public boolean estRespectee(Grille grille, Case c) {
|
||||
@@ -10,7 +8,6 @@ public class ContrainteLigne implements Contrainte {
|
||||
for (int col = 0; col < grille.getTaille(); col++) {
|
||||
Case currentCase = grille.getCase(ligne, col);
|
||||
if (currentCase != c && currentCase.getSymbole() != null && currentCase.getSymbole().equals(symbole)) {
|
||||
Console.errorln("La contrainte de ligne n'est pas respectee: ligne=" + ligne + ", col=" + col + ", symbole=" + symbole);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,12 +11,14 @@ public class Grille {
|
||||
private final Case[][] cases;
|
||||
private final ArrayList<Bloc> blocs;
|
||||
private ArrayList<Symbole> symbolesPossibles;
|
||||
private final Sudoku sudoku;
|
||||
|
||||
public Grille(int taille) {
|
||||
public Grille(int taille, Sudoku sudoku) {
|
||||
this.taille = taille;
|
||||
this.cases = new Case[taille][taille];
|
||||
this.blocs = new ArrayList<>();
|
||||
this.symbolesPossibles = new ArrayList<>();
|
||||
this.sudoku = sudoku;
|
||||
|
||||
// Initialiser les cases
|
||||
for (int i = 0; i < taille; i++) {
|
||||
@@ -31,11 +33,22 @@ public class Grille {
|
||||
if (symbole != null && !symbolesPossibles.contains(symbole)) {
|
||||
throw new IllegalArgumentException("Symbole non autorisé : " + symbole);
|
||||
}
|
||||
// Save ancien symbole
|
||||
Symbole ancienSymbole = cases[ligne][colonne].getSymbole();
|
||||
|
||||
// Set nouveau symbole
|
||||
cases[ligne][colonne].setSymbole(symbole);
|
||||
|
||||
// Vérifier les contraintes
|
||||
if (!sudoku.verifierToutesContraintes()) {
|
||||
// Revert to ancien symbole
|
||||
cases[ligne][colonne].setSymbole(ancienSymbole);
|
||||
throw new IllegalArgumentException("SET CASE: Les contraintes ne sont pas respectées pour la case ("
|
||||
+ ligne + ", " + colonne + ")");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Console.errorln(e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Case getCase(int ligne, int colonne) {
|
||||
@@ -49,9 +62,10 @@ public class Grille {
|
||||
"\u001B[33m" // Jaune
|
||||
};
|
||||
|
||||
private int getCouleurDisponible(int blocRow, int blocCol) {
|
||||
private int getCouleurDisponible(int blocRow, int blocCol, int blocHeight, int blocWidth) {
|
||||
List<Integer> couleursUtilisees = new ArrayList<>();
|
||||
int blocSize = (int) Math.sqrt(taille);
|
||||
int blocsParLigne = taille / blocWidth;
|
||||
int blocsParColonne = taille / blocHeight;
|
||||
|
||||
// Parcourir les voisins (haut, bas, gauche, droite, et diagonaux)
|
||||
for (int dRow = -1; dRow <= 1; dRow++) {
|
||||
@@ -63,9 +77,9 @@ public class Grille {
|
||||
int voisinCol = blocCol + dCol;
|
||||
|
||||
// Vérifier si le voisin est dans les limites
|
||||
if (voisinRow >= 0 && voisinRow < taille / blocSize &&
|
||||
voisinCol >= 0 && voisinCol < taille / blocSize) {
|
||||
int blockIndex = voisinRow * (taille / blocSize) + voisinCol;
|
||||
if (voisinRow >= 0 && voisinRow < blocsParColonne &&
|
||||
voisinCol >= 0 && voisinCol < blocsParLigne) {
|
||||
int blockIndex = voisinRow * blocsParLigne + voisinCol;
|
||||
if (blockIndex < blocs.size()) {
|
||||
couleursUtilisees.add(blocs.get(blockIndex).getCouleurIndex());
|
||||
}
|
||||
@@ -102,19 +116,7 @@ public class Grille {
|
||||
* @param positions
|
||||
* @return
|
||||
*/
|
||||
public Bloc creerBloc(List<int[]> positions) {
|
||||
int i = positions.get(0)[0];
|
||||
int j = positions.get(0)[1];
|
||||
int blocSize = (int) Math.sqrt(taille);
|
||||
int couleurIndex = getCouleurDisponible(i / blocSize, j / blocSize);
|
||||
|
||||
Bloc bloc = new Bloc(QUATRE_COULEURS[couleurIndex], couleurIndex);
|
||||
for (int[] pos : positions) {
|
||||
bloc.ajouterCase(cases[pos[0]][pos[1]]);
|
||||
}
|
||||
blocs.add(bloc);
|
||||
return bloc;
|
||||
}
|
||||
// TODO : Refactor to use BlocBuilder
|
||||
|
||||
public void creerBlocCarre() {
|
||||
try {
|
||||
@@ -138,7 +140,55 @@ public class Grille {
|
||||
}
|
||||
}
|
||||
|
||||
int couleurIndex = getCouleurDisponible(blocRow, blocCol);
|
||||
int couleurIndex = getCouleurDisponible(blocRow, blocCol, blocSize, blocSize);
|
||||
Bloc bloc = new Bloc(QUATRE_COULEURS[couleurIndex], couleurIndex);
|
||||
|
||||
for (int[] pos : positions) {
|
||||
bloc.ajouterCase(cases[pos[0]][pos[1]]);
|
||||
}
|
||||
blocs.add(bloc);
|
||||
}
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
Console.errorln(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Crée des blocs rectangles automatiquement à partir de la taille de la grille
|
||||
* Ne fonctionne pas pour les tailles de grilles qui sont des carrés parfaits
|
||||
*
|
||||
* @param blocRow
|
||||
* @param blocCol
|
||||
* @param blocHeight
|
||||
* @param blocWidth
|
||||
*/
|
||||
public void creerBlocRectangulaire(int blocHeight, int blocWidth) {
|
||||
try {
|
||||
if (taille % blocHeight != 0 || taille % blocWidth != 0) {
|
||||
throw new IllegalArgumentException(
|
||||
"La taille de la grille doit être divisible par les dimensions des blocs.");
|
||||
}
|
||||
|
||||
int blocsParLigne = taille / blocWidth;
|
||||
int blocsParColonne = taille / blocHeight;
|
||||
|
||||
// Create blocks in rectangular pattern
|
||||
for (int blocRow = 0; blocRow < blocsParColonne; blocRow++) {
|
||||
for (int blocCol = 0; blocCol < blocsParLigne; blocCol++) {
|
||||
List<int[]> positions = new ArrayList<>();
|
||||
|
||||
// Add all positions for current block
|
||||
for (int i = 0; i < blocHeight; i++) {
|
||||
for (int j = 0; j < blocWidth; j++) {
|
||||
positions.add(new int[] {
|
||||
blocRow * blocHeight + i,
|
||||
blocCol * blocWidth + j
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
int couleurIndex = getCouleurDisponible(blocRow, blocCol, blocHeight, blocWidth);
|
||||
Bloc bloc = new Bloc(QUATRE_COULEURS[couleurIndex], couleurIndex);
|
||||
|
||||
for (int[] pos : positions) {
|
||||
@@ -266,6 +316,7 @@ public class Grille {
|
||||
/**
|
||||
* Vérifie si toutes les contraintes sont respectées
|
||||
* S'arrête dès qu'une contrainte n'est pas respectée
|
||||
*
|
||||
* @param contraintes
|
||||
* @return
|
||||
*/
|
||||
@@ -279,7 +330,8 @@ public class Grille {
|
||||
// Vérifier toutes les contraintes pour cette case
|
||||
for (Contrainte contrainte : contraintes) {
|
||||
if (!contrainte.estRespectee(this, currentCase)) {
|
||||
Console.errorln("Contrainte non respectée à la position : ligne=" + i + ", colonne=" + j);
|
||||
Console.errorln(
|
||||
"GRILLE: Contrainte non respectée à la position : ligne=" + i + ", colonne=" + j);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -289,7 +341,52 @@ public class Grille {
|
||||
return true;
|
||||
}
|
||||
|
||||
public Case getCaseLibre() {
|
||||
for (int i = 0; i < taille; i++) {
|
||||
for (int j = 0; j < taille; j++) {
|
||||
if (cases[i][j].getSymbole() == null) {
|
||||
return cases[i][j];
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getLongueurSymboleLePlusLong() {
|
||||
int max = 0;
|
||||
for (Symbole symbole : symbolesPossibles) {
|
||||
if (symbole.toString().length() > max) {
|
||||
max = symbole.toString().length();
|
||||
}
|
||||
}
|
||||
return max;
|
||||
}
|
||||
|
||||
@Override
|
||||
// public String toString() {
|
||||
// StringBuilder sb = new StringBuilder();
|
||||
// int plusLongSymbole = this.getLongueurSymboleLePlusLong();
|
||||
|
||||
// for (int i = 0; i < taille; i++) {
|
||||
// for (int j = 0; j < taille; j++) {
|
||||
// Case currentCase = cases[i][j];
|
||||
// Bloc bloc = findBlocForCase(currentCase);
|
||||
|
||||
// if (bloc != null) {
|
||||
// sb.append(bloc.getCouleur()) // Couleur du bloc
|
||||
// .append(" ".repeat(plusLongSymbole - currentCase.toString().length())) // Alignement
|
||||
// .append(currentCase.toString())
|
||||
// .append("\u001B[0m ") // Réinitialiser la couleur
|
||||
// .append(" ");
|
||||
// } else {
|
||||
// sb.append(currentCase.toString()).append(" ");
|
||||
// }
|
||||
// }
|
||||
// sb.append("\n");
|
||||
// }
|
||||
|
||||
// return sb.toString();
|
||||
// }
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
|
||||
5
app/src/main/java/sudoku/Resolveur.java
Normal file
5
app/src/main/java/sudoku/Resolveur.java
Normal file
@@ -0,0 +1,5 @@
|
||||
package sudoku;
|
||||
|
||||
public interface Resolveur {
|
||||
boolean resoudre(Sudoku s, boolean afficherEtape);
|
||||
}
|
||||
62
app/src/main/java/sudoku/ResolveurBacktraceSimple.java
Normal file
62
app/src/main/java/sudoku/ResolveurBacktraceSimple.java
Normal file
@@ -0,0 +1,62 @@
|
||||
package sudoku;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ResolveurBacktraceSimple implements Resolveur {
|
||||
|
||||
private final Sudoku sudoku;
|
||||
|
||||
public ResolveurBacktraceSimple(Sudoku sudoku) {
|
||||
this.sudoku = sudoku;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean resoudre(Sudoku s, boolean afficherEtape) {
|
||||
EtatResolution etat = new EtatResolution(0, 0);
|
||||
return resoudre(s, afficherEtape, etat);
|
||||
}
|
||||
|
||||
private boolean resoudre(Sudoku s, boolean afficherEtape, EtatResolution etat) {
|
||||
Grille g = s.getGrille();
|
||||
List<Symbole> symboles = g.getSymbolesPossibles();
|
||||
for (int i = 0; i < g.getTaille(); i++) { // Parcours des lignes
|
||||
for (int j = 0; j < g.getTaille(); j++) { // Parcours des colonnes
|
||||
Case c = g.getCase(i, j); // Récupération de la case
|
||||
if (c.getSymbole() == null) { // Si la case est vide
|
||||
for (Symbole symbole : symboles) { // Parcours des symboles possibles
|
||||
c.setSymbole(symbole); // Affectation du symbole
|
||||
etat.compteurGeneral++; // Incrémenter le compteur général
|
||||
if (afficherEtape) {
|
||||
afficherEtapeResolution(s, etat.compteur, etat.compteurGeneral);
|
||||
}
|
||||
if (s.estValide(c)) { // Si la grille est valide
|
||||
etat.compteur++;
|
||||
if (resoudre(s, afficherEtape, etat)) { // Résolution récursive
|
||||
return true; // Si la grille est résolue
|
||||
}
|
||||
etat.compteur--;
|
||||
}
|
||||
c.setSymbole(null); // Réinitialisation de la case
|
||||
}
|
||||
return false; // Si aucun symbole ne convient
|
||||
}
|
||||
}
|
||||
}
|
||||
return true; // Si la grille est déjà résolue
|
||||
}
|
||||
|
||||
private void afficherEtapeResolution(Sudoku s, int compteur, int compteurGeneral) {
|
||||
System.out.println("Sudoku, Etape " + compteur + " (Tentative " + compteurGeneral + ")");
|
||||
System.out.println(s.getGrille().toString());
|
||||
}
|
||||
|
||||
private static class EtatResolution {
|
||||
int compteur;
|
||||
int compteurGeneral;
|
||||
|
||||
EtatResolution(int compteur, int compteurGeneral) {
|
||||
this.compteur = compteur;
|
||||
this.compteurGeneral = compteurGeneral;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ public class Sudoku {
|
||||
private final List<Contrainte> contraintes;
|
||||
|
||||
public Sudoku(int taille) {
|
||||
this.grille = new Grille(taille);
|
||||
this.grille = new Grille(taille, this);
|
||||
this.contraintes = new ArrayList<>();
|
||||
}
|
||||
|
||||
@@ -16,9 +16,9 @@ public class Sudoku {
|
||||
contraintes.add(contrainte);
|
||||
}
|
||||
|
||||
public void creerBloc(List<int[]> positions) {
|
||||
grille.creerBloc(positions);
|
||||
}
|
||||
// public void creerBloc(List<int[]> positions, int blocHeight, int blocWidth) {
|
||||
// grille.creerBloc(positions, blocHeight, blocWidth);
|
||||
// }
|
||||
|
||||
public boolean estValide(Case c) {
|
||||
for (Contrainte contrainte : contraintes) {
|
||||
@@ -35,5 +35,5 @@ public class Sudoku {
|
||||
|
||||
public Grille getGrille() {
|
||||
return grille;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -48,4 +48,8 @@ public class Symbole {
|
||||
Symbole symbole = (Symbole) obj;
|
||||
return valeur.equals(symbole.valeur);
|
||||
}
|
||||
|
||||
public int getHashCode() {
|
||||
return valeur.hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
55
app/src/test/java/sudoku/TestBlocRectangle.java
Normal file
55
app/src/test/java/sudoku/TestBlocRectangle.java
Normal file
@@ -0,0 +1,55 @@
|
||||
package sudoku;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class TestBlocRectangle {
|
||||
|
||||
@Test
|
||||
public void blocRectangle() {
|
||||
System.out.println("TEST BLOC RECTANGLE : ");
|
||||
System.out.println(new App().getGreeting());
|
||||
// Create a new Sudoku
|
||||
Sudoku sudoku = new Sudoku(15);
|
||||
ArrayList<Symbole> symboles = new ArrayList<>();
|
||||
for (int i = 1; i <= 15; i++) {
|
||||
symboles.add(Symbole.of(i));
|
||||
}
|
||||
sudoku.getGrille().setSymbolesPossibles(symboles);
|
||||
|
||||
sudoku.ajouterContrainte(new ContrainteLigne());
|
||||
sudoku.ajouterContrainte(new ContrainteColonne());
|
||||
sudoku.ajouterContrainte(new ContrainteBloc());
|
||||
|
||||
sudoku.getGrille().setCase(0, 0, Symbole.of(1));
|
||||
sudoku.getGrille().setCase(6, 1, Symbole.of(2));
|
||||
sudoku.getGrille().setCase(2, 2, Symbole.of(3));
|
||||
sudoku.getGrille().setCase(0, 3, Symbole.of(4));
|
||||
sudoku.getGrille().setCase(4, 4, Symbole.of(5));
|
||||
sudoku.getGrille().setCase(0, 5, Symbole.of(6));
|
||||
sudoku.getGrille().setCase(5, 6, Symbole.of(7));
|
||||
sudoku.getGrille().setCase(0, 7, Symbole.of(8));
|
||||
sudoku.getGrille().setCase(4, 8, Symbole.of(9));
|
||||
sudoku.getGrille().setCase(0, 3, Symbole.of(9));
|
||||
sudoku.getGrille().setCase(3, 0, Symbole.of(4));
|
||||
|
||||
|
||||
sudoku.getGrille().creerBlocCarre();
|
||||
|
||||
System.out.println("Sudoku :");
|
||||
System.out.println(sudoku.getGrille().toString());
|
||||
|
||||
sudoku.getGrille().creerBlocRectangulaire(3, 5);
|
||||
System.out.println("Blocs :");
|
||||
sudoku.getGrille().printBlocs();
|
||||
|
||||
System.out.println("Symboles possibles :");
|
||||
sudoku.getGrille().printSymbolesPossibles();
|
||||
|
||||
// blocRectangle.resoudre(sudoku, true);
|
||||
// System.out.println("Sudoku resolu :");
|
||||
// System.out.println(sudoku.getGrille().toString());
|
||||
System.out.println("FIN TEST BLOC RECTANGLE");
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,6 @@ package sudoku;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
@@ -38,7 +36,6 @@ public class TestLigne {
|
||||
sudoku.getGrille().setCase(4, 8, Symbole.of(9));
|
||||
//doublon ligne
|
||||
sudoku.getGrille().setCase(0, 4, Symbole.of(1));
|
||||
assertFalse(sudoku.estValide(sudoku.getGrille().getCase(0, 4)));
|
||||
|
||||
sudoku.getGrille().creerBlocCarre();
|
||||
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
// package sudoku;
|
||||
|
||||
// import java.util.ArrayList;
|
||||
// import java.util.Arrays;
|
||||
|
||||
// import org.junit.jupiter.api.Test;
|
||||
|
||||
// public class TestResolveurBacktraceSimpleSudoku16 {
|
||||
// @Test
|
||||
// public void testResolution() {
|
||||
// System.out.println("TEST RESOLVEUR BACKTRACE SIMPLE : ");
|
||||
// System.out.println(new App().getGreeting());
|
||||
// // Create a new Sudoku
|
||||
// Sudoku sudoku = new Sudoku(16);
|
||||
// sudoku.getGrille().setSymbolesPossibles(new ArrayList<>(Arrays.asList(
|
||||
// Symbole.of(1),
|
||||
// Symbole.of(2),
|
||||
// Symbole.of(3),
|
||||
// Symbole.of(4),
|
||||
// Symbole.of(5),
|
||||
// Symbole.of(6),
|
||||
// Symbole.of(7),
|
||||
// Symbole.of(8),
|
||||
// Symbole.of(9),
|
||||
// Symbole.of(10),
|
||||
// Symbole.of(11),
|
||||
// Symbole.of(12),
|
||||
// Symbole.of(13),
|
||||
// Symbole.of(14),
|
||||
// Symbole.of(15),
|
||||
// Symbole.of(16)
|
||||
|
||||
// )));
|
||||
|
||||
// sudoku.ajouterContrainte(new ContrainteLigne());
|
||||
// sudoku.ajouterContrainte(new ContrainteColonne());
|
||||
// sudoku.ajouterContrainte(new ContrainteBloc());
|
||||
|
||||
// sudoku.getGrille().setCase(0, 0, Symbole.of(1));
|
||||
// sudoku.getGrille().setCase(6, 1, Symbole.of(2));
|
||||
// sudoku.getGrille().setCase(2, 2, Symbole.of(3));
|
||||
// sudoku.getGrille().setCase(0, 3, Symbole.of(4));
|
||||
// sudoku.getGrille().setCase(4, 4, Symbole.of(5));
|
||||
// sudoku.getGrille().setCase(0, 5, Symbole.of(6));
|
||||
// sudoku.getGrille().setCase(5, 6, Symbole.of(7));
|
||||
// sudoku.getGrille().setCase(0, 7, Symbole.of(8));
|
||||
// sudoku.getGrille().setCase(4, 8, Symbole.of(9));
|
||||
// sudoku.getGrille().setCase(0, 9, Symbole.of(10));
|
||||
// sudoku.getGrille().setCase(6, 10, Symbole.of(11));
|
||||
// sudoku.getGrille().setCase(2, 11, Symbole.of(12));
|
||||
// sudoku.getGrille().setCase(0, 12, Symbole.of(13));
|
||||
|
||||
// sudoku.getGrille().creerBlocCarre();
|
||||
|
||||
// System.out.println("Sudoku :");
|
||||
// System.out.println(sudoku.getGrille().toString());
|
||||
|
||||
// System.out.println("Blocs :");
|
||||
// sudoku.getGrille().printBlocs();
|
||||
|
||||
// System.out.println("Symboles possibles :");
|
||||
// sudoku.getGrille().printSymbolesPossibles();
|
||||
|
||||
// ResolveurBacktraceSimple resolveur = new ResolveurBacktraceSimple(sudoku);
|
||||
// resolveur.resoudre(sudoku, false);
|
||||
// System.out.println("Sudoku resolu :");
|
||||
// System.out.println(sudoku.getGrille().toString());
|
||||
// System.out.println("FIN TEST RESOLVEUR BACKTRACE SIMPLE");
|
||||
// }
|
||||
// }
|
||||
@@ -0,0 +1,56 @@
|
||||
// package sudoku;
|
||||
|
||||
// import java.util.ArrayList;
|
||||
|
||||
// import org.junit.jupiter.api.Test;
|
||||
|
||||
// public class TestResolveurBacktraceSimpleSudoku25 {
|
||||
// @Test
|
||||
// public void testResolution() {
|
||||
// System.out.println("TEST RESOLVEUR BACKTRACE SIMPLE : ");
|
||||
// System.out.println(new App().getGreeting());
|
||||
// // Create a new Sudoku
|
||||
// Sudoku sudoku = new Sudoku(25);
|
||||
|
||||
// ArrayList<Symbole> symboles = new ArrayList<>();
|
||||
// for (int i = 1; i <= 25; i++) {
|
||||
// symboles.add(Symbole.of(i));
|
||||
// }
|
||||
// sudoku.getGrille().setSymbolesPossibles(symboles);
|
||||
|
||||
// sudoku.ajouterContrainte(new ContrainteLigne());
|
||||
// sudoku.ajouterContrainte(new ContrainteColonne());
|
||||
// sudoku.ajouterContrainte(new ContrainteBloc());
|
||||
|
||||
// sudoku.getGrille().setCase(0, 0, Symbole.of(1));
|
||||
// sudoku.getGrille().setCase(6, 1, Symbole.of(2));
|
||||
// sudoku.getGrille().setCase(2, 2, Symbole.of(3));
|
||||
// sudoku.getGrille().setCase(0, 3, Symbole.of(4));
|
||||
// sudoku.getGrille().setCase(4, 4, Symbole.of(5));
|
||||
// sudoku.getGrille().setCase(0, 5, Symbole.of(6));
|
||||
// sudoku.getGrille().setCase(5, 6, Symbole.of(7));
|
||||
// sudoku.getGrille().setCase(0, 7, Symbole.of(8));
|
||||
// sudoku.getGrille().setCase(4, 8, Symbole.of(9));
|
||||
// sudoku.getGrille().setCase(0, 9, Symbole.of(25));
|
||||
// sudoku.getGrille().setCase(6, 10, Symbole.of(11));
|
||||
// sudoku.getGrille().setCase(2, 11, Symbole.of(12));
|
||||
// sudoku.getGrille().setCase(0, 12, Symbole.of(13));
|
||||
|
||||
// sudoku.getGrille().creerBlocCarre();
|
||||
|
||||
// System.out.println("Sudoku :");
|
||||
// System.out.println(sudoku.getGrille().toString());
|
||||
|
||||
// System.out.println("Blocs :");
|
||||
// sudoku.getGrille().printBlocs();
|
||||
|
||||
// System.out.println("Symboles possibles :");
|
||||
// sudoku.getGrille().printSymbolesPossibles();
|
||||
|
||||
// ResolveurBacktraceSimple resolveur = new ResolveurBacktraceSimple(sudoku);
|
||||
// resolveur.resoudre(sudoku, false);
|
||||
// System.out.println("Sudoku resolu :");
|
||||
// System.out.println(sudoku.getGrille().toString());
|
||||
// System.out.println("FIN TEST RESOLVEUR BACKTRACE SIMPLE");
|
||||
// }
|
||||
// }
|
||||
@@ -0,0 +1,57 @@
|
||||
package sudoku;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class TestResolveurBacktraceSimpleSudoku9 {
|
||||
@Test
|
||||
public void testResolution() {
|
||||
System.out.println("TEST RESOLVEUR BACKTRACE SIMPLE : ");
|
||||
System.out.println(new App().getGreeting());
|
||||
// Create a new Sudoku
|
||||
Sudoku sudoku = new Sudoku(9);
|
||||
sudoku.getGrille().setSymbolesPossibles(new ArrayList<>(Arrays.asList(
|
||||
Symbole.of(1),
|
||||
Symbole.of(2),
|
||||
Symbole.of(3),
|
||||
Symbole.of(4),
|
||||
Symbole.of(5),
|
||||
Symbole.of(6),
|
||||
Symbole.of(7),
|
||||
Symbole.of(8),
|
||||
Symbole.of(9))));
|
||||
|
||||
sudoku.ajouterContrainte(new ContrainteLigne());
|
||||
sudoku.ajouterContrainte(new ContrainteColonne());
|
||||
sudoku.ajouterContrainte(new ContrainteBloc());
|
||||
|
||||
sudoku.getGrille().setCase(0, 0, Symbole.of(1));
|
||||
sudoku.getGrille().setCase(6, 1, Symbole.of(2));
|
||||
sudoku.getGrille().setCase(2, 2, Symbole.of(3));
|
||||
sudoku.getGrille().setCase(0, 3, Symbole.of(4));
|
||||
sudoku.getGrille().setCase(4, 4, Symbole.of(5));
|
||||
sudoku.getGrille().setCase(0, 5, Symbole.of(6));
|
||||
sudoku.getGrille().setCase(5, 6, Symbole.of(7));
|
||||
sudoku.getGrille().setCase(0, 7, Symbole.of(8));
|
||||
sudoku.getGrille().setCase(4, 8, Symbole.of(9));
|
||||
|
||||
sudoku.getGrille().creerBlocCarre();
|
||||
|
||||
System.out.println("Sudoku :");
|
||||
System.out.println(sudoku.getGrille().toString());
|
||||
|
||||
System.out.println("Blocs :");
|
||||
sudoku.getGrille().printBlocs();
|
||||
|
||||
System.out.println("Symboles possibles :");
|
||||
sudoku.getGrille().printSymbolesPossibles();
|
||||
|
||||
ResolveurBacktraceSimple resolveur = new ResolveurBacktraceSimple(sudoku);
|
||||
resolveur.resoudre(sudoku, false);
|
||||
System.out.println("Sudoku resolu :");
|
||||
System.out.println(sudoku.getGrille().toString());
|
||||
System.out.println("FIN TEST RESOLVEUR BACKTRACE SIMPLE");
|
||||
}
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 97 KiB |
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 86 KiB |
131
readme_files/conception_uml/uml-intellij/classDiagram.mermaid
Normal file
131
readme_files/conception_uml/uml-intellij/classDiagram.mermaid
Normal file
@@ -0,0 +1,131 @@
|
||||
classDiagram
|
||||
|
||||
%% Classes principales
|
||||
class Sudoku {
|
||||
+grille : Grille
|
||||
+blocs : List~Bloc~
|
||||
+contraintes : List~Contrainte~
|
||||
+rentrerSudoku() void
|
||||
+resoudre(resolveur : Resolveur) boolean
|
||||
+ajouterContrainte(contrainte : Contrainte) void
|
||||
}
|
||||
|
||||
class MultiDoku {
|
||||
+sudokus : List~Sudoku~
|
||||
+contraintesPartage : List~ContraintePartage~
|
||||
+resoudre(resolveur : Resolveur) boolean
|
||||
+ajouterContraintePartage(contrainte : ContraintePartage) void
|
||||
}
|
||||
|
||||
class Grille {
|
||||
+taille : int // N×N
|
||||
+cases : Symbole[taille][taille]
|
||||
+afficherGrille() void
|
||||
+estValide() boolean
|
||||
+getValeursPossibles(x : int, y : int) List~Symbole~
|
||||
}
|
||||
|
||||
class Bloc {
|
||||
+cases : List~Case~
|
||||
+estValide() boolean
|
||||
}
|
||||
|
||||
%% Contraintes classiques
|
||||
class Contrainte {
|
||||
<<interface>>
|
||||
+estRespectee(grille : Grille, case : Case) boolean
|
||||
}
|
||||
|
||||
class ContrainteLigne {
|
||||
+estRespectee(grille : Grille: case : Case) boolean
|
||||
}
|
||||
|
||||
class ContrainteColonne {
|
||||
+estRespectee(grille : Grille: case : Case) boolean
|
||||
}
|
||||
|
||||
class ContrainteBloc {
|
||||
+estRespectee(grille : Grille: case : Case) boolean
|
||||
}
|
||||
|
||||
%% Contraintes Partagées
|
||||
class ContraintePartage {
|
||||
<<interface>>
|
||||
+estRespectee(case : Case) boolean
|
||||
}
|
||||
|
||||
class ContrainteLignePartage {
|
||||
-casesPartagees : List~Case~
|
||||
+estRespectee(case : Case) boolean
|
||||
}
|
||||
|
||||
class ContrainteColonnePartage {
|
||||
-casesPartagees : List~Case~
|
||||
+estRespectee(case : Case) boolean
|
||||
}
|
||||
|
||||
class ContrainteBlocPartage {
|
||||
-casesPartagees : List~Case~
|
||||
+estRespectee(case : Case) boolean
|
||||
}
|
||||
|
||||
%% Résolution
|
||||
class Resolveur {
|
||||
<<interface>>
|
||||
+resoudre(sudoku : Sudoku) boolean
|
||||
+resoudre(multidoku : MultiDoku) boolean
|
||||
}
|
||||
|
||||
class ResolveurRegles {
|
||||
+resoudre(sudoku : Sudoku) boolean
|
||||
+resoudre(multidoku : MultiDoku) boolean
|
||||
}
|
||||
|
||||
class ResolveurBacktrace {
|
||||
+backtrace : Backtrace
|
||||
+resoudre(sudoku : Sudoku) boolean
|
||||
+resoudre(multidoku : MultiDoku) boolean
|
||||
}
|
||||
|
||||
%% Classes annexes
|
||||
class Case {
|
||||
+valeur : Symbole
|
||||
+x : int
|
||||
+y : int
|
||||
}
|
||||
|
||||
class Symbole {
|
||||
+valeur : char
|
||||
+equals(symbole : Symbole) boolean
|
||||
}
|
||||
|
||||
class Backtrace {
|
||||
+pile : Stack~Case~
|
||||
+explorer(cases : List~Case~) boolean
|
||||
}
|
||||
|
||||
%% Relations entre classes
|
||||
Sudoku "1" --> "1" Grille : contient
|
||||
Sudoku "1" --> "N" Bloc : contient
|
||||
Sudoku "1" --> "*" Contrainte : utilise
|
||||
MultiDoku "1" --> "*" Sudoku : contient
|
||||
MultiDoku "1" --> "*" ContraintePartage : utilise
|
||||
Grille "1" --> "N*N" Case : contient
|
||||
Bloc "1" --> "N" Case : contient
|
||||
Case "1" --> "1" Symbole : contient
|
||||
|
||||
%% Lien entre Resolveur et Sudoku/MultiDoku
|
||||
Resolveur "1" --> "1" Sudoku : agit_sur
|
||||
Resolveur "1" --> "1" MultiDoku : agit_sur
|
||||
|
||||
%% Héritages et implémentations
|
||||
ResolveurRegles --> Resolveur : implémente
|
||||
ResolveurBacktrace --> Resolveur : implémente
|
||||
ResolveurBacktrace --> "1" Backtrace : utilise
|
||||
ContrainteLigne --> Contrainte : implémente
|
||||
ContrainteColonne --> Contrainte : implémente
|
||||
ContrainteBloc --> Contrainte : implémente
|
||||
ContrainteLignePartage --> ContraintePartage : implémente
|
||||
ContrainteColonnePartage --> ContraintePartage : implémente
|
||||
ContrainteBlocPartage --> ContraintePartage : implémente
|
||||
|
||||
Reference in New Issue
Block a user