diff --git a/app/src/main/java/sudoku/structure/Block.java b/app/src/main/java/sudoku/structure/Block.java index 2fe28d4..356b20b 100644 --- a/app/src/main/java/sudoku/structure/Block.java +++ b/app/src/main/java/sudoku/structure/Block.java @@ -3,11 +3,21 @@ package sudoku.structure; import java.util.ArrayList; 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 { + /** + * L'ensemble des cellules du block + */ private final List cells; - // faster access to the sudoku + /** + * List de sudoku qui contiennent le block + * Pour un acces plus rapide aux sudokus + */ private List sudokus; public Block(List cells) { @@ -22,10 +32,19 @@ public class Block { return cells; } + /** + * Ajoute une Cell au Block + * @param newCell Cell, à ajouter + */ void addCell(Cell 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) { for (Cell cell : getCells()) { if (cell.getSymbolIndex() == symbolIndex) diff --git a/app/src/main/java/sudoku/structure/Cell.java b/app/src/main/java/sudoku/structure/Cell.java index 58e7aeb..3889282 100644 --- a/app/src/main/java/sudoku/structure/Cell.java +++ b/app/src/main/java/sudoku/structure/Cell.java @@ -3,13 +3,35 @@ package sudoku.structure; import java.util.ArrayList; 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 { + /** + * 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; + /** + * Block dans lequel est la Cell. + */ private Block blockContainer; + /** + * L'index du symbole que contient la Cell. + * Il est initialisé à 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 possibleSymbols; + /** + * Si cette Cell peut être modififié ou non. + */ private boolean isMutable = true; public Cell() { @@ -40,6 +62,9 @@ public class Cell { this.possibleSymbols.addAll(possibleSymbols); } + /** + * Rend la Cell immuable. + */ public void setImmutable() { this.isMutable = false; } @@ -62,6 +87,10 @@ public class Cell { return i; } + /** + * Renvoie si la Cell est vide ou non. + * @return boolean, true si la Cell est vide, false sinon. + */ public boolean isEmpty() { return this.symbolIndex == Cell.NOSYMBOL; } @@ -74,10 +103,18 @@ public class Cell { return this.possibleSymbols; } + /** + * Renvoie si la Cell est modifiable + * @return boolean, true si elle est modifiable ou false sinon. + */ public boolean 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() { int oldSymbol = this.symbolIndex; this.symbolIndex = Cell.NOSYMBOL; diff --git a/app/src/main/java/sudoku/structure/Coordinate.java b/app/src/main/java/sudoku/structure/Coordinate.java index 90164ff..40323f5 100644 --- a/app/src/main/java/sudoku/structure/Coordinate.java +++ b/app/src/main/java/sudoku/structure/Coordinate.java @@ -1,8 +1,17 @@ package sudoku.structure; +/** + * Représente les coordonnées d'une Cell + */ public class Coordinate { + /** + * L'abscisse de la Cell. + */ private int x; + /** + * L'ordonnée de la Cell. + */ private int y; public Coordinate(int x, int y) { diff --git a/app/src/main/java/sudoku/structure/MultiDoku.java b/app/src/main/java/sudoku/structure/MultiDoku.java index 6a78359..86c0bfb 100644 --- a/app/src/main/java/sudoku/structure/MultiDoku.java +++ b/app/src/main/java/sudoku/structure/MultiDoku.java @@ -1,7 +1,5 @@ package sudoku.structure; -import sudoku.constraint.IConstraint; - import java.util.ArrayList; import java.util.List; @@ -12,20 +10,37 @@ import java.util.List; */ public class MultiDoku { + /** + * Liste des sous-Sudoku contenue dans le multidoku. + */ private final List subGrids; public MultiDoku(List subGrids) { this.subGrids = subGrids; } + /** + * Renvoie le nombre de sudoku contenu dans ce MultiDoku. + * @return int + */ public int getNbSubGrids(){ 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){ return subGrids.get(i); } + /** + * Renvoie la liste des Cells contenue dans ce MultiDoku, + * soit les Cells contenues de chaques sous-Sudoku. + * @return List + */ public List getCells(){ List cells = new ArrayList<>(); for (Sudoku sudoku : subGrids){ @@ -34,6 +49,10 @@ public class MultiDoku { return cells; } + /** + * Met à jour les symboles possibles de chaque Cell. + * @throws Exception, si ce n'est pas possible. + */ public void updateSymbolsPossibilities() throws Exception { for (Sudoku sudoku : subGrids){ sudoku.updateSymbolsPossibilities(); @@ -51,16 +70,11 @@ public class MultiDoku { return sb.toString(); } - public Cell getFirstEmptyCell() { - for (Sudoku sudoku : this.subGrids) { - Cell cellTmp = sudoku.getFirstEmptyCell(); - if (cellTmp != null && cellTmp.isEmpty()) { - return cellTmp; - } - } - return null; - } - + /** + * Renvoie les symboles possibles d'une Cell donnée. + * @param cellToFill Cell. + * @return List, liste des symboles possible. + */ public List getPossibleSymbolsOfCell(Cell cellToFill) { List result = new ArrayList<>(); boolean hasBeenFill = false; @@ -78,10 +92,18 @@ public class MultiDoku { return result; } + /** + * Renvoie les sous-Sudoku + * @return List + */ public List getSubGrids() { 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() { boolean result = true; for (Sudoku sudoku : this.subGrids) { @@ -109,16 +131,38 @@ public class MultiDoku { 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, vide si aucune Cell n'est remplie. + */ public List getFilledCells() { List result = new ArrayList<>(); - for (Cell c : this.getCells()){ - if (!c.isEmpty()) { - result.add(c); + for (Cell cell : this.getCells()){ + if (!cell.isEmpty()) { + result.add(cell); } } return result; } + /** + * Vide une Cell donnée. + * @param cell Cell, à vider. + */ public void empty(Cell cell) { List cells = getCells(); Cell cellToEmpty = cells.get(cells.indexOf(cell)); diff --git a/app/src/main/java/sudoku/structure/Sudoku.java b/app/src/main/java/sudoku/structure/Sudoku.java index ec2860b..566728d 100644 --- a/app/src/main/java/sudoku/structure/Sudoku.java +++ b/app/src/main/java/sudoku/structure/Sudoku.java @@ -7,14 +7,25 @@ import java.util.List; /** * @class Sudoku - * @brief Represents a sudoku + * @brief Représent un Sudoku */ public class Sudoku { + /** + * Liste des Block contenus dans le Sudoku. + */ private final List blocks; + /** + * Liste des Cells contenus dans le Sudoku. + */ private final List cells; + /** + * Liste des contraintes (TODO) du Sudoku. + */ private final List constraints; - private boolean isMutable; + /** + * Largeur des Blocks s'ils sont rectangulaires, sinon ça vaut 0. + */ private int blockWidth; public Sudoku(List cells, List blocks, List constraints) { @@ -23,16 +34,29 @@ public class Sudoku { 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) { 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) { int index = toIndex(x, y);