functional multidoku printer

# Conflicts:
#	app/src/main/java/sudoku/io/ConsoleInterface.java
#	app/src/main/java/sudoku/solver/Solver.java
This commit is contained in:
Janet-Doe
2025-01-30 18:43:36 +01:00
parent 336d8378ae
commit 815756b5e9
5 changed files with 148 additions and 53 deletions

View File

@@ -1,21 +1,28 @@
package sudoku.io;
import gui.RenderableMultidoku;
import gui.Symbols;
import sudoku.constraint.*;
import sudoku.solver.Solver;
import sudoku.structure.Difficulty;
import sudoku.structure.MultiDoku;
import sudoku.structure.SudokuFactory;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.Scanner;
import sudoku.constraint.Constraint;
import sudoku.solver.RandomSolver;
import sudoku.structure.Difficulty;
import sudoku.structure.MultiDoku;
import sudoku.structure.Sudoku;
import sudoku.structure.SudokuFactory;
public class ConsoleInterface {
public Scanner reader = new Scanner(System.in);
public void welcome(){
System.out.println("Welcome to our Sudoku Solver!");
System.out.println("This is the project of Melvyn Bauvent, Lilas Grenier and Simon Priblyski.");
start();
}
public void start(){
welcome();
System.out.println("First of all, you need to tell me the size of the sudoku you want to generate.");
int width = getBlockWidth();
int height = getBlockHeight();
@@ -27,26 +34,21 @@ public class ConsoleInterface {
pickSymbols(listSymbols, numberOfSymbols);
}
else {
// TODO
System.out.println("Simon doit finir sa partie.");
assert false;
listSymbols = Symbols.Numbers.getSymbols();
}
List<Constraint> listConstraints = getListConstraints();
System.out.println("Now that we have the size of our sudoku, would you rather have a single grid ('one', default), " +
"or a a multidoku composed of 5 subgrids ('multi') ?");
List<Sudoku> subGrids = new ArrayList<>();
MultiDoku doku;
if (reader.next().equalsIgnoreCase("multi")) {
doku = SudokuFactory.createBasicEmptyRectangleDoku(width, height, listConstraints);
}
else {
doku = SudokuFactory.createBasicXShapedMultidoku(width, height, listConstraints);
}
else {
doku = SudokuFactory.createBasicEmptyRectangleDoku(width, height, listConstraints);
}
RenderableMultidoku rm = RenderableMultidoku.fromMultidoku(doku);
System.out.println("Your sudoku will look like this:");
// TODO printMultiDoku method not yet implemented
SudokuPrinter.printMultiDoku(doku, width, height);
SudokuPrinter.printMultiDoku(rm, listSymbols, width, height);
System.out.println("We now will fill this sudoku.");
System.out.println("What level of difficulty would you like? ('very easy', 'easy', 'medium' (default), 'hard', 'full' (sudoku fully completed))");
String difficulty = reader.next().toLowerCase();
@@ -57,12 +59,7 @@ public class ConsoleInterface {
generatePartialDoku(doku, difficulty);
}
System.out.println("Here's your sudoku !");
SudokuPrinter.printMultiDoku(doku, width, height);
}
public void welcome(){
System.out.println("Welcome to our Sudoku Solver!");
System.out.println("This is the project of Melvyn Bauvent, Lilas Grenier and Simon Priblyski.");
SudokuPrinter.printMultiDoku(rm, listSymbols, width, height);
}
public int getBlockWidth() {
@@ -132,7 +129,7 @@ public class ConsoleInterface {
}
private void generateFullDoku(MultiDoku doku) {
new RandomSolver().solve(doku);
Solver.randomSolve(doku, new Random());
}
}