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

@@ -1,5 +1,6 @@
package sudoku; package sudoku;
import java.util.ArrayList;
import java.util.List; import java.util.List;
public class Bloc { public class Bloc {
@@ -10,8 +11,16 @@ public class Bloc {
this.cases = cases; this.cases = cases;
} }
public Bloc() {
this.cases = new ArrayList<>();
}
public List<Case> getCases() { public List<Case> getCases() {
return cases; return cases;
} }
void addCase(Case newCase) {
this.cases.add(newCase);
}
} }

View File

@@ -10,6 +10,7 @@ public class Main {
public static void main(String[] args) { public static void main(String[] args) {
System.out.println(new Main().getGreeting()); System.out.println(new Main().getGreeting());
// var test = SudokuFactory.createBasicEmptySudoku(9); var test = SudokuFactory.createBasicEmptyRectangleSudoku(3, 3);
System.out.println(test);
} }
} }

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);
}
}