This commit is contained in:
@@ -227,7 +227,7 @@ public class ConsoleInterface {
|
||||
saveMultiDoku(doku);
|
||||
break;
|
||||
case "solution":
|
||||
solve(doku);
|
||||
solve(doku, listSymbols, width, height);
|
||||
break;
|
||||
case "exit":
|
||||
exit();
|
||||
@@ -238,21 +238,52 @@ public class ConsoleInterface {
|
||||
}
|
||||
}
|
||||
|
||||
private void solve(MultiDoku doku){
|
||||
System.out.println("Pick a solver to use : random ('random', default), human ('human') or mixed solver ('mixed').");
|
||||
private void applyStep(SolverStep step) {
|
||||
step.getCell().setSymbolIndex(step.getNewValue());
|
||||
}
|
||||
|
||||
private boolean showStep(MultiDoku doku, List<String> listSymbols, int width, int height, SolverStep step) {
|
||||
System.out.println("Here is the step : \n");
|
||||
showMultidoku(doku, listSymbols, width, height);
|
||||
applyStep(step);
|
||||
System.out.println("\nTurns into :\n");
|
||||
showMultidoku(doku, listSymbols, width, height);
|
||||
System.out.println("Do you want to see the next step ? (y/n, default n)");
|
||||
return reader.next().equals("y");
|
||||
}
|
||||
|
||||
private void showSolveSteps(MultiDoku doku, List<String> listSymbols, int width, int height, List<SolverStep> steps) {
|
||||
System.out.println("Would you like to see the steps of the solver ? (y/n, default n)");
|
||||
doku.getStateManager().popState();
|
||||
switch (reader.next()) {
|
||||
case "human":
|
||||
new HumanSolver().solve(doku);
|
||||
break;
|
||||
case "mixed":
|
||||
new MixedSolver().solve(doku);
|
||||
case "y":
|
||||
int stepCount = 0;
|
||||
while(stepCount < steps.size() && showStep(doku, listSymbols, width, height, steps.get(stepCount))){stepCount++;}
|
||||
break;
|
||||
|
||||
default:
|
||||
new RandomSolver().solve(doku);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void solve(MultiDoku doku, List<String> listSymbols, int width, int height){
|
||||
System.out.println("Pick a solver to use : random ('random', default), human ('human') or mixed solver ('mixed').");
|
||||
List<SolverStep> steps = new ArrayList<>();
|
||||
doku.getStateManager().pushState();
|
||||
switch (reader.next()) {
|
||||
case "human":
|
||||
new HumanSolver().solve(doku, steps);
|
||||
break;
|
||||
case "mixed":
|
||||
new MixedSolver().solve(doku, steps);
|
||||
break;
|
||||
default:
|
||||
new RandomSolver().solve(doku, steps);
|
||||
break;
|
||||
}
|
||||
showSolveSteps(doku, listSymbols, width, height, steps);
|
||||
}
|
||||
|
||||
private void play(MultiDoku doku, List<String> listSymbols, int width, int height) {
|
||||
int x, y;
|
||||
RenderableMultidoku rdoku = RenderableMultidoku.fromMultidoku(doku);
|
||||
|
||||
@@ -2,13 +2,9 @@ package sudoku.solver;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CancellationException;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import gui.constants.Symbols;
|
||||
import sudoku.io.SudokuPrinter;
|
||||
import sudoku.structure.Cell;
|
||||
import sudoku.structure.MultiDoku;
|
||||
import sudoku.structure.Sudoku;
|
||||
|
||||
public class HumanSolver implements Solver {
|
||||
|
||||
@@ -23,13 +19,6 @@ public class HumanSolver implements Solver {
|
||||
if (Thread.interrupted())
|
||||
throw new CancellationException("User wants to stop the solver");
|
||||
|
||||
Sudoku sudoku = doku.getSubGrid(0);
|
||||
logger.log(Level.FINE,
|
||||
'\n' + SudokuPrinter.toStringRectangleSudoku(sudoku,
|
||||
sudoku.getBlockWidth() == 0 ? sudoku.getSize() : sudoku.getBlockWidth(),
|
||||
sudoku.getBlockWidth() == 0 ? sudoku.getSize() : sudoku.getSize() / sudoku.getBlockWidth(),
|
||||
Symbols.Numbers));
|
||||
|
||||
if (doku.isSolved()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -3,13 +3,9 @@ package sudoku.solver;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.CancellationException;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import gui.constants.Symbols;
|
||||
import sudoku.io.SudokuPrinter;
|
||||
import sudoku.structure.Cell;
|
||||
import sudoku.structure.MultiDoku;
|
||||
import sudoku.structure.Sudoku;
|
||||
|
||||
public class MixedSolver implements Solver {
|
||||
|
||||
@@ -28,14 +24,6 @@ public class MixedSolver implements Solver {
|
||||
throw new CancellationException("User wants to stop the solver");
|
||||
}
|
||||
|
||||
Sudoku sudoku = doku.getSubGrid(0);
|
||||
logger.log(Level.FINE,
|
||||
'\n' + SudokuPrinter.toStringRectangleSudoku(
|
||||
sudoku,
|
||||
sudoku.getBlockWidth() == 0 ? sudoku.getSize() : sudoku.getBlockWidth(),
|
||||
sudoku.getBlockWidth() == 0 ? sudoku.getSize() : sudoku.getSize() / sudoku.getBlockWidth(),
|
||||
Symbols.Numbers));
|
||||
|
||||
if (doku.isSolved()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -3,13 +3,9 @@ package sudoku.solver;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.CancellationException;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import gui.constants.Symbols;
|
||||
import sudoku.io.SudokuPrinter;
|
||||
import sudoku.structure.Cell;
|
||||
import sudoku.structure.MultiDoku;
|
||||
import sudoku.structure.Sudoku;
|
||||
|
||||
public class RandomSolver implements Solver {
|
||||
|
||||
@@ -28,13 +24,6 @@ public class RandomSolver implements Solver {
|
||||
if (Thread.interrupted())
|
||||
throw new CancellationException("User wants to stop the solver");
|
||||
|
||||
Sudoku sudoku = doku.getSubGrid(0);
|
||||
logger.log(Level.FINE,
|
||||
'\n' + SudokuPrinter.toStringRectangleSudoku(sudoku,
|
||||
sudoku.getBlockWidth() == 0 ? sudoku.getSize() : sudoku.getBlockWidth(),
|
||||
sudoku.getBlockWidth() == 0 ? sudoku.getSize() : sudoku.getSize() / sudoku.getBlockWidth(),
|
||||
Symbols.Numbers));
|
||||
|
||||
if (doku.isSolved()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user