This commit is contained in:
@@ -27,21 +27,14 @@ public class Main {
|
||||
int blockHeight = 2;
|
||||
var multidoku = SudokuFactory.createBasicEmptyRectangleSudoku(blockWidth, blockHeight);
|
||||
var sudoku = multidoku.getSubGrid(0);
|
||||
sudoku.setCellsSymbol(Arrays.asList(0,1,2,3, 2,3,0,1, 1,0,3,2, 3,2,1,0));
|
||||
SudokuPrinter.printRectangleSudoku(multidoku.getSubGrid(0), blockWidth , blockHeight);
|
||||
if(!sudoku.setCellsSymbol(Arrays.asList(0,1,2,3, 2,3,1,1, 1,0,3,2, 3,2,1,1))){
|
||||
System.out.println("At least one of those values does not respect the constraints.");
|
||||
}
|
||||
|
||||
|
||||
//sudoku.setCellSymbol(8,3,0);
|
||||
|
||||
|
||||
|
||||
ArrayList<IConstraint> constraints = new ArrayList<>();
|
||||
constraints.add(new LineConstraint());
|
||||
constraints.add(new ColumnConstraint());
|
||||
constraints.add(new BlockConstraint());
|
||||
|
||||
System.out.println(sudoku.isValid(constraints));
|
||||
|
||||
|
||||
SudokuPrinter.printRectangleSudoku(multidoku.getSubGrid(0), blockWidth , blockHeight);
|
||||
|
||||
/*
|
||||
Solver solver = new Solver();
|
||||
|
||||
@@ -26,14 +26,6 @@ public class MultiDoku {
|
||||
return subGrids.get(i);
|
||||
}
|
||||
|
||||
public boolean isValid(List<IConstraint> constraints){
|
||||
for (Sudoku sudoku : subGrids){
|
||||
if (!sudoku.isValid(constraints))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public List<MutableCell> getMutableCells(){
|
||||
List<MutableCell> mutableCells = new ArrayList<>();
|
||||
for (Sudoku sudoku : subGrids){
|
||||
|
||||
@@ -56,7 +56,8 @@ public class Sudoku {
|
||||
for (int i = 0; i < values.size(); i++) {
|
||||
int x = i%this.blocks.size();
|
||||
int y = (i-x)/this.blocks.size();
|
||||
if (!this.setCellSymbol(x, y, values.get(i))) {
|
||||
int value = values.get(i);
|
||||
if (!this.setCellSymbol(x, y, value)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -82,12 +83,6 @@ public class Sudoku {
|
||||
return this.blocks.size();
|
||||
}
|
||||
|
||||
public boolean isValid(List<IConstraint> constraints) {
|
||||
// not implemented
|
||||
// for eachcase check contraintes
|
||||
return false;
|
||||
}
|
||||
|
||||
public List<Cell> getCells() {
|
||||
return this.cells;
|
||||
}
|
||||
|
||||
@@ -19,9 +19,6 @@ public class Solver {
|
||||
}
|
||||
|
||||
public MultiDoku solve(MultiDoku doku, List<IConstraint> constraints) throws Exception {
|
||||
if (!doku.isValid(constraints)) {
|
||||
throw new Exception("Invalid doku");
|
||||
}
|
||||
List<MutableCell> allMutableCells = doku.getMutableCells();
|
||||
List<MutableCell> remainingCellsToCheck = new ArrayList<>(allMutableCells);
|
||||
Random rand = new Random();
|
||||
|
||||
Reference in New Issue
Block a user