This commit is contained in:
@@ -3,6 +3,9 @@ package sudoku.constraint;
|
|||||||
import sudoku.structure.Block;
|
import sudoku.structure.Block;
|
||||||
import sudoku.structure.Sudoku;
|
import sudoku.structure.Sudoku;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contrainte de bloc
|
||||||
|
*/
|
||||||
public class BlockConstraint implements IConstraint{
|
public class BlockConstraint implements IConstraint{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -3,6 +3,9 @@ package sudoku.constraint;
|
|||||||
import sudoku.structure.Cell;
|
import sudoku.structure.Cell;
|
||||||
import sudoku.structure.Sudoku;
|
import sudoku.structure.Sudoku;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contrainte de colonne
|
||||||
|
*/
|
||||||
public class ColumnConstraint implements IConstraint {
|
public class ColumnConstraint implements IConstraint {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package sudoku.constraint;
|
package sudoku.constraint;
|
||||||
|
|
||||||
import java.util.List;
|
/**
|
||||||
|
* Enumération utilisée afin de simplifier l'affichage en graphique.
|
||||||
import sudoku.structure.Sudoku;
|
* Un sudoku peut tout de même contenir des contraintes qui ne sont pas dans cette énumération.
|
||||||
|
*/
|
||||||
public enum Constraint {
|
public enum Constraint {
|
||||||
|
|
||||||
Block("Bloc", new BlockConstraint()),
|
Block("Bloc", new BlockConstraint()),
|
||||||
@@ -19,14 +19,6 @@ public enum Constraint {
|
|||||||
this.displayName = displayName;
|
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() {
|
public String getDisplayName() {
|
||||||
return displayName;
|
return displayName;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,9 @@ package sudoku.constraint;
|
|||||||
|
|
||||||
import sudoku.structure.Sudoku;
|
import sudoku.structure.Sudoku;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contrainte de diagonale
|
||||||
|
*/
|
||||||
public class DiagonalConstraint implements IConstraint {
|
public class DiagonalConstraint implements IConstraint {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,22 +1,12 @@
|
|||||||
package sudoku.constraint;
|
package sudoku.constraint;
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import sudoku.structure.Sudoku;
|
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);
|
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;
|
import sudoku.structure.Sudoku;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contrainte de ligne
|
||||||
|
*/
|
||||||
public class LineConstraint implements IConstraint {
|
public class LineConstraint implements IConstraint {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user