Compare commits
5 Commits
merge/solv
...
feature/co
| Author | SHA1 | Date | |
|---|---|---|---|
| 862ff6e08d | |||
| b1dde68ec1 | |||
| d8486a3bd7 | |||
| 8945072074 | |||
| e35123e9fe |
3
.idea/.gitignore
generated
vendored
3
.idea/.gitignore
generated
vendored
@@ -1,3 +0,0 @@
|
|||||||
# Default ignored files
|
|
||||||
/shelf/
|
|
||||||
/workspace.xml
|
|
||||||
6
.idea/compiler.xml
generated
6
.idea/compiler.xml
generated
@@ -1,6 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="CompilerConfiguration">
|
|
||||||
<bytecodeTargetLevel target="1.8" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
17
.idea/gradle.xml
generated
17
.idea/gradle.xml
generated
@@ -1,17 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="GradleMigrationSettings" migrationVersion="1" />
|
|
||||||
<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>
|
|
||||||
20
.idea/jarRepositories.xml
generated
20
.idea/jarRepositories.xml
generated
@@ -1,20 +0,0 @@
|
|||||||
<?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>
|
|
||||||
5
.idea/misc.xml
generated
5
.idea/misc.xml
generated
@@ -1,5 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK" />
|
|
||||||
</project>
|
|
||||||
124
.idea/uiDesigner.xml
generated
124
.idea/uiDesigner.xml
generated
@@ -1,124 +0,0 @@
|
|||||||
<?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>
|
|
||||||
6
.idea/vcs.xml
generated
6
.idea/vcs.xml
generated
@@ -1,6 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="VcsDirectoryMappings">
|
|
||||||
<mapping directory="" vcs="Git" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
88
.idea/workspace.xml
generated
88
.idea/workspace.xml
generated
@@ -1,88 +0,0 @@
|
|||||||
<?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>
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 184 KiB |
@@ -1,5 +1,8 @@
|
|||||||
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!";
|
||||||
@@ -7,7 +10,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(
|
||||||
@@ -46,16 +49,9 @@ 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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package sudoku;
|
package sudoku;
|
||||||
|
|
||||||
|
import sudoku.core.Console;
|
||||||
|
|
||||||
public class ContrainteBloc implements Contrainte {
|
public class ContrainteBloc implements Contrainte {
|
||||||
@Override
|
@Override
|
||||||
public boolean estRespectee(Grille grille, Case c) {
|
public boolean estRespectee(Grille grille, Case c) {
|
||||||
@@ -12,6 +14,7 @@ public class ContrainteBloc implements Contrainte {
|
|||||||
for (int j = 0; j < blocSize; j++) {
|
for (int j = 0; j < blocSize; j++) {
|
||||||
Case currentCase = grille.getCase(startRow + i, startCol + j);
|
Case currentCase = grille.getCase(startRow + i, startCol + j);
|
||||||
if (currentCase != c && currentCase.getSymbole() != null && currentCase.getSymbole().equals(symbole)) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package sudoku;
|
package sudoku;
|
||||||
|
|
||||||
|
import sudoku.core.Console;
|
||||||
|
|
||||||
public class ContrainteColonne implements Contrainte {
|
public class ContrainteColonne implements Contrainte {
|
||||||
@Override
|
@Override
|
||||||
public boolean estRespectee(Grille grille, Case c) {
|
public boolean estRespectee(Grille grille, Case c) {
|
||||||
@@ -8,6 +10,7 @@ public class ContrainteColonne implements Contrainte {
|
|||||||
for (int ligne = 0; ligne < grille.getTaille(); ligne++) {
|
for (int ligne = 0; ligne < grille.getTaille(); ligne++) {
|
||||||
Case currentCase = grille.getCase(ligne, colonne);
|
Case currentCase = grille.getCase(ligne, colonne);
|
||||||
if (currentCase != c && currentCase.getSymbole() != null && currentCase.getSymbole().equals(symbole)) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package sudoku;
|
package sudoku;
|
||||||
|
|
||||||
|
import sudoku.core.Console;
|
||||||
|
|
||||||
public class ContrainteLigne implements Contrainte {
|
public class ContrainteLigne implements Contrainte {
|
||||||
@Override
|
@Override
|
||||||
public boolean estRespectee(Grille grille, Case c) {
|
public boolean estRespectee(Grille grille, Case c) {
|
||||||
@@ -8,6 +10,7 @@ public class ContrainteLigne implements Contrainte {
|
|||||||
for (int col = 0; col < grille.getTaille(); col++) {
|
for (int col = 0; col < grille.getTaille(); col++) {
|
||||||
Case currentCase = grille.getCase(ligne, col);
|
Case currentCase = grille.getCase(ligne, col);
|
||||||
if (currentCase != c && currentCase.getSymbole() != null && currentCase.getSymbole().equals(symbole)) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ 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;
|
||||||
@@ -12,14 +11,12 @@ public class Grille {
|
|||||||
private final Case[][] cases;
|
private final Case[][] cases;
|
||||||
private final ArrayList<Bloc> blocs;
|
private final ArrayList<Bloc> blocs;
|
||||||
private ArrayList<Symbole> symbolesPossibles;
|
private ArrayList<Symbole> symbolesPossibles;
|
||||||
private final Sudoku sudoku;
|
|
||||||
|
|
||||||
public Grille(int taille, Sudoku sudoku) {
|
public Grille(int taille) {
|
||||||
this.taille = taille;
|
this.taille = taille;
|
||||||
this.cases = new Case[taille][taille];
|
this.cases = new Case[taille][taille];
|
||||||
this.blocs = new ArrayList<>();
|
this.blocs = new ArrayList<>();
|
||||||
this.symbolesPossibles = new ArrayList<>();
|
this.symbolesPossibles = new ArrayList<>();
|
||||||
this.sudoku = sudoku;
|
|
||||||
|
|
||||||
// Initialiser les cases
|
// Initialiser les cases
|
||||||
for (int i = 0; i < taille; i++) {
|
for (int i = 0; i < taille; i++) {
|
||||||
@@ -34,22 +31,11 @@ public class Grille {
|
|||||||
if (symbole != null && !symbolesPossibles.contains(symbole)) {
|
if (symbole != null && !symbolesPossibles.contains(symbole)) {
|
||||||
throw new IllegalArgumentException("Symbole non autorisé : " + 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);
|
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) {
|
} catch (Exception e) {
|
||||||
Console.errorln(e.getMessage());
|
Console.errorln(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Case getCase(int ligne, int colonne) {
|
public Case getCase(int ligne, int colonne) {
|
||||||
@@ -63,10 +49,9 @@ public class Grille {
|
|||||||
"\u001B[33m" // Jaune
|
"\u001B[33m" // Jaune
|
||||||
};
|
};
|
||||||
|
|
||||||
private int getCouleurDisponible(int blocRow, int blocCol, int blocHeight, int blocWidth) {
|
private int getCouleurDisponible(int blocRow, int blocCol) {
|
||||||
List<Integer> couleursUtilisees = new ArrayList<>();
|
List<Integer> couleursUtilisees = new ArrayList<>();
|
||||||
int blocsParLigne = taille / blocWidth;
|
int blocSize = (int) Math.sqrt(taille);
|
||||||
int blocsParColonne = taille / blocHeight;
|
|
||||||
|
|
||||||
// Parcourir les voisins (haut, bas, gauche, droite, et diagonaux)
|
// Parcourir les voisins (haut, bas, gauche, droite, et diagonaux)
|
||||||
for (int dRow = -1; dRow <= 1; dRow++) {
|
for (int dRow = -1; dRow <= 1; dRow++) {
|
||||||
@@ -78,9 +63,9 @@ public class Grille {
|
|||||||
int voisinCol = blocCol + dCol;
|
int voisinCol = blocCol + dCol;
|
||||||
|
|
||||||
// Vérifier si le voisin est dans les limites
|
// Vérifier si le voisin est dans les limites
|
||||||
if (voisinRow >= 0 && voisinRow < blocsParColonne &&
|
if (voisinRow >= 0 && voisinRow < taille / blocSize &&
|
||||||
voisinCol >= 0 && voisinCol < blocsParLigne) {
|
voisinCol >= 0 && voisinCol < taille / blocSize) {
|
||||||
int blockIndex = voisinRow * blocsParLigne + voisinCol;
|
int blockIndex = voisinRow * (taille / blocSize) + voisinCol;
|
||||||
if (blockIndex < blocs.size()) {
|
if (blockIndex < blocs.size()) {
|
||||||
couleursUtilisees.add(blocs.get(blockIndex).getCouleurIndex());
|
couleursUtilisees.add(blocs.get(blockIndex).getCouleurIndex());
|
||||||
}
|
}
|
||||||
@@ -117,55 +102,18 @@ public class Grille {
|
|||||||
* @param positions
|
* @param positions
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public void creerBlocPersonnalise(List<int[]> positions) {
|
public Bloc creerBloc(List<int[]> positions) {
|
||||||
try {
|
int i = positions.get(0)[0];
|
||||||
// Validation des positions
|
int j = positions.get(0)[1];
|
||||||
for (int[] pos : positions) {
|
int blocSize = (int) Math.sqrt(taille);
|
||||||
if (pos[0] < 0 || pos[0] >= taille || pos[1] < 0 || pos[1] >= taille) {
|
int couleurIndex = getCouleurDisponible(i / blocSize, j / blocSize);
|
||||||
throw new IllegalArgumentException("Position invalide : (" + pos[0] + ", " + pos[1] + ")");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Collecter les couleurs des blocs voisins
|
Bloc bloc = new Bloc(QUATRE_COULEURS[couleurIndex], couleurIndex);
|
||||||
List<Integer> couleursVoisines = new ArrayList<>();
|
for (int[] pos : positions) {
|
||||||
for (int[] pos : positions) {
|
bloc.ajouterCase(cases[pos[0]][pos[1]]);
|
||||||
// Vérifier les cases adjacentes
|
|
||||||
int[][] directions = { { -1, 0 }, { 1, 0 }, { 0, -1 }, { 0, 1 } };
|
|
||||||
for (int[] dir : directions) {
|
|
||||||
int neighborRow = pos[0] + dir[0];
|
|
||||||
int neighborCol = pos[1] + dir[1];
|
|
||||||
if (neighborRow >= 0 && neighborRow < taille && neighborCol >= 0 && neighborCol < taille) {
|
|
||||||
Case neighborCase = cases[neighborRow][neighborCol];
|
|
||||||
Bloc neighborBloc = findBlocForCase(neighborCase);
|
|
||||||
if (neighborBloc != null) {
|
|
||||||
couleursVoisines.add(neighborBloc.getCouleurIndex());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Trouver une couleur disponible
|
|
||||||
int couleurIndex = -1;
|
|
||||||
for (int c = 0; c < QUATRE_COULEURS.length; c++) {
|
|
||||||
if (!couleursVoisines.contains(c)) {
|
|
||||||
couleurIndex = c;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (couleurIndex == -1) {
|
|
||||||
couleurIndex = 0; // Fallback
|
|
||||||
}
|
|
||||||
|
|
||||||
// Créer et ajouter le bloc
|
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
|
blocs.add(bloc);
|
||||||
|
return bloc;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void creerBlocCarre() {
|
public void creerBlocCarre() {
|
||||||
@@ -190,55 +138,7 @@ public class Grille {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int couleurIndex = getCouleurDisponible(blocRow, blocCol, blocSize, blocSize);
|
int couleurIndex = getCouleurDisponible(blocRow, blocCol);
|
||||||
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);
|
Bloc bloc = new Bloc(QUATRE_COULEURS[couleurIndex], couleurIndex);
|
||||||
|
|
||||||
for (int[] pos : positions) {
|
for (int[] pos : positions) {
|
||||||
@@ -317,9 +217,6 @@ 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);
|
||||||
}
|
}
|
||||||
@@ -327,10 +224,13 @@ 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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -366,7 +266,6 @@ public class Grille {
|
|||||||
/**
|
/**
|
||||||
* Vérifie si toutes les contraintes sont respectées
|
* Vérifie si toutes les contraintes sont respectées
|
||||||
* S'arrête dès qu'une contrainte n'est pas respectée
|
* S'arrête dès qu'une contrainte n'est pas respectée
|
||||||
*
|
|
||||||
* @param contraintes
|
* @param contraintes
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@@ -380,8 +279,7 @@ public class Grille {
|
|||||||
// Vérifier toutes les contraintes pour cette case
|
// Vérifier toutes les contraintes pour cette case
|
||||||
for (Contrainte contrainte : contraintes) {
|
for (Contrainte contrainte : contraintes) {
|
||||||
if (!contrainte.estRespectee(this, currentCase)) {
|
if (!contrainte.estRespectee(this, currentCase)) {
|
||||||
Console.errorln(
|
Console.errorln("Contrainte non respectée à la position : ligne=" + i + ", colonne=" + j);
|
||||||
"GRILLE: Contrainte non respectée à la position : ligne=" + i + ", colonne=" + j);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -391,53 +289,7 @@ public class Grille {
|
|||||||
return true;
|
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
|
@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() {
|
public String toString() {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
package sudoku;
|
|
||||||
|
|
||||||
public interface Resolveur {
|
|
||||||
boolean resoudre(Sudoku s, boolean afficherEtape);
|
|
||||||
}
|
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,19 +1,14 @@
|
|||||||
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;
|
||||||
private final List<Contrainte> contraintes;
|
private final List<Contrainte> contraintes;
|
||||||
|
|
||||||
public Sudoku(int taille) {
|
public Sudoku(int taille) {
|
||||||
this.grille = new Grille(taille, this);
|
this.grille = new Grille(taille);
|
||||||
this.contraintes = new ArrayList<>();
|
this.contraintes = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -21,9 +16,9 @@ public class Sudoku {
|
|||||||
contraintes.add(contrainte);
|
contraintes.add(contrainte);
|
||||||
}
|
}
|
||||||
|
|
||||||
// public void creerBloc(List<int[]> positions, int blocHeight, int blocWidth) {
|
public void creerBloc(List<int[]> positions) {
|
||||||
// grille.creerBloc(positions, blocHeight, blocWidth);
|
grille.creerBloc(positions);
|
||||||
// }
|
}
|
||||||
|
|
||||||
public boolean estValide(Case c) {
|
public boolean estValide(Case c) {
|
||||||
for (Contrainte contrainte : contraintes) {
|
for (Contrainte contrainte : contraintes) {
|
||||||
@@ -41,208 +36,4 @@ 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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -48,8 +48,4 @@ public class Symbole {
|
|||||||
Symbole symbole = (Symbole) obj;
|
Symbole symbole = (Symbole) obj;
|
||||||
return valeur.equals(symbole.valeur);
|
return valeur.equals(symbole.valeur);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getHashCode() {
|
|
||||||
return valeur.hashCode();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,69 +0,0 @@
|
|||||||
package sudoku;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
public class TestBlocParticuliers {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void blocParticuliers() {
|
|
||||||
System.out.println("TEST BLOC PARTICULIERS : ");
|
|
||||||
System.out.println(new App().getGreeting());
|
|
||||||
// Create a new Sudoku
|
|
||||||
Sudoku sudoku = new Sudoku(4);
|
|
||||||
|
|
||||||
sudoku.getGrille().setSymbolesPossibles(new ArrayList<>(Arrays.asList(
|
|
||||||
Symbole.of(1),
|
|
||||||
Symbole.of(2),
|
|
||||||
Symbole.of(3),
|
|
||||||
Symbole.of(4))));
|
|
||||||
|
|
||||||
sudoku.ajouterContrainte(new ContrainteBloc());
|
|
||||||
sudoku.ajouterContrainte(new ContrainteLigne());
|
|
||||||
sudoku.ajouterContrainte(new ContrainteColonne());
|
|
||||||
|
|
||||||
sudoku.getGrille().setCase(0, 0, Symbole.of(1));
|
|
||||||
sudoku.getGrille().setCase(3, 1, Symbole.of(2));
|
|
||||||
sudoku.getGrille().setCase(2, 2, Symbole.of(3));
|
|
||||||
|
|
||||||
sudoku.getGrille().creerBlocPersonnalise(Arrays.asList(
|
|
||||||
new int[] { 0, 0 },
|
|
||||||
new int[] { 3, 3 },
|
|
||||||
new int[] { 0, 1 },
|
|
||||||
new int[] { 2, 3 }));
|
|
||||||
sudoku.getGrille().creerBlocPersonnalise(Arrays.asList(
|
|
||||||
new int[] { 0, 2 },
|
|
||||||
new int[] { 1, 3 },
|
|
||||||
new int[] { 1, 2 },
|
|
||||||
new int[] { 3, 1 }));
|
|
||||||
sudoku.getGrille().creerBlocPersonnalise(Arrays.asList(
|
|
||||||
new int[] { 1, 1 },
|
|
||||||
new int[] { 1, 0 },
|
|
||||||
new int[] { 0, 3 },
|
|
||||||
new int[] { 3, 0 }));
|
|
||||||
sudoku.getGrille().creerBlocPersonnalise(Arrays.asList(
|
|
||||||
new int[] { 2, 0 },
|
|
||||||
new int[] { 2, 1 },
|
|
||||||
new int[] { 2, 2 },
|
|
||||||
new int[] { 3, 2 }));
|
|
||||||
|
|
||||||
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, true);
|
|
||||||
|
|
||||||
System.out.println("Sudoku résolu :");
|
|
||||||
System.out.println(sudoku.getGrille().toString());
|
|
||||||
|
|
||||||
System.out.println("FIN TEST BLOC PARTICULIERS");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
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");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,97 +0,0 @@
|
|||||||
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");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,6 +2,8 @@ package sudoku;
|
|||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
@@ -36,6 +38,7 @@ public class TestLigne {
|
|||||||
sudoku.getGrille().setCase(4, 8, Symbole.of(9));
|
sudoku.getGrille().setCase(4, 8, Symbole.of(9));
|
||||||
//doublon ligne
|
//doublon ligne
|
||||||
sudoku.getGrille().setCase(0, 4, Symbole.of(1));
|
sudoku.getGrille().setCase(0, 4, Symbole.of(1));
|
||||||
|
assertFalse(sudoku.estValide(sudoku.getGrille().getCase(0, 4)));
|
||||||
|
|
||||||
sudoku.getGrille().creerBlocCarre();
|
sudoku.getGrille().creerBlocCarre();
|
||||||
|
|
||||||
|
|||||||
@@ -1,70 +0,0 @@
|
|||||||
// 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");
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
// 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");
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
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
|
Before Width: | Height: | Size: 97 KiB |
File diff suppressed because one or more lines are too long
|
Before Width: | Height: | Size: 86 KiB |
@@ -1,131 +0,0 @@
|
|||||||
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