feat : solver + test
All checks were successful
Linux arm64 / Build (push) Successful in 5m9s

This commit is contained in:
Melvyn
2025-01-23 23:20:16 +01:00
parent 6902321101
commit 483b286bac
13 changed files with 292 additions and 183 deletions

View File

@@ -10,17 +10,16 @@ import sudoku.Block;
import sudoku.Cell;
import sudoku.ImmutableCell;
import sudoku.MultiDoku;
import sudoku.MutableCell;
import sudoku.Sudoku;
public class SudokuSerializer {
public static String serializeSudoku(final MultiDoku multidoku) {
List<Cell> cellIds = new ArrayList<>();
List<Cell> cellIds = new ArrayList<>();
List<Block> blockIds = new ArrayList<>();
JSONObject jsonRoot = new JSONObject();
JSONArray jsonCells = new JSONArray();
JSONObject jsonRoot = new JSONObject();
JSONArray jsonCells = new JSONArray();
JSONArray jsonBlocks = new JSONArray();
JSONArray jsonSudokus = new JSONArray(multidoku.getNbSubGrids());
@@ -55,17 +54,16 @@ public class SudokuSerializer {
// init blocks
for (int i = 0; i < blockIds.size(); i++) {
JSONObject blockJsonObject = new JSONObject();
JSONArray cellsJsonArray = new JSONArray();
Block block = blockIds.get(i);
for (Cell cell : block.getCells()) {
int cellID = cellIds.indexOf(cell);
cellsJsonArray.put(cellID);
}
blockJsonObject.put("cellIDs", cellsJsonArray);
jsonBlocks.put(blockJsonObject);
}
for (Block blockId : blockIds) {
JSONObject blockJsonObject = new JSONObject();
JSONArray cellsJsonArray = new JSONArray();
for (Cell cell : blockId.getCells()) {
int cellID = cellIds.indexOf(cell);
cellsJsonArray.put(cellID);
}
blockJsonObject.put("cellIDs", cellsJsonArray);
jsonBlocks.put(blockJsonObject);
}
for (int i = 0; i < multidoku.getNbSubGrids(); i++) {
// serialise sub grid
@@ -115,7 +113,7 @@ public class SudokuSerializer {
if (entry.has("immutable")) {
cells.add(new ImmutableCell(symboleIndex));
} else {
cells.add(new MutableCell(symboleIndex));
cells.add(new Cell(symboleIndex));
}
}