This commit is contained in:
@@ -3,6 +3,9 @@ package sudoku.constraint;
|
||||
import sudoku.structure.Block;
|
||||
import sudoku.structure.Sudoku;
|
||||
|
||||
/**
|
||||
* Contrainte de bloc
|
||||
*/
|
||||
public class BlockConstraint implements IConstraint{
|
||||
|
||||
@Override
|
||||
|
||||
@@ -3,6 +3,9 @@ package sudoku.constraint;
|
||||
import sudoku.structure.Cell;
|
||||
import sudoku.structure.Sudoku;
|
||||
|
||||
/**
|
||||
* Contrainte de colonne
|
||||
*/
|
||||
public class ColumnConstraint implements IConstraint {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package sudoku.constraint;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import sudoku.structure.Sudoku;
|
||||
|
||||
/**
|
||||
* Enumération utilisée afin de simplifier l'affichage en graphique.
|
||||
* Un sudoku peut tout de même contenir des contraintes qui ne sont pas dans cette énumération.
|
||||
*/
|
||||
public enum Constraint {
|
||||
|
||||
Block("Bloc", new BlockConstraint()),
|
||||
@@ -19,14 +19,6 @@ public enum Constraint {
|
||||
this.displayName = displayName;
|
||||
}
|
||||
|
||||
public boolean canBePlaced(Sudoku s, int x, int y, int newValue) {
|
||||
return getConstraint().canBePlaced(s, x, y, newValue);
|
||||
}
|
||||
|
||||
public List<Integer> getPossibleSymbols(final Sudoku s, int x, int y) {
|
||||
return getConstraint().getPossibleSymbols(s, x, y);
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
return displayName;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,9 @@ package sudoku.constraint;
|
||||
|
||||
import sudoku.structure.Sudoku;
|
||||
|
||||
/**
|
||||
* Contrainte de diagonale
|
||||
*/
|
||||
public class DiagonalConstraint implements IConstraint {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,22 +1,12 @@
|
||||
package sudoku.constraint;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import sudoku.structure.Sudoku;
|
||||
|
||||
public interface IConstraint extends Serializable {
|
||||
/**
|
||||
* Interface de base pour la déclaration d'une contrainte
|
||||
* Elle est en théorie assez générique pour implémenter n'importe quelle
|
||||
* contrainte
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,9 @@ package sudoku.constraint;
|
||||
|
||||
import sudoku.structure.Sudoku;
|
||||
|
||||
/**
|
||||
* Contrainte de ligne
|
||||
*/
|
||||
public class LineConstraint implements IConstraint {
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user