This commit is contained in:
@@ -227,7 +227,7 @@ public class ConsoleInterface {
|
|||||||
saveMultiDoku(doku);
|
saveMultiDoku(doku);
|
||||||
break;
|
break;
|
||||||
case "solution":
|
case "solution":
|
||||||
solve(doku);
|
solve(doku, listSymbols, width, height);
|
||||||
break;
|
break;
|
||||||
case "exit":
|
case "exit":
|
||||||
exit();
|
exit();
|
||||||
@@ -238,21 +238,52 @@ public class ConsoleInterface {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void solve(MultiDoku doku){
|
private void applyStep(SolverStep step) {
|
||||||
System.out.println("Pick a solver to use : random ('random', default), human ('human') or mixed solver ('mixed').");
|
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()) {
|
switch (reader.next()) {
|
||||||
case "human":
|
case "y":
|
||||||
new HumanSolver().solve(doku);
|
int stepCount = 0;
|
||||||
break;
|
while(stepCount < steps.size() && showStep(doku, listSymbols, width, height, steps.get(stepCount))){stepCount++;}
|
||||||
case "mixed":
|
|
||||||
new MixedSolver().solve(doku);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
new RandomSolver().solve(doku);
|
|
||||||
break;
|
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) {
|
private void play(MultiDoku doku, List<String> listSymbols, int width, int height) {
|
||||||
int x, y;
|
int x, y;
|
||||||
RenderableMultidoku rdoku = RenderableMultidoku.fromMultidoku(doku);
|
RenderableMultidoku rdoku = RenderableMultidoku.fromMultidoku(doku);
|
||||||
|
|||||||
@@ -2,13 +2,9 @@ package sudoku.solver;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.CancellationException;
|
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.Cell;
|
||||||
import sudoku.structure.MultiDoku;
|
import sudoku.structure.MultiDoku;
|
||||||
import sudoku.structure.Sudoku;
|
|
||||||
|
|
||||||
public class HumanSolver implements Solver {
|
public class HumanSolver implements Solver {
|
||||||
|
|
||||||
@@ -23,13 +19,6 @@ public class HumanSolver implements Solver {
|
|||||||
if (Thread.interrupted())
|
if (Thread.interrupted())
|
||||||
throw new CancellationException("User wants to stop the 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()) {
|
if (doku.isSolved()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,13 +3,9 @@ package sudoku.solver;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.concurrent.CancellationException;
|
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.Cell;
|
||||||
import sudoku.structure.MultiDoku;
|
import sudoku.structure.MultiDoku;
|
||||||
import sudoku.structure.Sudoku;
|
|
||||||
|
|
||||||
public class MixedSolver implements Solver {
|
public class MixedSolver implements Solver {
|
||||||
|
|
||||||
@@ -28,14 +24,6 @@ public class MixedSolver implements Solver {
|
|||||||
throw new CancellationException("User wants to stop the 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()) {
|
if (doku.isSolved()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,13 +3,9 @@ package sudoku.solver;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.concurrent.CancellationException;
|
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.Cell;
|
||||||
import sudoku.structure.MultiDoku;
|
import sudoku.structure.MultiDoku;
|
||||||
import sudoku.structure.Sudoku;
|
|
||||||
|
|
||||||
public class RandomSolver implements Solver {
|
public class RandomSolver implements Solver {
|
||||||
|
|
||||||
@@ -28,13 +24,6 @@ public class RandomSolver implements Solver {
|
|||||||
if (Thread.interrupted())
|
if (Thread.interrupted())
|
||||||
throw new CancellationException("User wants to stop the 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()) {
|
if (doku.isSolved()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user