This commit is contained in:
@@ -15,14 +15,13 @@ import java.util.Scanner;
|
||||
public class ConsoleInterface {
|
||||
public Scanner reader = new Scanner(System.in);
|
||||
|
||||
public void welcome(){
|
||||
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.");
|
||||
System.out.println("Do you have a save sudoku you would like to continue? (y/n, default n)");
|
||||
if (reader.next().equalsIgnoreCase("y")){
|
||||
if (reader.next().equalsIgnoreCase("y")) {
|
||||
useSavedDoku();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
createDoku();
|
||||
}
|
||||
}
|
||||
@@ -32,27 +31,26 @@ public class ConsoleInterface {
|
||||
MultiDoku md = saveChoice();
|
||||
int blockWidth = md.getSubGrid(0).getBlockWidth();
|
||||
int blockHeight = md.getSubGrid(0).getBlocks().getFirst().getCells().size() / blockWidth;
|
||||
List<String> listSymbols = pickSymbols(blockWidth*blockHeight);
|
||||
List<String> listSymbols = pickSymbols(blockWidth * blockHeight);
|
||||
System.out.println("This is the saved sudoku:");
|
||||
showMultidoku(md, listSymbols, blockWidth, blockHeight);
|
||||
}
|
||||
|
||||
public void createDoku(){
|
||||
public void createDoku() {
|
||||
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();
|
||||
System.out.println("Your sudoku will have blocks of a " + width + " x " + height + " format.");
|
||||
int numberOfSymbols = width * height;
|
||||
List<String> listSymbols = pickSymbols(numberOfSymbols);
|
||||
List<Constraint> listConstraints = getListConstraints();
|
||||
List<IConstraint> 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') ?");
|
||||
MultiDoku doku;
|
||||
if (reader.next().equalsIgnoreCase("multi")) {
|
||||
doku = SudokuFactory.createBasicXShapedMultidoku(width, height, listConstraints);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
doku = SudokuFactory.createBasicEmptyRectangleDoku(width, height, listConstraints);
|
||||
}
|
||||
System.out.println("Your sudoku will look like this:");
|
||||
@@ -63,8 +61,7 @@ public class ConsoleInterface {
|
||||
String difficulty = reader.next().toLowerCase();
|
||||
if (difficulty.equals("full")) {
|
||||
generateFullDoku(doku);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
generatePartialDoku(doku, difficulty);
|
||||
}
|
||||
System.out.println("Here's your sudoku !");
|
||||
@@ -116,7 +113,8 @@ public class ConsoleInterface {
|
||||
}
|
||||
|
||||
private List<String> pickSymbols(int numberOfSymbols) {
|
||||
System.out.println("Would you like to pick the " + numberOfSymbols + " symbols from the sudoku? (y/n, default 'no' will use numbers)");
|
||||
System.out.println("Would you like to pick the " + numberOfSymbols
|
||||
+ " symbols from the sudoku? (y/n, default 'no' will use numbers)");
|
||||
if (reader.next().equalsIgnoreCase("y")) {
|
||||
List<String> listSymbols = new ArrayList<>();
|
||||
System.out.println("You have chosen to pick your own symbols.");
|
||||
@@ -132,7 +130,8 @@ public class ConsoleInterface {
|
||||
System.out.println("You chose the symbols: " + listSymbols.toString());
|
||||
return listSymbols;
|
||||
} else {
|
||||
System.out.println("What existing sets of symbols do you want to use? Numbers ('n', default), letters ('l'), or emojis ('e')?");
|
||||
System.out.println(
|
||||
"What existing sets of symbols do you want to use? Numbers ('n', default), letters ('l'), or emojis ('e')?");
|
||||
return switch (reader.next().toLowerCase()) {
|
||||
case "l" -> Symbols.Letters.getSymbols();
|
||||
case "e" -> Symbols.Emojis.getSymbols();
|
||||
@@ -141,22 +140,27 @@ public class ConsoleInterface {
|
||||
}
|
||||
}
|
||||
|
||||
private List<Constraint> getListConstraints() {
|
||||
List<Constraint> listConstraints = SudokuFactory.DEFAULT_CONSTRAINTS;
|
||||
System.out.println("The sudoku have constraints of blocks, lines and columns. Would you like to add the diagonal constraints ? (y/n, default 'no')");
|
||||
if(reader.next().equalsIgnoreCase("y")){
|
||||
listConstraints.add(Constraint.Diagonal);
|
||||
private List<IConstraint> getListConstraints() {
|
||||
List<IConstraint> listConstraints = SudokuFactory.DEFAULT_CONSTRAINTS;
|
||||
System.out.println(
|
||||
"The sudoku have constraints of blocks, lines and columns. Would you like to add the diagonal constraints ? (y/n, default 'no')");
|
||||
if (reader.next().equalsIgnoreCase("y")) {
|
||||
listConstraints.add(Constraint.Diagonal.getConstraint());
|
||||
}
|
||||
return listConstraints;
|
||||
}
|
||||
|
||||
private void generatePartialDoku(MultiDoku doku, String difficultyName) {
|
||||
Difficulty difficulty;
|
||||
switch (difficultyName){
|
||||
case "very easy": difficulty = Difficulty.VeryEasy;
|
||||
case "easy": difficulty = Difficulty.Easy;
|
||||
case "hard": difficulty = Difficulty.Hard;
|
||||
default: difficulty = Difficulty.Medium;
|
||||
switch (difficultyName) {
|
||||
case "very easy":
|
||||
difficulty = Difficulty.VeryEasy;
|
||||
case "easy":
|
||||
difficulty = Difficulty.Easy;
|
||||
case "hard":
|
||||
difficulty = Difficulty.Hard;
|
||||
default:
|
||||
difficulty = Difficulty.Medium;
|
||||
}
|
||||
try {
|
||||
SudokuFactory.fillDoku(doku, difficulty);
|
||||
@@ -169,15 +173,15 @@ public class ConsoleInterface {
|
||||
new RandomSolver().solve(doku);
|
||||
}
|
||||
|
||||
private void showMultidoku(MultiDoku doku, List<String> listSymbols, int width, int height){
|
||||
private void showMultidoku(MultiDoku doku, List<String> listSymbols, int width, int height) {
|
||||
showMultiDoku(RenderableMultidoku.fromMultidoku(doku), listSymbols, width, height);
|
||||
}
|
||||
|
||||
private void showMultiDoku(RenderableMultidoku doku, List<String> listSymbols, int width, int height){
|
||||
private void showMultiDoku(RenderableMultidoku doku, List<String> listSymbols, int width, int height) {
|
||||
SudokuPrinter.printMultiDoku(doku, listSymbols, width, height);
|
||||
}
|
||||
|
||||
private void saveMultiDoku(MultiDoku doku){
|
||||
private void saveMultiDoku(MultiDoku doku) {
|
||||
System.out.println("Number of the file to overwrite ('-1' or unused save file number to create a new save) :");
|
||||
int n = reader.nextInt();
|
||||
String path = SudokuSerializer.saveMultiDoku(doku, n);
|
||||
|
||||
Reference in New Issue
Block a user