doc : Block, Cell, Coordiante, MultiDoku
Some checks failed
Linux arm64 / Build (push) Has been cancelled
Some checks failed
Linux arm64 / Build (push) Has been cancelled
This commit is contained in:
@@ -3,11 +3,21 @@ package sudoku.structure;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class qui représente les block de chaque sudoku,
|
||||||
|
* Un block étant un ensemble de cellule avec une contrainte de block qui lui ait associé
|
||||||
|
*/
|
||||||
public class Block {
|
public class Block {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* L'ensemble des cellules du block
|
||||||
|
*/
|
||||||
private final List<Cell> cells;
|
private final List<Cell> cells;
|
||||||
|
|
||||||
// faster access to the sudoku
|
/**
|
||||||
|
* List de sudoku qui contiennent le block
|
||||||
|
* Pour un acces plus rapide aux sudokus
|
||||||
|
*/
|
||||||
private List<Sudoku> sudokus;
|
private List<Sudoku> sudokus;
|
||||||
|
|
||||||
public Block(List<Cell> cells) {
|
public Block(List<Cell> cells) {
|
||||||
@@ -22,10 +32,19 @@ public class Block {
|
|||||||
return cells;
|
return cells;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ajoute une Cell au Block
|
||||||
|
* @param newCell Cell, à ajouter
|
||||||
|
*/
|
||||||
void addCell(Cell newCell) {
|
void addCell(Cell newCell) {
|
||||||
this.cells.add(newCell);
|
this.cells.add(newCell);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cherche si le Block contient déjà un symbole donné.
|
||||||
|
* @param symbolIndex int, un index de symbole
|
||||||
|
* @return boolean, true s'il contient le symbole et false sinon
|
||||||
|
*/
|
||||||
public boolean containsSymbol(int symbolIndex) {
|
public boolean containsSymbol(int symbolIndex) {
|
||||||
for (Cell cell : getCells()) {
|
for (Cell cell : getCells()) {
|
||||||
if (cell.getSymbolIndex() == symbolIndex)
|
if (cell.getSymbolIndex() == symbolIndex)
|
||||||
|
|||||||
@@ -3,13 +3,35 @@ package sudoku.structure;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Représente une case d'un, ou plusieurs, sudoku qui à comme valeur un index de symbole.
|
||||||
|
* Celui ci pourra être remplacer par un symbole en temps voulu.
|
||||||
|
*/
|
||||||
public class Cell {
|
public class Cell {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constante de valeur d'index de symbole quand il n'y en a pas,
|
||||||
|
* soit que la Cell est vide.
|
||||||
|
*/
|
||||||
public static int NOSYMBOL = -1;
|
public static int NOSYMBOL = -1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Block dans lequel est la Cell.
|
||||||
|
*/
|
||||||
private Block blockContainer;
|
private Block blockContainer;
|
||||||
|
/**
|
||||||
|
* L'index du symbole que contient la Cell.
|
||||||
|
* Il est initialisé à Cell.NOSYMBOL.
|
||||||
|
*/
|
||||||
private int symbolIndex = Cell.NOSYMBOL;
|
private int symbolIndex = Cell.NOSYMBOL;
|
||||||
|
/**
|
||||||
|
* Liste des index de symbole possibles pour cette Cell,
|
||||||
|
* en fonction des contraintes de sudoku dans lequel elle est.
|
||||||
|
*/
|
||||||
private final List<Integer> possibleSymbols;
|
private final List<Integer> possibleSymbols;
|
||||||
|
/**
|
||||||
|
* Si cette Cell peut être modififié ou non.
|
||||||
|
*/
|
||||||
private boolean isMutable = true;
|
private boolean isMutable = true;
|
||||||
|
|
||||||
public Cell() {
|
public Cell() {
|
||||||
@@ -40,6 +62,9 @@ public class Cell {
|
|||||||
this.possibleSymbols.addAll(possibleSymbols);
|
this.possibleSymbols.addAll(possibleSymbols);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rend la Cell immuable.
|
||||||
|
*/
|
||||||
public void setImmutable() {
|
public void setImmutable() {
|
||||||
this.isMutable = false;
|
this.isMutable = false;
|
||||||
}
|
}
|
||||||
@@ -62,6 +87,10 @@ public class Cell {
|
|||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renvoie si la Cell est vide ou non.
|
||||||
|
* @return boolean, true si la Cell est vide, false sinon.
|
||||||
|
*/
|
||||||
public boolean isEmpty() {
|
public boolean isEmpty() {
|
||||||
return this.symbolIndex == Cell.NOSYMBOL;
|
return this.symbolIndex == Cell.NOSYMBOL;
|
||||||
}
|
}
|
||||||
@@ -74,10 +103,18 @@ public class Cell {
|
|||||||
return this.possibleSymbols;
|
return this.possibleSymbols;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renvoie si la Cell est modifiable
|
||||||
|
* @return boolean, true si elle est modifiable ou false sinon.
|
||||||
|
*/
|
||||||
public boolean isMutable() {
|
public boolean isMutable() {
|
||||||
return this.isMutable;
|
return this.isMutable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Vide la Cell, en renvoie l'ancien index du symbole qui était dedans.
|
||||||
|
* @return int, index du symbole anciennement contenue dans la Cell.
|
||||||
|
*/
|
||||||
public int empty() {
|
public int empty() {
|
||||||
int oldSymbol = this.symbolIndex;
|
int oldSymbol = this.symbolIndex;
|
||||||
this.symbolIndex = Cell.NOSYMBOL;
|
this.symbolIndex = Cell.NOSYMBOL;
|
||||||
|
|||||||
@@ -1,8 +1,17 @@
|
|||||||
package sudoku.structure;
|
package sudoku.structure;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Représente les coordonnées d'une Cell
|
||||||
|
*/
|
||||||
public class Coordinate {
|
public class Coordinate {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* L'abscisse de la Cell.
|
||||||
|
*/
|
||||||
private int x;
|
private int x;
|
||||||
|
/**
|
||||||
|
* L'ordonnée de la Cell.
|
||||||
|
*/
|
||||||
private int y;
|
private int y;
|
||||||
|
|
||||||
public Coordinate(int x, int y) {
|
public Coordinate(int x, int y) {
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package sudoku.structure;
|
package sudoku.structure;
|
||||||
|
|
||||||
import sudoku.constraint.IConstraint;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -12,20 +10,37 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class MultiDoku {
|
public class MultiDoku {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Liste des sous-Sudoku contenue dans le multidoku.
|
||||||
|
*/
|
||||||
private final List<Sudoku> subGrids;
|
private final List<Sudoku> subGrids;
|
||||||
|
|
||||||
public MultiDoku(List<Sudoku> subGrids) {
|
public MultiDoku(List<Sudoku> subGrids) {
|
||||||
this.subGrids = subGrids;
|
this.subGrids = subGrids;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renvoie le nombre de sudoku contenu dans ce MultiDoku.
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
public int getNbSubGrids(){
|
public int getNbSubGrids(){
|
||||||
return subGrids.size();
|
return subGrids.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renvoie la ie sudoku contenue dans ce MultiDoku.
|
||||||
|
* @param i int, indice du sudoku à renvoyer.
|
||||||
|
* @return Sudoku, ie Sudoku
|
||||||
|
*/
|
||||||
public Sudoku getSubGrid(int i){
|
public Sudoku getSubGrid(int i){
|
||||||
return subGrids.get(i);
|
return subGrids.get(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renvoie la liste des Cells contenue dans ce MultiDoku,
|
||||||
|
* soit les Cells contenues de chaques sous-Sudoku.
|
||||||
|
* @return List<Cell>
|
||||||
|
*/
|
||||||
public List<Cell> getCells(){
|
public List<Cell> getCells(){
|
||||||
List<Cell> cells = new ArrayList<>();
|
List<Cell> cells = new ArrayList<>();
|
||||||
for (Sudoku sudoku : subGrids){
|
for (Sudoku sudoku : subGrids){
|
||||||
@@ -34,6 +49,10 @@ public class MultiDoku {
|
|||||||
return cells;
|
return cells;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Met à jour les symboles possibles de chaque Cell.
|
||||||
|
* @throws Exception, si ce n'est pas possible.
|
||||||
|
*/
|
||||||
public void updateSymbolsPossibilities() throws Exception {
|
public void updateSymbolsPossibilities() throws Exception {
|
||||||
for (Sudoku sudoku : subGrids){
|
for (Sudoku sudoku : subGrids){
|
||||||
sudoku.updateSymbolsPossibilities();
|
sudoku.updateSymbolsPossibilities();
|
||||||
@@ -51,16 +70,11 @@ public class MultiDoku {
|
|||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Cell getFirstEmptyCell() {
|
/**
|
||||||
for (Sudoku sudoku : this.subGrids) {
|
* Renvoie les symboles possibles d'une Cell donnée.
|
||||||
Cell cellTmp = sudoku.getFirstEmptyCell();
|
* @param cellToFill Cell.
|
||||||
if (cellTmp != null && cellTmp.isEmpty()) {
|
* @return List<Integer>, liste des symboles possible.
|
||||||
return cellTmp;
|
*/
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Integer> getPossibleSymbolsOfCell(Cell cellToFill) {
|
public List<Integer> getPossibleSymbolsOfCell(Cell cellToFill) {
|
||||||
List<Integer> result = new ArrayList<>();
|
List<Integer> result = new ArrayList<>();
|
||||||
boolean hasBeenFill = false;
|
boolean hasBeenFill = false;
|
||||||
@@ -78,10 +92,18 @@ public class MultiDoku {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renvoie les sous-Sudoku
|
||||||
|
* @return List<Sudoku>
|
||||||
|
*/
|
||||||
public List<Sudoku> getSubGrids() {
|
public List<Sudoku> getSubGrids() {
|
||||||
return this.subGrids;
|
return this.subGrids;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check si le MultiDoku est valide, en fonction de ses sous-Sudokus.
|
||||||
|
* @return boolean, true s'il est valide et false sinon.
|
||||||
|
*/
|
||||||
public boolean isValid() {
|
public boolean isValid() {
|
||||||
boolean result = true;
|
boolean result = true;
|
||||||
for (Sudoku sudoku : this.subGrids) {
|
for (Sudoku sudoku : this.subGrids) {
|
||||||
@@ -109,16 +131,38 @@ public class MultiDoku {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renvoie la 1re Cell vide des sous-Sudoku.
|
||||||
|
* @return Cell, une Cell vide, ou null s'il n'y en a pas.
|
||||||
|
*/
|
||||||
|
public Cell getFirstEmptyCell() {
|
||||||
|
for (Sudoku sudoku : this.subGrids) {
|
||||||
|
Cell cellTmp = sudoku.getFirstEmptyCell();
|
||||||
|
if (cellTmp != null && cellTmp.isEmpty()) {
|
||||||
|
return cellTmp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renvoie la liste des Cells préalablement remplies du MultiDoku.
|
||||||
|
* @return List<Cell>, vide si aucune Cell n'est remplie.
|
||||||
|
*/
|
||||||
public List<Cell> getFilledCells() {
|
public List<Cell> getFilledCells() {
|
||||||
List<Cell> result = new ArrayList<>();
|
List<Cell> result = new ArrayList<>();
|
||||||
for (Cell c : this.getCells()){
|
for (Cell cell : this.getCells()){
|
||||||
if (!c.isEmpty()) {
|
if (!cell.isEmpty()) {
|
||||||
result.add(c);
|
result.add(cell);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Vide une Cell donnée.
|
||||||
|
* @param cell Cell, à vider.
|
||||||
|
*/
|
||||||
public void empty(Cell cell) {
|
public void empty(Cell cell) {
|
||||||
List<Cell> cells = getCells();
|
List<Cell> cells = getCells();
|
||||||
Cell cellToEmpty = cells.get(cells.indexOf(cell));
|
Cell cellToEmpty = cells.get(cells.indexOf(cell));
|
||||||
|
|||||||
@@ -7,14 +7,25 @@ import java.util.List;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @class Sudoku
|
* @class Sudoku
|
||||||
* @brief Represents a sudoku
|
* @brief Représent un Sudoku
|
||||||
*/
|
*/
|
||||||
public class Sudoku {
|
public class Sudoku {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Liste des Block contenus dans le Sudoku.
|
||||||
|
*/
|
||||||
private final List<Block> blocks;
|
private final List<Block> blocks;
|
||||||
|
/**
|
||||||
|
* Liste des Cells contenus dans le Sudoku.
|
||||||
|
*/
|
||||||
private final List<Cell> cells;
|
private final List<Cell> cells;
|
||||||
|
/**
|
||||||
|
* Liste des contraintes (TODO) du Sudoku.
|
||||||
|
*/
|
||||||
private final List<IConstraint> constraints;
|
private final List<IConstraint> constraints;
|
||||||
private boolean isMutable;
|
/**
|
||||||
|
* Largeur des Blocks s'ils sont rectangulaires, sinon ça vaut 0.
|
||||||
|
*/
|
||||||
private int blockWidth;
|
private int blockWidth;
|
||||||
|
|
||||||
public Sudoku(List<Cell> cells, List<Block> blocks, List<IConstraint> constraints) {
|
public Sudoku(List<Cell> cells, List<Block> blocks, List<IConstraint> constraints) {
|
||||||
@@ -23,16 +34,29 @@ public class Sudoku {
|
|||||||
this.constraints = constraints;
|
this.constraints = constraints;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int[] toCoords(int index) {
|
/**
|
||||||
return new int[] { index % getSize(), index / getSize() };
|
* Transforme un index de Cell en Coordiante.
|
||||||
|
*
|
||||||
|
* @param index int, index d'une Cell.
|
||||||
|
* @return Coordinate, correspondante à l'index donné.
|
||||||
|
*/
|
||||||
|
public Coordinate toCoords(int index) {
|
||||||
|
return new Coordinate( index % getSize(), index / getSize() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transforme des coordonées d'une Cell en index.
|
||||||
|
* @param x int, abscisse.
|
||||||
|
* @param y int, ordonnée.
|
||||||
|
* @return int, index correspondant.
|
||||||
|
*/
|
||||||
public int toIndex(int x, int y) {
|
public int toIndex(int x, int y) {
|
||||||
return y * getSize() + x;
|
return y * getSize() + x;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return wether the coords are in the sudoku
|
* Vérifie que des coordonnées correspondent bien à une Cell dans le Sudoku.
|
||||||
|
* @return boolean, wether the coords are in the sudoku
|
||||||
*/
|
*/
|
||||||
public boolean isValidCoords(int x, int y) {
|
public boolean isValidCoords(int x, int y) {
|
||||||
int index = toIndex(x, y);
|
int index = toIndex(x, y);
|
||||||
|
|||||||
Reference in New Issue
Block a user