This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user