This commit is contained in:
@@ -2,10 +2,8 @@ package gui.menu;
|
|||||||
|
|
||||||
import imgui.ImGui;
|
import imgui.ImGui;
|
||||||
import imgui.type.ImInt;
|
import imgui.type.ImInt;
|
||||||
import sudoku.solver.Solver;
|
import sudoku.structure.Difficulty;
|
||||||
import sudoku.structure.Cell;
|
|
||||||
import sudoku.structure.MultiDoku;
|
import sudoku.structure.MultiDoku;
|
||||||
import sudoku.structure.Sudoku;
|
|
||||||
import sudoku.structure.SudokuFactory;
|
import sudoku.structure.SudokuFactory;
|
||||||
|
|
||||||
public class SoloMenu extends BaseView {
|
public class SoloMenu extends BaseView {
|
||||||
@@ -26,20 +24,7 @@ public class SoloMenu extends BaseView {
|
|||||||
private void pushSudokuState(MultiDoku doku, boolean empty) {
|
private void pushSudokuState(MultiDoku doku, boolean empty) {
|
||||||
if (!empty) {
|
if (!empty) {
|
||||||
try {
|
try {
|
||||||
int level = 0;
|
SudokuFactory.fillDoku(doku, Difficulty.Easy);
|
||||||
for (Sudoku sudoku : doku.getSubGrids()) {
|
|
||||||
level += sudoku.getSize() * sudoku.getSize() / 10 * 3;
|
|
||||||
}
|
|
||||||
Solver.solve(doku);
|
|
||||||
level = (level - 1) / doku.getNbSubGrids();
|
|
||||||
SudokuFactory.newDokuFromFilledOne(doku, level);
|
|
||||||
for (Sudoku sudoku : doku.getSubGrids()) {
|
|
||||||
for (Cell cell : sudoku.getCells()) {
|
|
||||||
if (cell.getSymbolIndex() != Cell.NOSYMBOL) {
|
|
||||||
cell.setImmutable();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|||||||
18
app/src/main/java/sudoku/structure/Difficulty.java
Normal file
18
app/src/main/java/sudoku/structure/Difficulty.java
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
package sudoku.structure;
|
||||||
|
|
||||||
|
//TODO: melvyn va passer par là
|
||||||
|
public enum Difficulty {
|
||||||
|
|
||||||
|
VeryEasy(0.1), Easy(0.25), Medium(0.5), Hard(0.75);
|
||||||
|
|
||||||
|
double factor;
|
||||||
|
|
||||||
|
Difficulty(double factor) {
|
||||||
|
this.factor = factor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getFactor() {
|
||||||
|
return factor;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -237,31 +237,13 @@ public class SudokuFactory {
|
|||||||
return new MultiDoku(Arrays.asList(sudoku1, sudoku2, sudoku3, sudoku4, sudoku5));
|
return new MultiDoku(Arrays.asList(sudoku1, sudoku2, sudoku3, sudoku4, sudoku5));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MultiDoku createBasicRectangleDokuToSolve(int width, int height, double difficulty) throws Exception {
|
public static void fillDoku(MultiDoku doku, Difficulty difficulty) throws Exception {
|
||||||
MultiDoku doku = createBasicEmptyRectangleSudoku(width, height);
|
|
||||||
Solver.solveRandom(doku, random);
|
Solver.solveRandom(doku, random);
|
||||||
int nbCellsToEmpty = (int)(difficulty*doku.getNbCells());
|
int nbCellsToEmpty = (int)(difficulty.getFactor()*doku.getNbCells());
|
||||||
boolean successfull = newDokuFromFilledOne(doku, nbCellsToEmpty);
|
boolean successfull = newDokuFromFilledOne(doku, nbCellsToEmpty);
|
||||||
if (!successfull) {
|
if (!successfull) {
|
||||||
throw new Exception("Canno't create this doku with this difficulty");
|
throw new Exception("Canno't create this doku with this difficulty");
|
||||||
}
|
}
|
||||||
doku.setFilledCellsImmutable();
|
doku.setFilledCellsImmutable();
|
||||||
return doku;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static MultiDoku createBasicSquareDokuToSolve(int size, double difficulty) throws Exception {
|
|
||||||
return createBasicRectangleDokuToSolve(size, size, difficulty);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static MultiDoku createBasicXShapedMultiDokuToSolve(int size, double difficulty) throws Exception {
|
|
||||||
MultiDoku doku = createBasicXShapedMultidoku(size);
|
|
||||||
Solver.solveRandom(doku, random);
|
|
||||||
int nbCellsToEmpty = (int)(difficulty*doku.getNbCells());
|
|
||||||
boolean successful = newDokuFromFilledOne(doku, nbCellsToEmpty);
|
|
||||||
if (!successful) {
|
|
||||||
throw new Exception("Cannot create this Doku with this difficulty");
|
|
||||||
}
|
|
||||||
doku.setFilledCellsImmutable();
|
|
||||||
return doku;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user