73 lines
1.4 KiB
Java
73 lines
1.4 KiB
Java
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<Cell> cells;
|
|
|
|
/**
|
|
* List de sudoku qui contiennent le block
|
|
* Pour un acces plus rapide aux sudokus
|
|
*/
|
|
private final List<Sudoku> sudokus;
|
|
|
|
public Block(List<Cell> cells) {
|
|
this.cells = cells;
|
|
this.sudokus = new ArrayList<>();
|
|
}
|
|
|
|
public Block() {
|
|
this(new ArrayList<>());
|
|
}
|
|
|
|
public List<Cell> getCells() {
|
|
return cells;
|
|
}
|
|
|
|
/**
|
|
* Ajoute une Cell au Block
|
|
*
|
|
* @param newCell Cell, à ajouter
|
|
*/
|
|
public 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)
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public boolean containsCell(Cell cell) {
|
|
for (Cell cellTmp : this.cells) {
|
|
if (cellTmp.equals(cell)) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public List<Sudoku> getSudokus() {
|
|
return sudokus;
|
|
}
|
|
}
|