multidoku constraints gui
Some checks are pending
Linux arm64 / Build (push) Waiting to run

This commit is contained in:
2025-01-28 09:20:48 +01:00
parent 182f79d4b4
commit c7d3430d21
3 changed files with 22 additions and 16 deletions

View File

@@ -48,18 +48,17 @@ public class RenderableMultidoku {
} }
public boolean setCellValue(Cell cell, int value) { public boolean setCellValue(Cell cell, int value) {
// TODO: fix constraints for (Sudoku s : doku.getSubGrids()) {
// for (Sudoku s : doku.getSubGrids()) { int cellIndex = s.getCells().indexOf(cell);
// int cellIndex = s.getCells().indexOf(cell); // la cellule existe
// // la cellule existe if (cellIndex != -1) {
// if (cellIndex != -1) { int cellX = cellIndex % s.getSize();
// int cellX = cellIndex % s.getSize(); int cellY = cellIndex / s.getSize();
// int cellY = cellIndex / s.getSize(); if (!s.canBePlaced(cellX, cellY, value)) {
// if (s.canBePlaced(cellX, cellY, value)) { return false;
// return false; }
// } }
// } }
// }
cell.setSymbolIndex(value); cell.setSymbolIndex(value);
return true; return true;
} }
@@ -100,7 +99,8 @@ public class RenderableMultidoku {
for (Coordinate coordinate : sudokusOffset.values()) { for (Coordinate coordinate : sudokusOffset.values()) {
if (minCoordinate == null) if (minCoordinate == null)
minCoordinate = coordinate; minCoordinate = coordinate;
minCoordinate = new Coordinate(Math.min(minCoordinate.getX(), coordinate.getX()), Math.min(minCoordinate.getY(), coordinate.getY())); minCoordinate = new Coordinate(Math.min(minCoordinate.getX(), coordinate.getX()),
Math.min(minCoordinate.getY(), coordinate.getY()));
} }
return minCoordinate; return minCoordinate;
} }
@@ -134,7 +134,8 @@ public class RenderableMultidoku {
public static RenderableMultidoku fromMultidoku(MultiDoku doku) { public static RenderableMultidoku fromMultidoku(MultiDoku doku) {
if (doku.getNbSubGrids() == 1) { if (doku.getNbSubGrids() == 1) {
Sudoku sudoku = doku.getSubGrid(0); Sudoku sudoku = doku.getSubGrid(0);
return new RenderableMultidoku(doku, sudoku.getBlocks(), sudoku.getCells(), sudoku.getSize(), sudoku.getSize()); return new RenderableMultidoku(doku, sudoku.getBlocks(), sudoku.getCells(), sudoku.getSize(),
sudoku.getSize());
} }
Map<Sudoku, Coordinate> sudokusOffset = new HashMap<>(); Map<Sudoku, Coordinate> sudokusOffset = new HashMap<>();
// coordinates in cell // coordinates in cell
@@ -203,4 +204,8 @@ public class RenderableMultidoku {
return new RenderableMultidoku(doku, blocks, cells, maxCoordinate.getX(), maxCoordinate.getY()); return new RenderableMultidoku(doku, blocks, cells, maxCoordinate.getX(), maxCoordinate.getY());
} }
public MultiDoku getDoku() {
return doku;
}
} }

View File

@@ -10,6 +10,7 @@ import sudoku.structure.Block;
import sudoku.structure.Cell; import sudoku.structure.Cell;
import sudoku.structure.MultiDoku; import sudoku.structure.MultiDoku;
import sudoku.structure.Sudoku; import sudoku.structure.Sudoku;
import sudoku.structure.SudokuFactory;
public class SudokuSerializer { public class SudokuSerializer {
@@ -152,7 +153,7 @@ public class SudokuSerializer {
sudokuBlocks.add(blocks.get(blockID)); sudokuBlocks.add(blocks.get(blockID));
} }
Sudoku s = new Sudoku(sudokuCells, sudokuBlocks, null); Sudoku s = new Sudoku(sudokuCells, sudokuBlocks, SudokuFactory.DEFAULT_CONSTRAINTS);
s.setBlockWidth(sudokuJsonObject.getInt("blockWidth")); s.setBlockWidth(sudokuJsonObject.getInt("blockWidth"));
sudokus.add(s); sudokus.add(s);
} }

View File

@@ -12,7 +12,7 @@ import sudoku.constraint.LineConstraint;
public class SudokuFactory { public class SudokuFactory {
private static List<IConstraint> DEFAULT_CONSTRAINTS = Arrays.asList(new BlockConstraint(), new LineConstraint(), new ColumnConstraint()); public static List<IConstraint> DEFAULT_CONSTRAINTS = Arrays.asList(new BlockConstraint(), new LineConstraint(), new ColumnConstraint());
private static List<Cell> initCells(int size) { private static List<Cell> initCells(int size) {
List<Cell> cells = new ArrayList<>(size * size); List<Cell> cells = new ArrayList<>(size * size);