fix: serialize
This commit is contained in:
@@ -24,28 +24,21 @@ public class 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<Integer> possibleSymbols;
|
||||
/**
|
||||
* Si cette Cell peut être modififié ou non.
|
||||
*/
|
||||
private boolean isMutable = true;
|
||||
|
||||
public Cell() {
|
||||
this.possibleSymbols = new ArrayList<>();
|
||||
this(Cell.NOSYMBOL);
|
||||
}
|
||||
|
||||
public Cell(int symbolIndex) {
|
||||
this.symbolIndex = symbolIndex;
|
||||
this.possibleSymbols = new ArrayList<>();
|
||||
}
|
||||
|
||||
public Cell(int symbolIndex, boolean isMutable) {
|
||||
this.symbolIndex = symbolIndex;
|
||||
this.possibleSymbols = new ArrayList<>();
|
||||
this.isMutable = isMutable;
|
||||
}
|
||||
|
||||
@@ -57,11 +50,6 @@ public class Cell {
|
||||
this.symbolIndex = symbolIndex;
|
||||
}
|
||||
|
||||
public void setPossibleSymbols(List<Integer> possibleSymbols) {
|
||||
this.possibleSymbols.clear();
|
||||
this.possibleSymbols.addAll(possibleSymbols);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rend la Cell immuable.
|
||||
*/
|
||||
@@ -95,14 +83,6 @@ public class Cell {
|
||||
return this.symbolIndex == Cell.NOSYMBOL;
|
||||
}
|
||||
|
||||
public void removeSymbolFromPossibilities(int indexSymbol) {
|
||||
possibleSymbols.remove(indexSymbol);
|
||||
}
|
||||
|
||||
public List<Integer> getPossibleSymbols() {
|
||||
return this.possibleSymbols;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renvoie si la Cell est modifiable
|
||||
* @return boolean, true si elle est modifiable ou false sinon.
|
||||
@@ -120,4 +100,35 @@ public class Cell {
|
||||
this.symbolIndex = Cell.NOSYMBOL;
|
||||
return oldSymbol;
|
||||
}
|
||||
|
||||
public boolean canHaveValue(int value) {
|
||||
for (Sudoku s :getBlock().getSudokus()) {
|
||||
int cellIndex = s.getCells().indexOf(this);
|
||||
// la cellule existe
|
||||
if (cellIndex != -1) {
|
||||
int cellX = cellIndex % s.getSize();
|
||||
int cellY = cellIndex / s.getSize();
|
||||
if (!s.canBePlaced(cellX, cellY, value)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public List<Integer> getPossibleSymbols() {
|
||||
List<Integer> result = new ArrayList<>();
|
||||
for (int i = 0; i < getBlock().getSudokus().get(0).getSize(); i++) {
|
||||
if (canHaveValue(i))
|
||||
result.add(i);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean trySetValue(int newValue) {
|
||||
if (!canHaveValue(newValue))
|
||||
return false;
|
||||
setSymbolIndex(newValue);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user