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