This commit is contained in:
@@ -291,4 +291,28 @@ public class SudokuFactory {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static MultiDoku createBasicEmptyRandomBlockDoku(int blockSize, List<Constraint> constraints) {
|
||||
int blockCellCount = blockSize * blockSize;
|
||||
List<Cell> cells = initCells(blockCellCount);
|
||||
List<Cell> homeLessCells = new ArrayList<>();
|
||||
homeLessCells.addAll(cells);
|
||||
List<Block> blocks = new ArrayList<>();
|
||||
Random r = new Random();
|
||||
for (int i = 0 ; i < blockCellCount; i++) {
|
||||
Block b = new Block();
|
||||
for (int j = 0; j < blockCellCount; j++) {
|
||||
int cellIndex = r.nextInt(homeLessCells.size());
|
||||
Cell cell = homeLessCells.remove(cellIndex);
|
||||
b.addCell(cell);
|
||||
cell.setBlock(b);
|
||||
}
|
||||
blocks.add(b);
|
||||
}
|
||||
Sudoku sudoku = new Sudoku(cells, blocks, constraints);
|
||||
for (Block block : blocks) {
|
||||
block.getSudokus().add(sudoku);
|
||||
}
|
||||
return new MultiDoku(Arrays.asList(sudoku));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user