feat: added method to fill sudoku from integer list
All checks were successful
Linux arm64 / Build (push) Successful in 1m4s

This commit is contained in:
fl.du.pr Grens
2025-01-21 21:42:39 +01:00
parent f44311fd5c
commit 38d1bc466f
3 changed files with 36 additions and 23 deletions

View File

@@ -12,6 +12,8 @@ import sudoku.io.SudokuSerializer;
import sudoku.solver.Solver; import sudoku.solver.Solver;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class Main { public class Main {
public String getGreeting() { public String getGreeting() {
@@ -20,34 +22,18 @@ public class Main {
public static void main(String[] args) { public static void main(String[] args) {
System.out.println(new Main().getGreeting()); System.out.println(new Main().getGreeting());
int blockWidth = 2; int blockWidth = 2;
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);
//SudokuPrinter.printRectangleSudoku(sudoku, blockWidth , blockHeight); sudoku.setCellsSymbol(Arrays.asList(0,1,2,3, 2,3,0,1, 1,0,3,2, 3,2,1,0));
//Line 1:
((MutableCell)sudoku.getCell(0)).setSymbolIndex(0);
((MutableCell)sudoku.getCell(1)).setSymbolIndex(1);
((MutableCell)sudoku.getCell(2)).setSymbolIndex(2);
((MutableCell)sudoku.getCell(3)).setSymbolIndex(3);
//Line 2:
((MutableCell)sudoku.getCell(4)).setSymbolIndex(2);
((MutableCell)sudoku.getCell(5)).setSymbolIndex(3);
((MutableCell)sudoku.getCell(6)).setSymbolIndex(0);
((MutableCell)sudoku.getCell(7)).setSymbolIndex(1);
//Line 3:
((MutableCell)sudoku.getCell(8)).setSymbolIndex(1);
((MutableCell)sudoku.getCell(9)).setSymbolIndex(0);
((MutableCell)sudoku.getCell(10)).setSymbolIndex(3);
((MutableCell)sudoku.getCell(11)).setSymbolIndex(2);
// Line 4
((MutableCell)sudoku.getCell(12)).setSymbolIndex(3);
((MutableCell)sudoku.getCell(13)).setSymbolIndex(2);
((MutableCell)sudoku.getCell(14)).setSymbolIndex(1);
((MutableCell)sudoku.getCell(15)).setSymbolIndex(0);
SudokuPrinter.printRectangleSudoku(multidoku.getSubGrid(0), blockWidth , blockHeight); SudokuPrinter.printRectangleSudoku(multidoku.getSubGrid(0), blockWidth , blockHeight);
//sudoku.setCellSymbol(8,3,0);
ArrayList<IConstraint> constraints = new ArrayList<>(); ArrayList<IConstraint> constraints = new ArrayList<>();
constraints.add(new LineConstraint()); constraints.add(new LineConstraint());
constraints.add(new ColumnConstraint()); constraints.add(new ColumnConstraint());
@@ -55,6 +41,8 @@ public class Main {
System.out.println(sudoku.isValid(constraints)); System.out.println(sudoku.isValid(constraints));
/* /*
Solver solver = new Solver(); Solver solver = new Solver();
ArrayList<IConstraint> constraints = new ArrayList<>(); ArrayList<IConstraint> constraints = new ArrayList<>();

View File

@@ -49,6 +49,21 @@ public class Sudoku {
return false; return false;
} }
public boolean setCellsSymbol(List<Integer> values) {
if (values.size() > this.cells.size()) {
return false;
}
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))) {
return false;
}
}
return true;
}
public Cell getCell(int x, int y) { public Cell getCell(int x, int y) {
int index = y * getSize() + x; int index = y * getSize() + x;
assert (isValidCoords(x, y)); assert (isValidCoords(x, y));

10
imgui.ini Normal file
View File

@@ -0,0 +1,10 @@
[Window][Debug##Default]
Pos=60,60
Size=400,400
Collapsed=0
[Window][Window]
Pos=32,164
Size=1096,529
Collapsed=1