This commit is contained in:
@@ -17,8 +17,6 @@ public class MixedSolver implements Solver{
|
||||
* backtracking.
|
||||
*
|
||||
* @param doku MultiDoku, MultiDoku à résoudre.
|
||||
* @param rand Random, pour tester aléatoirement les symboles, lors du
|
||||
* backtracking.
|
||||
* @return boolean, valant true si le MultiDoku est résolu, false sinon.
|
||||
*/
|
||||
@Override
|
||||
@@ -40,29 +38,20 @@ public class MixedSolver implements Solver{
|
||||
return true;
|
||||
}
|
||||
|
||||
List<Cell> cellsToFill = doku.getEmptyCells();
|
||||
if (cellsToFill.isEmpty()) {
|
||||
Cell cellToFill = doku.getFirstEmptyCell();
|
||||
if (cellToFill == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Règles de déduction
|
||||
for (Cell cellToFill : cellsToFill) {
|
||||
|
||||
List<Integer> possibleSymbols = cellToFill.getPossibleSymbols();
|
||||
if (possibleSymbols.size() != 1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
cellToFill.setSymbolIndex(possibleSymbols.getFirst());
|
||||
|
||||
return this.solve(doku);
|
||||
}
|
||||
|
||||
// Si ça ne marche pas
|
||||
// On fait du backtracking
|
||||
Cell cellToFill = doku.getRandomEmptyCell(rand);
|
||||
List<Integer> possibleSymbols = cellToFill.getPossibleSymbols();
|
||||
|
||||
if (possibleSymbols.size() == 1) {
|
||||
cellToFill.setSymbolIndex(possibleSymbols.getFirst());
|
||||
if (this.solve(doku)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
while (!possibleSymbols.isEmpty()) {
|
||||
int nextPossibleSymbolIndex = rand.nextInt(possibleSymbols.size());
|
||||
int nextSymbol = possibleSymbols.get(nextPossibleSymbolIndex);
|
||||
@@ -71,9 +60,9 @@ public class MixedSolver implements Solver{
|
||||
if (this.solve(doku)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
cellToFill.setSymbolIndex(Cell.NOSYMBOL);
|
||||
possibleSymbols.remove(nextPossibleSymbolIndex);
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user