feat : Solver.solve()
This commit is contained in:
@@ -10,14 +10,41 @@ import java.util.Random;
|
||||
import java.util.Stack;
|
||||
|
||||
public class Solver {
|
||||
Stack<MutableCell> stack;
|
||||
|
||||
public Solver() {}
|
||||
|
||||
/**
|
||||
* Résout le multidoku passé en paramètre si c'est possible.
|
||||
* En testant toutes les possibilités avec un algorithme de backtracking.
|
||||
* @param doku Multidouke, à résoudre
|
||||
* @return boolean, true s'il est résolut ou false s'il ne l'est pas.
|
||||
*/
|
||||
public boolean solve(MultiDoku doku) {
|
||||
MutableCell cellToFill = doku.getFirstEmptyMutableCell();
|
||||
if (cellToFill == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
List<Integer> possibleSymbols = doku.getPossibleSymbolsOfCell(cellToFill);
|
||||
if (possibleSymbols.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int symbol : possibleSymbols) {
|
||||
cellToFill.setSymbolIndex(symbol);
|
||||
return this.solve(doku);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
Ancien algo abandonné pour le moment
|
||||
|
||||
private void rollBack() {
|
||||
stack.pop();
|
||||
}
|
||||
|
||||
|
||||
public MultiDoku solve(MultiDoku doku, List<IConstraint> constraints) throws Exception {
|
||||
List<MutableCell> allMutableCells = doku.getMutableCells();
|
||||
List<MutableCell> remainingCellsToCheck = new ArrayList<>(allMutableCells);
|
||||
@@ -39,4 +66,6 @@ public class Solver {
|
||||
}
|
||||
return doku;
|
||||
}
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user