This commit is contained in:
5
.gitignore
vendored
5
.gitignore
vendored
@@ -3,3 +3,8 @@
|
|||||||
|
|
||||||
# Ignore Gradle build output directory
|
# Ignore Gradle build output directory
|
||||||
build
|
build
|
||||||
|
|
||||||
|
.vscode
|
||||||
|
.idea
|
||||||
|
|
||||||
|
output.puml
|
||||||
@@ -22,6 +22,9 @@ dependencies {
|
|||||||
|
|
||||||
// This dependency is used by the application.
|
// This dependency is used by the application.
|
||||||
implementation 'com.google.guava:guava:31.1-jre'
|
implementation 'com.google.guava:guava:31.1-jre'
|
||||||
|
|
||||||
|
// uml
|
||||||
|
implementation 'com.github.javaparser:javaparser-symbol-solver-core:3.26.2'
|
||||||
}
|
}
|
||||||
|
|
||||||
application {
|
application {
|
||||||
|
|||||||
@@ -1,14 +1,16 @@
|
|||||||
package sudoku;
|
package sudoku;
|
||||||
|
|
||||||
public class Bloc<S> {
|
import java.util.List;
|
||||||
|
|
||||||
private final Case<S>[] cases;
|
public class Bloc {
|
||||||
|
|
||||||
public Bloc(Case<S>[] cases) {
|
private final List<Case> cases;
|
||||||
|
|
||||||
|
public Bloc(List<Case> cases) {
|
||||||
this.cases = cases;
|
this.cases = cases;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Case<S>[] getCases() {
|
public List<Case> getCases() {
|
||||||
return cases;
|
return cases;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,46 @@
|
|||||||
package sudoku;
|
package sudoku;
|
||||||
|
|
||||||
public class Case<S> {
|
public class Case {
|
||||||
|
|
||||||
private Symbole<S> symbole;
|
private static int NOSYMBOLE = -1;
|
||||||
|
private int symboleIndex;
|
||||||
|
private Bloc bloc = null;
|
||||||
|
|
||||||
public Case(Symbole<S> symbole) {
|
public Case(int symboleIndex) {
|
||||||
this.symbole = symbole;
|
this.symboleIndex = symboleIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Symbole<S> getSymbole() {
|
/**
|
||||||
return this.symbole;
|
* @brief Default constructor, empty square
|
||||||
|
*/
|
||||||
|
public Case() {
|
||||||
|
this(NOSYMBOLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSymbole(Symbole<S> symbole) {
|
public int getSymboleIndex() {
|
||||||
this.symbole = symbole;
|
return symboleIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSymboleIndex(int symboleIndex) {
|
||||||
|
this.symboleIndex = symboleIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clear() {
|
||||||
|
setSymboleIndex(NOSYMBOLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Bloc getBloc() {
|
||||||
|
return this.bloc;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setBloc(Bloc bloc) {
|
||||||
|
this.bloc = bloc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (obj instanceof Case autreCase)
|
||||||
|
return autreCase.getSymboleIndex() == this.getSymboleIndex();
|
||||||
|
return super.equals(obj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,5 +10,6 @@ public class Main {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
System.out.println(new Main().getGreeting());
|
System.out.println(new Main().getGreeting());
|
||||||
|
// var test = SudokuFactory.createBasicEmptySudoku(9);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package sudoku;
|
package sudoku;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -8,12 +7,12 @@ import java.util.List;
|
|||||||
* @brief Représente une grille de Multidoku.
|
* @brief Représente une grille de Multidoku.
|
||||||
* Une grille de sudoku est un multidoku avec un seul sous-sudoku
|
* Une grille de sudoku est un multidoku avec un seul sous-sudoku
|
||||||
*/
|
*/
|
||||||
public class MultiDoku<S> {
|
public class MultiDoku {
|
||||||
|
|
||||||
private final List<Sudoku<S>> sousGrilles;
|
private final List<Sudoku> sousGrilles;
|
||||||
|
|
||||||
public MultiDoku(List<Symbole<S>> symboles) {
|
public MultiDoku(List<Sudoku> sousGrilles) {
|
||||||
this.sousGrilles = new ArrayList<>();
|
this.sousGrilles = sousGrilles;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,27 +1,36 @@
|
|||||||
package sudoku;
|
package sudoku;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @class Sudoku
|
* @class Sudoku
|
||||||
* @brief Représente une grille de sudoku avec N symboles
|
* @brief Représente une grille de sudoku avec N symboles
|
||||||
*/
|
*/
|
||||||
public class Sudoku<S> {
|
public class Sudoku {
|
||||||
|
|
||||||
private final List<Symbole<S>> symboles;
|
private final List<Bloc> blocs;
|
||||||
private final List<Bloc<S>> blocs;
|
private final List<Case> cases;
|
||||||
private final List<Case<S>> cases;
|
|
||||||
|
|
||||||
public Sudoku(List<Symbole<S>> symboles) {
|
public Sudoku(List<Case> cases, List<Bloc> blocs) {
|
||||||
this.symboles = symboles;
|
// assert(symbolCount >= 2);
|
||||||
// initialisation des cases
|
// // initialisation des cases
|
||||||
this.cases = new ArrayList<>(this.symboles.size() * this.symboles.size());
|
// this.cases = new ArrayList<>(symbolCount * symbolCount);
|
||||||
Collections.fill(this.cases, new Case<>(null));
|
// Collections.fill(this.cases, new Case());
|
||||||
// initialisation des blocs
|
// // initialisation des blocs
|
||||||
this.blocs = new ArrayList<>(this.symboles.size());
|
// this.blocs = new ArrayList<>(symbolCount);
|
||||||
Collections.fill(this.blocs, new Bloc<>(null));
|
// Collections.fill(this.blocs, new Bloc(null));
|
||||||
|
this.cases = cases;
|
||||||
|
this.blocs = blocs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Case getCase(int x, int y) {
|
||||||
|
int index = y * getSize() + x;
|
||||||
|
assert(index < getSize() * getSize());
|
||||||
|
return this.cases.get(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSize() {
|
||||||
|
return this.blocs.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
package sudoku;
|
|
||||||
|
|
||||||
public class Symbole<S> {
|
|
||||||
|
|
||||||
private final S valeur;
|
|
||||||
|
|
||||||
public Symbole(S valeur) {
|
|
||||||
this.valeur = valeur;
|
|
||||||
}
|
|
||||||
|
|
||||||
public S getValeur() {
|
|
||||||
return valeur;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
15
app/src/main/java/sudoku/constraint/BlockConstraint.java
Normal file
15
app/src/main/java/sudoku/constraint/BlockConstraint.java
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
package sudoku.constraint;
|
||||||
|
|
||||||
|
import sudoku.Bloc;
|
||||||
|
import sudoku.Case;
|
||||||
|
import sudoku.Sudoku;
|
||||||
|
|
||||||
|
public class BlockConstraint implements IConstraint{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canBePlaced(final Sudoku s, int x, int y, int newSymbolIndex) {
|
||||||
|
Bloc bloc = s.getCase(x, y).getBloc();
|
||||||
|
return !bloc.getCases().contains(new Case(newSymbolIndex));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
16
app/src/main/java/sudoku/constraint/ColumnConstraint.java
Normal file
16
app/src/main/java/sudoku/constraint/ColumnConstraint.java
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
package sudoku.constraint;
|
||||||
|
|
||||||
|
import sudoku.Sudoku;
|
||||||
|
|
||||||
|
public class ColumnConstraint implements IConstraint {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canBePlaced(final Sudoku s, int x, int y, int newSymbolIndex) {
|
||||||
|
for (int i = 0; i < s.getSize(); i++) {
|
||||||
|
if (s.getCase(x, newSymbolIndex).getSymboleIndex() == newSymbolIndex)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
22
app/src/main/java/sudoku/constraint/IConstraint.java
Normal file
22
app/src/main/java/sudoku/constraint/IConstraint.java
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
package sudoku.constraint;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import sudoku.Sudoku;
|
||||||
|
|
||||||
|
public interface IConstraint {
|
||||||
|
|
||||||
|
boolean canBePlaced(final Sudoku s, int x, int y, int newSymbolIndex);
|
||||||
|
|
||||||
|
default List<Integer> getPossibleSymbols(final Sudoku s, int x, int y) {
|
||||||
|
List<Integer> possibilities = new ArrayList<>();
|
||||||
|
for (int i = 0; i < s.getSize(); i++) {
|
||||||
|
if (canBePlaced(s, x, y, i)) {
|
||||||
|
possibilities.add(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return possibilities;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
16
app/src/main/java/sudoku/constraint/LineConstraint.java
Normal file
16
app/src/main/java/sudoku/constraint/LineConstraint.java
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
package sudoku.constraint;
|
||||||
|
|
||||||
|
import sudoku.Sudoku;
|
||||||
|
|
||||||
|
public class LineConstraint implements IConstraint {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canBePlaced(final Sudoku s, int x, int y, int newSymbolIndex) {
|
||||||
|
for (int i = 0; i < s.getSize(); i++) {
|
||||||
|
if (s.getCase(newSymbolIndex, y).getSymboleIndex() == newSymbolIndex)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
BIN
java2plantuml.jar
Normal file
BIN
java2plantuml.jar
Normal file
Binary file not shown.
Reference in New Issue
Block a user