This commit is contained in:
@@ -5,38 +5,38 @@ import java.util.List;
|
||||
|
||||
public class SudokuFactory {
|
||||
|
||||
private static List<Case> initCases(int size) {
|
||||
List<Case> cases = new ArrayList<>(size * size);
|
||||
private static List<Cell> initCells(int size) {
|
||||
List<Cell> cells = new ArrayList<>(size * size);
|
||||
for (int i = 0; i < size * size; i++) {
|
||||
cases.add(new Case());
|
||||
cells.add(new Cell());
|
||||
}
|
||||
return cases;
|
||||
return cells;
|
||||
}
|
||||
|
||||
private static List<Bloc> initRectangleBlocs(List<Case> cases, int width, int height) {
|
||||
List<Bloc> blocs = new ArrayList<>();
|
||||
private static List<Block> initRectangleBlocs(List<Cell> cells, int width, int height) {
|
||||
List<Block> blocs = new ArrayList<>();
|
||||
int size = width * height;
|
||||
for (int i = 0; i < size; i++) {
|
||||
Bloc newBloc = new Bloc();
|
||||
int blocX = i % height;
|
||||
int blocY = i / height;
|
||||
Block newBlock = new Block();
|
||||
int blockX = i % height;
|
||||
int blockY = i / height;
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
int index = ((y + blocY * height) * size + (x + blocX * width));
|
||||
Case caseBloc = cases.get(index);
|
||||
caseBloc.setBloc(newBloc);
|
||||
newBloc.addCase(caseBloc);
|
||||
int index = ((y + blockY * height) * size + (x + blockX * width));
|
||||
Cell blockCell = cells.get(index);
|
||||
blockCell.setBlock(newBlock);
|
||||
newBlock.addCell(blockCell);
|
||||
}
|
||||
}
|
||||
blocs.add(newBloc);
|
||||
blocs.add(newBlock);
|
||||
}
|
||||
return blocs;
|
||||
}
|
||||
|
||||
public static MultiDoku createBasicEmptyRectangleSudoku(int width, int height) {
|
||||
int symbolCount = width * height;
|
||||
List<Case> cases = initCases(symbolCount);
|
||||
List<Bloc> blocs = initRectangleBlocs(cases, width, height);
|
||||
List<Cell> cases = initCells(symbolCount);
|
||||
List<Block> blocs = initRectangleBlocs(cases, width, height);
|
||||
Sudoku s = new Sudoku(cases, blocs);
|
||||
List<Sudoku> ss = new ArrayList<>();
|
||||
ss.add(s);
|
||||
|
||||
Reference in New Issue
Block a user