feat : Solver.solve()

This commit is contained in:
Melvyn
2025-01-23 16:28:41 +01:00
parent e19a9c7b27
commit fc7ae02387
5 changed files with 80 additions and 9 deletions

View File

@@ -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;
}
}