Squashed commit of the following:
commit 1791846882ffc30b5fb052b1619093a5a74a409c Author: ROGER <gwendal.roger@etu.univ-lyon1.fr> Date: Mon Feb 3 10:23:53 2025 +0100 03/02/2025 : Ajout d'un mecanisme pour la création de bloc mannuels commit 39892a169561e4827a9e14fdb52cdf870ef30013 Author: ROGER <gwendal.roger@etu.univ-lyon1.fr> Date: Mon Feb 3 10:21:06 2025 +0100 03/02/2025 : Ajout d'un mecanisme pour la création de bloc mannuels commit ec5101a213c6a5fc24997eab3375def7595a637a Author: ROGER <gwendal.roger@etu.univ-lyon1.fr> Date: Thu Jan 30 10:57:46 2025 +0100 30/01/2025 : Ajout d'un menu utilisateur + ajout de système de vérification des saisies commit 8d77fd725f65ba946c46b344186aa56d53448b1a Author: ROGER <gwendal.roger@etu.univ-lyon1.fr> Date: Mon Jan 20 13:01:12 2025 +0100 20/01/2025 : Ajout de test + création d'un menu utilisateur commit af2dcfe2c46eefa0e49e3bf88ea51327690c660d Author: Morph01 <thibaut6969delastreet@gmail.com> Date: Mon Jan 20 12:57:32 2025 +0100 Squashed commit of the following: commit3586ae4c15Author: Morph01 <thibaut6969delastreet@gmail.com> Date: Mon Jan 20 12:53:23 2025 +0100 Squashed commit of the following: commit862ff6e08dAuthor: Morph01 <thibaut6969delastreet@gmail.com> Date: Mon Jan 20 12:49:38 2025 +0100 feat: affichage de la grille colorée et vérification de tt les contraintes commitb1dde68ec1Author: Morph01 <thibaut6969delastreet@gmail.com> Date: Sun Jan 5 11:16:34 2025 +0100 feat: add constraint management and validation to Sudoku class commitd8486a3bd7Author: Morph01 <thibaut6969delastreet@gmail.com> Date: Sun Jan 5 11:13:19 2025 +0100 feat: implement constraint classes for Sudoku (row, column, block) commit8945072074Author: Morph01 <thibaut6969delastreet@gmail.com> Date: Sun Jan 5 11:12:59 2025 +0100 refactor: rename methods to French for consistency in the Sudoku application commite35123e9feAuthor: Morph01 <thibaut6969delastreet@gmail.com> Date: Sun Jan 5 11:11:40 2025 +0100 fix: update build.gradle to use testRuntimeOnly for JUnit Jupiter engine commit22e88a899fAuthor: Morph01 <thibaut6969delastreet@gmail.com> Date: Sat Jan 4 15:56:23 2025 +0000 Gwendal in main : add test on futur constraints and enhance input symbol method (#1) Co-authored-by: ROGER <gwendal.roger@etu.univ-lyon1.fr> Reviewed-on: #1 commit3e6aa821fcAuthor: Morph01 <thibaut6969delastreet@gmail.com> Date: Sat Jan 4 16:51:12 2025 +0100 feat: enhance symbol input validation and improve console messaging commit7c4fa8cbe8Author: Morph01 <thibaut6969delastreet@gmail.com> Date: Sat Jan 4 16:49:41 2025 +0100 chore: update Gradle wrapper to version 8.3 commitc226eeebaeAuthor: ROGER <gwendal.roger@etu.univ-lyon1.fr> Date: Fri Jan 3 22:58:54 2025 +0100 03/01/2025 : Intégration d'un mécanisme permettant de contrôler que le symbole choisi ne figure pas déjà dans la liste de symboles possibles. Permet d'éviter les doublons commitb553fd2be9Author: ROGER <gwendal.roger@etu.univ-lyon1.fr> Date: Fri Jan 3 17:12:10 2025 +0100 03/01/2025 : Création d'un second sudoku avec intégration automatique des symboles commita1b130b968Author: ROGER <gwendal.roger@etu.univ-lyon1.fr> Date: Fri Jan 3 16:35:02 2025 +0100 03/01/2025 : Ajout des tests lignes, colonne et bloc commit7c29041ca4Author: ROGER <gwendal.roger@etu.univ-lyon1.fr> Date: Thu Dec 26 20:27:49 2024 +0100 Création de branche / 1er COMMIT de test
This commit is contained in:
3
.idea/.gitignore
generated
vendored
Normal file
3
.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
2
.idea/compiler.xml
generated
2
.idea/compiler.xml
generated
@@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="CompilerConfiguration">
|
<component name="CompilerConfiguration">
|
||||||
<bytecodeTargetLevel target="21" />
|
<bytecodeTargetLevel target="1.8" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
1
.idea/gradle.xml
generated
1
.idea/gradle.xml
generated
@@ -1,5 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
|
<component name="GradleMigrationSettings" migrationVersion="1" />
|
||||||
<component name="GradleSettings">
|
<component name="GradleSettings">
|
||||||
<option name="linkedExternalProjectsSettings">
|
<option name="linkedExternalProjectsSettings">
|
||||||
<GradleProjectSettings>
|
<GradleProjectSettings>
|
||||||
|
|||||||
20
.idea/jarRepositories.xml
generated
Normal file
20
.idea/jarRepositories.xml
generated
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="RemoteRepositoriesConfiguration">
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="central" />
|
||||||
|
<option name="name" value="Maven Central repository" />
|
||||||
|
<option name="url" value="https://repo1.maven.org/maven2" />
|
||||||
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="jboss.community" />
|
||||||
|
<option name="name" value="JBoss Community repository" />
|
||||||
|
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||||
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="MavenRepo" />
|
||||||
|
<option name="name" value="MavenRepo" />
|
||||||
|
<option name="url" value="https://repo.maven.apache.org/maven2/" />
|
||||||
|
</remote-repository>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="21" project-jdk-type="JavaSDK" />
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK" />
|
||||||
</project>
|
</project>
|
||||||
124
.idea/uiDesigner.xml
generated
Normal file
124
.idea/uiDesigner.xml
generated
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Palette2">
|
||||||
|
<group name="Swing">
|
||||||
|
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="Button" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="RadioButton" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="CheckBox" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="Label" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||||
|
<preferred-size width="150" height="-1" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||||
|
<preferred-size width="150" height="-1" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||||
|
<preferred-size width="150" height="-1" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||||
|
<preferred-size width="200" height="200" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||||
|
<preferred-size width="200" height="200" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
|
||||||
|
<preferred-size width="-1" height="20" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
|
||||||
|
</item>
|
||||||
|
</group>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
BIN
Sudoku_menuGrille.jpg
Normal file
BIN
Sudoku_menuGrille.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 184 KiB |
@@ -1,8 +1,5 @@
|
|||||||
package sudoku;
|
package sudoku;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
public class App {
|
public class App {
|
||||||
public String getGreeting() {
|
public String getGreeting() {
|
||||||
return "Hello World!";
|
return "Hello World!";
|
||||||
@@ -10,7 +7,7 @@ public class App {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
System.out.println(new App().getGreeting());
|
System.out.println(new App().getGreeting());
|
||||||
|
/*
|
||||||
// Create a new Sudoku
|
// Create a new Sudoku
|
||||||
Sudoku sudoku = new Sudoku(9);
|
Sudoku sudoku = new Sudoku(9);
|
||||||
sudoku.getGrille().setSymbolesPossibles(new ArrayList<>(Arrays.asList(
|
sudoku.getGrille().setSymbolesPossibles(new ArrayList<>(Arrays.asList(
|
||||||
@@ -49,9 +46,16 @@ public class App {
|
|||||||
System.out.println("Création d'un second SUDOKU");
|
System.out.println("Création d'un second SUDOKU");
|
||||||
|
|
||||||
Sudoku sudoku2 = new Sudoku(9);
|
Sudoku sudoku2 = new Sudoku(9);
|
||||||
sudoku2.getGrille().askSetSymbolesPossibles();
|
/*sudoku2.getGrille().askSetSymbolesPossibles();
|
||||||
|
|
||||||
System.out.println("Symboles possibles :");
|
System.out.println("Symboles possibles :");
|
||||||
sudoku2.getGrille().printSymbolesPossibles();
|
sudoku2.getGrille().printSymbolesPossibles();*/
|
||||||
|
|
||||||
|
try{
|
||||||
|
Sudoku.menuGrille();
|
||||||
|
} catch (Exception e){
|
||||||
|
System.err.println("Une erreur fatale est survenue : " + e.getMessage());
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package sudoku;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
import sudoku.core.Console;
|
import sudoku.core.Console;
|
||||||
@@ -316,6 +317,9 @@ public class Grille {
|
|||||||
if (symbolesPossibles.contains(stringTemp)) {
|
if (symbolesPossibles.contains(stringTemp)) {
|
||||||
Console.errorln("Ce symbole existe déjà, veuillez entrer un autre symbole");
|
Console.errorln("Ce symbole existe déjà, veuillez entrer un autre symbole");
|
||||||
i--;
|
i--;
|
||||||
|
} else if (Objects.equals(input, "ESC")) {
|
||||||
|
Console.errorln("Ce symbole est interdit, veuillez entrer un autre symbole");
|
||||||
|
i--;
|
||||||
} else {
|
} else {
|
||||||
symbolesPossibles.add(stringTemp);
|
symbolesPossibles.add(stringTemp);
|
||||||
}
|
}
|
||||||
@@ -323,13 +327,10 @@ public class Grille {
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
Console.errorln("Type non supporté");
|
Console.errorln("Type non supporté");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.out.println("Une erreur est survenue : " + e.getMessage());
|
System.out.println("Une erreur est survenue : " + e.getMessage());
|
||||||
} finally {
|
|
||||||
scanner.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,12 @@
|
|||||||
package sudoku;
|
package sudoku;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Scanner;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import sudoku.core.Console;
|
||||||
|
|
||||||
public class Sudoku {
|
public class Sudoku {
|
||||||
private final Grille grille;
|
private final Grille grille;
|
||||||
@@ -17,7 +22,7 @@ public class Sudoku {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// public void creerBloc(List<int[]> positions, int blocHeight, int blocWidth) {
|
// public void creerBloc(List<int[]> positions, int blocHeight, int blocWidth) {
|
||||||
// grille.creerBloc(positions, blocHeight, blocWidth);
|
// grille.creerBloc(positions, blocHeight, blocWidth);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
public boolean estValide(Case c) {
|
public boolean estValide(Case c) {
|
||||||
@@ -36,4 +41,208 @@ public class Sudoku {
|
|||||||
public Grille getGrille() {
|
public Grille getGrille() {
|
||||||
return grille;
|
return grille;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Sudoku menuGrille() {
|
||||||
|
Scanner scanner = new Scanner(System.in);
|
||||||
|
// ETAPE 1 : TAILLE GRILLE
|
||||||
|
System.out.println("ETAPE 1 : Choisir la taille de la grille");
|
||||||
|
int tailleGrille = setTailleGrille(scanner); // récpère la taille de la grille
|
||||||
|
Sudoku sudoku = new Sudoku(tailleGrille);
|
||||||
|
// ETAPE 2 : SYMBOLE POSSIBLE
|
||||||
|
System.out.println("ETAPE 2 : Choisir les symboles possibles");
|
||||||
|
sudoku.getGrille().askSetSymbolesPossibles(); // demande à l'utilisateur de saisir ses symboles
|
||||||
|
// ETAPE 3 : REMPLIR LA GRILLE
|
||||||
|
System.out.println("ETAPE 3 : Remplir la grille");
|
||||||
|
setValeursGrille(sudoku, scanner, tailleGrille);
|
||||||
|
System.out.println("Voici votre sudoku : ");
|
||||||
|
System.out.println(sudoku.getGrille().toString());
|
||||||
|
// System.out.println("ETAPE 4 : Choisir type de grille");
|
||||||
|
return sudoku;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int setTailleGrille(Scanner scanner) {
|
||||||
|
int tailleGrille = -1;
|
||||||
|
while (tailleGrille <= 0) {
|
||||||
|
try {
|
||||||
|
tailleGrille = Integer.parseInt(scanner.nextLine());
|
||||||
|
if (tailleGrille <= 0) {
|
||||||
|
System.out.println("Erreur : Veuillez entrer un entier positif.");
|
||||||
|
}
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
System.out.println("Erreur : Entrée invalide. Veuillez entrer un nombre.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return tailleGrille;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Sudoku setValeursGrille(Sudoku sudoku, Scanner scanner, int tailleGrille) {
|
||||||
|
// Etude de la taille de la grille pour choisir le type de génération
|
||||||
|
if (carreParfait(tailleGrille)) {
|
||||||
|
System.out.println(tailleGrille + " est un carré parfait.");
|
||||||
|
sudoku.getGrille().creerBlocCarre();
|
||||||
|
} else {
|
||||||
|
while (true) {
|
||||||
|
System.out.println("Veillez faire votre choix");
|
||||||
|
System.out.println("1 : Entrer les blocs manuellement");
|
||||||
|
System.out.println("2 : Entrer les blocs à l'aide de la longueur et de la largeur");
|
||||||
|
|
||||||
|
int choixGenerationBloc = Integer.parseInt(scanner.nextLine());
|
||||||
|
|
||||||
|
switch (choixGenerationBloc) {
|
||||||
|
case 1:
|
||||||
|
// Entrer les blocs manuellement
|
||||||
|
System.out.println("Entrez les blocs manuellement.");
|
||||||
|
creationBlocMannuel(sudoku, scanner, tailleGrille);
|
||||||
|
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
// Entrer les blocs à l'aide de la longueur et de la largeur
|
||||||
|
System.out.println("Entrez les blocs à l'aide de la longueur et de la largeur.");
|
||||||
|
System.out.println("Entrez la longueur du bloc : ");
|
||||||
|
int longueurBloc = scanner.nextInt();
|
||||||
|
System.out.println("Entrez la largeur du bloc :");
|
||||||
|
int largeurBloc = scanner.nextInt();
|
||||||
|
sudoku.getGrille().creerBlocRectangulaire(longueurBloc, largeurBloc);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Console.errorln("Choix invalide.");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// DEBUT DU REMPLISSAGE DU SUDOKU
|
||||||
|
String input;
|
||||||
|
while (true) {
|
||||||
|
// Demander et vérifier la ligne
|
||||||
|
int ligne = -1;
|
||||||
|
while (true) {
|
||||||
|
System.out.println("Entrez le numéro de ligne (ou tapez ESC pour quitter) :");
|
||||||
|
input = scanner.nextLine(); // Lire la ligne
|
||||||
|
if (input.equalsIgnoreCase("ESC")) {
|
||||||
|
break; // Sortie de la boucle si l'utilisateur tape ESC
|
||||||
|
}
|
||||||
|
if (input.isEmpty()) {
|
||||||
|
System.out.println("Veuillez entrer un numéro de ligne valide.");
|
||||||
|
continue; // Recommencer la saisie de la ligne si l'entrée est vide
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
ligne = Integer.parseInt(input); // Convertir la ligne en entier
|
||||||
|
break; // Sortir de la boucle si la ligne est valide
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
System.out.println("Veuillez entrer un numéro de ligne valide (un nombre entier).");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ARRET DE LA BOUCLE SI SAISIE DE "ESC"
|
||||||
|
if (input.equalsIgnoreCase("ESC")) {
|
||||||
|
break; // Sortie de la boucle principale si l'utilisateur tape ESC
|
||||||
|
}
|
||||||
|
|
||||||
|
// Demander et vérifier la colonne
|
||||||
|
int colonne = -1;
|
||||||
|
while (true) {
|
||||||
|
System.out.println("Entrez le numéro de colonne :");
|
||||||
|
input = scanner.nextLine(); // Lire la colonne
|
||||||
|
if (input.isEmpty()) {
|
||||||
|
System.out.println("Veuillez entrer un numéro de colonne valide.");
|
||||||
|
continue; // Recommencer la saisie de la colonne si l'entrée est vide
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
colonne = Integer.parseInt(input); // Convertir la colonne en entier
|
||||||
|
break; // Sortir de la boucle si la colonne est valide
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
System.out.println("Veuillez entrer un numéro de colonne valide (un nombre entier).");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Demander et vérifier le symbole
|
||||||
|
String symbole = "";
|
||||||
|
while (true) {
|
||||||
|
System.out.println("Entrez le numéro du symbole :");
|
||||||
|
symbole = scanner.nextLine(); // Lire le symbole
|
||||||
|
if (symbole.isEmpty()) {
|
||||||
|
System.out.println("Veuillez entrer un symbole valide.");
|
||||||
|
continue; // Recommencer la saisie du symbole si l'entrée est vide
|
||||||
|
}
|
||||||
|
break; // Sortir de la boucle si le symbole est valide
|
||||||
|
}
|
||||||
|
|
||||||
|
// Assigner la valeur dans la grille
|
||||||
|
sudoku.getGrille().setCase(ligne, colonne, Symbole.of(symbole));
|
||||||
|
System.out.println(sudoku.getGrille().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
return sudoku;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean carreParfait(int nombre) {
|
||||||
|
if (nombre < 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
int racine = (int) Math.sqrt(nombre);
|
||||||
|
return racine * racine == nombre;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Sudoku creationBlocMannuel(Sudoku sudoku, Scanner scanner, int tailleGrille) {
|
||||||
|
int nombreBloc = tailleGrille; // Nombre de blocs dans la grille
|
||||||
|
|
||||||
|
Set<String> toutesLesCoordonnees = new HashSet<>(); // Stocke toutes les coordonnées utilisées
|
||||||
|
|
||||||
|
while (nombreBloc != 0) {
|
||||||
|
List<int[]> listeCases = new ArrayList<>(); // Liste des cases du bloc
|
||||||
|
System.out.println("Remplissage du bloc " + nombreBloc);
|
||||||
|
|
||||||
|
for (int i = 1; i <= tailleGrille; i++) {
|
||||||
|
int choixLigne, choixColonne;
|
||||||
|
boolean coordonneesValides;
|
||||||
|
|
||||||
|
do {
|
||||||
|
coordonneesValides = true; // Par défaut, on suppose que la coordonnée est valide
|
||||||
|
|
||||||
|
// Demande de saisie
|
||||||
|
System.out.println("Entrez la ligne de la case " + i + " dans le bloc " + nombreBloc + " (0 à "
|
||||||
|
+ (tailleGrille - 1) + "):");
|
||||||
|
choixLigne = scanner.nextInt();
|
||||||
|
System.out.println("Entrez la colonne de la case " + i + " dans le bloc " + nombreBloc + " (0 à "
|
||||||
|
+ (tailleGrille - 1) + "):");
|
||||||
|
choixColonne = scanner.nextInt();
|
||||||
|
|
||||||
|
// Vérification des limites
|
||||||
|
if (choixLigne < 0 || choixLigne >= tailleGrille || choixColonne < 0
|
||||||
|
|| choixColonne >= tailleGrille) {
|
||||||
|
System.out.println("Erreur : Coordonnées hors limites ! Veuillez réessayer.");
|
||||||
|
coordonneesValides = false;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Vérification si la coordonnée existe déjà dans TOUTE la grille
|
||||||
|
String coordonneeStr = choixLigne + "-" + choixColonne;
|
||||||
|
if (toutesLesCoordonnees.contains(coordonneeStr)) {
|
||||||
|
System.out.println(
|
||||||
|
"Erreur : Ces coordonnées sont déjà utilisées dans un autre bloc ! Veuillez en entrer une nouvelle.");
|
||||||
|
coordonneesValides = false;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
} while (!coordonneesValides); // Tant que la saisie est invalide, on redemande
|
||||||
|
|
||||||
|
// Ajout des coordonnées validées
|
||||||
|
listeCases.add(new int[] { choixLigne, choixColonne });
|
||||||
|
toutesLesCoordonnees.add(choixLigne + "-" + choixColonne); // Ajout dans l'ensemble global
|
||||||
|
}
|
||||||
|
|
||||||
|
// Création du bloc après la saisie complète
|
||||||
|
try {
|
||||||
|
sudoku.getGrille().creerBlocPersonnalise(listeCases);
|
||||||
|
System.out.println("Bloc " + nombreBloc + " enregistré avec succès !");
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
System.out.println("Erreur lors de la création du bloc : " + e.getMessage());
|
||||||
|
System.out.println("Veuillez recommencer la saisie de ce bloc.");
|
||||||
|
continue; // Recommence le bloc en cours
|
||||||
|
}
|
||||||
|
|
||||||
|
nombreBloc--; // Passer au bloc suivant
|
||||||
|
}
|
||||||
|
return sudoku;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
97
app/src/test/java/sudoku/TestCreationGrille.java
Normal file
97
app/src/test/java/sudoku/TestCreationGrille.java
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
package sudoku;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class TestCreationGrille {
|
||||||
|
@Test
|
||||||
|
public void testLigne() {
|
||||||
|
//CREATION D'UN SUDOKU SIMPLE 12*12
|
||||||
|
Sudoku sudoku = new Sudoku(12);
|
||||||
|
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))));
|
||||||
|
sudoku.getGrille().setCase(0, 1, Symbole.of(12));
|
||||||
|
sudoku.getGrille().setCase(0, 6, Symbole.of(3));
|
||||||
|
sudoku.getGrille().setCase(0, 7, Symbole.of(8));
|
||||||
|
sudoku.getGrille().setCase(0, 8, Symbole.of(2));
|
||||||
|
sudoku.getGrille().setCase(0, 9, Symbole.of(6));
|
||||||
|
sudoku.getGrille().setCase(1, 0, Symbole.of(7));
|
||||||
|
sudoku.getGrille().setCase(1, 1, Symbole.of(2));
|
||||||
|
sudoku.getGrille().setCase(1, 2, Symbole.of(1));
|
||||||
|
sudoku.getGrille().setCase(1, 5, Symbole.of(4));
|
||||||
|
sudoku.getGrille().setCase(1, 7, Symbole.of(5));
|
||||||
|
sudoku.getGrille().setCase(1, 9, Symbole.of(10));
|
||||||
|
sudoku.getGrille().setCase(1, 11, Symbole.of(9));
|
||||||
|
sudoku.getGrille().setCase(2, 1, Symbole.of(5));
|
||||||
|
sudoku.getGrille().setCase(2, 2, Symbole.of(10));
|
||||||
|
sudoku.getGrille().setCase(2, 5, Symbole.of(2));
|
||||||
|
sudoku.getGrille().setCase(2, 6, Symbole.of(7));
|
||||||
|
sudoku.getGrille().setCase(2, 10, Symbole.of(4));
|
||||||
|
sudoku.getGrille().setCase(3, 5, Symbole.of(12));
|
||||||
|
sudoku.getGrille().setCase(3, 11, Symbole.of(7));
|
||||||
|
sudoku.getGrille().setCase(4, 1, Symbole.of(1));
|
||||||
|
sudoku.getGrille().setCase(4, 3, Symbole.of(2));
|
||||||
|
sudoku.getGrille().setCase(4, 4, Symbole.of(6));
|
||||||
|
sudoku.getGrille().setCase(4, 5, Symbole.of(9));
|
||||||
|
sudoku.getGrille().setCase(4, 6, Symbole.of(5));
|
||||||
|
sudoku.getGrille().setCase(4, 9, Symbole.of(12));
|
||||||
|
sudoku.getGrille().setCase(4, 10, Symbole.of(3));
|
||||||
|
sudoku.getGrille().setCase(4, 11, Symbole.of(8));
|
||||||
|
sudoku.getGrille().setCase(5, 1, Symbole.of(4));
|
||||||
|
sudoku.getGrille().setCase(5, 2, Symbole.of(6));
|
||||||
|
sudoku.getGrille().setCase(5, 3, Symbole.of(12));
|
||||||
|
sudoku.getGrille().setCase(5, 5, Symbole.of(7));
|
||||||
|
sudoku.getGrille().setCase(5, 6, Symbole.of(10));
|
||||||
|
sudoku.getGrille().setCase(5, 9, Symbole.of(5));
|
||||||
|
sudoku.getGrille().setCase(5, 11, Symbole.of(11));
|
||||||
|
sudoku.getGrille().setCase(6, 0, Symbole.of(1));
|
||||||
|
sudoku.getGrille().setCase(6, 1, Symbole.of(8));
|
||||||
|
sudoku.getGrille().setCase(6, 2, Symbole.of(12));
|
||||||
|
sudoku.getGrille().setCase(6, 11, Symbole.of(6));
|
||||||
|
sudoku.getGrille().setCase(7, 2, Symbole.of(2));
|
||||||
|
sudoku.getGrille().setCase(7, 3, Symbole.of(5));
|
||||||
|
sudoku.getGrille().setCase(7, 5, Symbole.of(11));
|
||||||
|
sudoku.getGrille().setCase(7, 6, Symbole.of(8));
|
||||||
|
sudoku.getGrille().setCase(7, 7, Symbole.of(6));
|
||||||
|
sudoku.getGrille().setCase(7, 8, Symbole.of(7));
|
||||||
|
sudoku.getGrille().setCase(7, 10, Symbole.of(1));
|
||||||
|
sudoku.getGrille().setCase(7, 11, Symbole.of(12));
|
||||||
|
sudoku.getGrille().setCase(8, 4, Symbole.of(1));
|
||||||
|
sudoku.getGrille().setCase(8, 7, Symbole.of(10));
|
||||||
|
sudoku.getGrille().setCase(8, 8, Symbole.of(8));
|
||||||
|
sudoku.getGrille().setCase(8, 9, Symbole.of(11));
|
||||||
|
sudoku.getGrille().setCase(9, 5, Symbole.of(8));
|
||||||
|
sudoku.getGrille().setCase(9, 10, Symbole.of(9));
|
||||||
|
sudoku.getGrille().setCase(9, 11, Symbole.of(4));
|
||||||
|
sudoku.getGrille().setCase(10, 0, Symbole.of(2));
|
||||||
|
sudoku.getGrille().setCase(10, 2, Symbole.of(3));
|
||||||
|
sudoku.getGrille().setCase(10, 4, Symbole.of(9));
|
||||||
|
sudoku.getGrille().setCase(11, 0, Symbole.of(4));
|
||||||
|
sudoku.getGrille().setCase(11, 3, Symbole.of(9));
|
||||||
|
sudoku.getGrille().setCase(11, 4, Symbole.of(5));
|
||||||
|
sudoku.getGrille().setCase(11, 6, Symbole.of(11));
|
||||||
|
sudoku.getGrille().setCase(11, 8, Symbole.of(6));
|
||||||
|
sudoku.getGrille().setCase(11, 11, Symbole.of(3));
|
||||||
|
// TODO
|
||||||
|
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();
|
||||||
|
System.out.println("FIN TEST LIGNE");
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user