sudoku vide
All checks were successful
Linux arm64 / Build (push) Successful in 34s

This commit is contained in:
2025-01-10 15:58:34 +01:00
parent 09ba8c00cb
commit 77c0b0d41b
3 changed files with 61 additions and 1 deletions

View File

@@ -0,0 +1,50 @@
package sudoku;
import java.util.ArrayList;
import java.util.List;
public class SudokuFactory {
private static List<Case> initCases(int size) {
List<Case> cases = new ArrayList<>(size * size);
for (int i = 0; i < size * size; i++) {
cases.add(new Case());
}
return cases;
}
private static List<Bloc> initRectangleBlocs(List<Case> cases, int width, int height) {
List<Bloc> 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;
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);
}
}
blocs.add(newBloc);
}
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);
Sudoku s = new Sudoku(cases, blocs);
List<Sudoku> ss = new ArrayList<>();
ss.add(s);
return new MultiDoku(ss);
}
public static MultiDoku createBasicEmptySquareSudoku(int size) {
return createBasicEmptyRectangleSudoku(size, size);
}
}