feat : Solver.solve()
This commit is contained in:
@@ -162,4 +162,31 @@ public class Sudoku {
|
||||
sb.append("\n}");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public MutableCell getFirstEmptyMutableCell() {
|
||||
for (MutableCell cell : this.getMutableCells()) {
|
||||
if (cell.isEmpty()) {
|
||||
return cell;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<Integer> getPossibleSymbolsOfCell(MutableCell cellToFill) {
|
||||
List<Integer> result = new ArrayList<>();
|
||||
Coordinate cellCoordinates;
|
||||
try {
|
||||
cellCoordinates = this.getCoordinateCell(cellToFill);
|
||||
} catch (Exception e) {
|
||||
return result;
|
||||
}
|
||||
for (IConstraint constraint : this.constraints) {
|
||||
if (result.isEmpty()) {
|
||||
result.addAll(constraint.getPossibleSymbols(this, cellCoordinates.getX(), cellCoordinates.getY()));
|
||||
} else {
|
||||
result.retainAll(constraint.getPossibleSymbols(this, cellCoordinates.getX(), cellCoordinates.getY()));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user