diff --git a/app/src/main/java/gui/RenderableMultidoku.java b/app/src/main/java/gui/RenderableMultidoku.java index aa4350f..33372f0 100644 --- a/app/src/main/java/gui/RenderableMultidoku.java +++ b/app/src/main/java/gui/RenderableMultidoku.java @@ -48,18 +48,17 @@ public class RenderableMultidoku { } public boolean setCellValue(Cell cell, int value) { - // TODO: fix constraints - // for (Sudoku s : doku.getSubGrids()) { - // int cellIndex = s.getCells().indexOf(cell); - // // la cellule existe - // if (cellIndex != -1) { - // int cellX = cellIndex % s.getSize(); - // int cellY = cellIndex / s.getSize(); - // if (s.canBePlaced(cellX, cellY, value)) { - // return false; - // } - // } - // } + for (Sudoku s : doku.getSubGrids()) { + int cellIndex = s.getCells().indexOf(cell); + // la cellule existe + if (cellIndex != -1) { + int cellX = cellIndex % s.getSize(); + int cellY = cellIndex / s.getSize(); + if (!s.canBePlaced(cellX, cellY, value)) { + return false; + } + } + } cell.setSymbolIndex(value); return true; } @@ -100,7 +99,8 @@ public class RenderableMultidoku { for (Coordinate coordinate : sudokusOffset.values()) { if (minCoordinate == null) 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; } @@ -134,7 +134,8 @@ public class RenderableMultidoku { public static RenderableMultidoku fromMultidoku(MultiDoku doku) { if (doku.getNbSubGrids() == 1) { 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 sudokusOffset = new HashMap<>(); // coordinates in cell @@ -203,4 +204,8 @@ public class RenderableMultidoku { return new RenderableMultidoku(doku, blocks, cells, maxCoordinate.getX(), maxCoordinate.getY()); } + public MultiDoku getDoku() { + return doku; + } + } diff --git a/app/src/main/java/sudoku/io/SudokuSerializer.java b/app/src/main/java/sudoku/io/SudokuSerializer.java index 3cceebf..d56535c 100644 --- a/app/src/main/java/sudoku/io/SudokuSerializer.java +++ b/app/src/main/java/sudoku/io/SudokuSerializer.java @@ -10,6 +10,7 @@ import sudoku.structure.Block; import sudoku.structure.Cell; import sudoku.structure.MultiDoku; import sudoku.structure.Sudoku; +import sudoku.structure.SudokuFactory; public class SudokuSerializer { @@ -152,7 +153,7 @@ public class SudokuSerializer { 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")); sudokus.add(s); } diff --git a/app/src/main/java/sudoku/structure/SudokuFactory.java b/app/src/main/java/sudoku/structure/SudokuFactory.java index cb2c560..719d822 100644 --- a/app/src/main/java/sudoku/structure/SudokuFactory.java +++ b/app/src/main/java/sudoku/structure/SudokuFactory.java @@ -12,7 +12,7 @@ import sudoku.constraint.LineConstraint; public class SudokuFactory { - private static List DEFAULT_CONSTRAINTS = Arrays.asList(new BlockConstraint(), new LineConstraint(), new ColumnConstraint()); + public static List DEFAULT_CONSTRAINTS = Arrays.asList(new BlockConstraint(), new LineConstraint(), new ColumnConstraint()); private static List initCells(int size) { List cells = new ArrayList<>(size * size);