Skip to content
Snippets Groups Projects
Commit 4d1369f1 authored by Nimrod Abramovich's avatar Nimrod Abramovich
Browse files

added difficulty setting

parent d9119293
No related branches found
No related tags found
No related merge requests found
No preview for this file type
No preview for this file type
...@@ -9,7 +9,6 @@ import java.util.ArrayList; ...@@ -9,7 +9,6 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Stack; import java.util.Stack;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream;
import javafx.application.*; import javafx.application.*;
import javafx.geometry.Insets; import javafx.geometry.Insets;
...@@ -27,8 +26,6 @@ import javafx.scene.control.Slider; ...@@ -27,8 +26,6 @@ import javafx.scene.control.Slider;
import javafx.scene.control.TextArea; import javafx.scene.control.TextArea;
import javafx.scene.control.TextField; import javafx.scene.control.TextField;
import javafx.scene.control.ToggleGroup; import javafx.scene.control.ToggleGroup;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent; import javafx.scene.input.MouseEvent;
import javafx.scene.layout.BorderPane; import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane; import javafx.scene.layout.GridPane;
...@@ -190,7 +187,7 @@ public class Main extends Application { ...@@ -190,7 +187,7 @@ public class Main extends Application {
Button generateRandomGameButton = new Button("Generate Random\nGame"); Button generateRandomGameButton = new Button("Generate Random\nGame");
generateRandomGameButton.setPrefWidth(loadGameFileButton.getPrefWidth()); generateRandomGameButton.setPrefWidth(loadGameFileButton.getPrefWidth());
generateRandomGameButton.setPrefHeight(50); generateRandomGameButton.setPrefHeight(60);
generateRandomGameButton.setStyle("-fx-text-alignment:center;"); generateRandomGameButton.setStyle("-fx-text-alignment:center;");
VBox leftVBox = new VBox(); VBox leftVBox = new VBox();
...@@ -373,29 +370,6 @@ public class Main extends Application { ...@@ -373,29 +370,6 @@ public class Main extends Application {
return slider; return slider;
} }
// private HBox setupRadioHBox() {
// HBox hboxMiddle = new HBox();
// ToggleGroup tg = new ToggleGroup();
// RadioButton easy = new RadioButton("Easy");
// easy.setToggleGroup(tg);
// RadioButton medium = new RadioButton("Medium");
// medium.setToggleGroup(tg);
// RadioButton hard = new RadioButton("Hard");
// hard.setToggleGroup(tg);
// hboxMiddle.setAlignment(Pos.CENTER);
// hboxMiddle.setSpacing(10);
// VBox radioVBox = new VBox(easy, medium, hard);
// radioVBox.setSpacing(5);
// hboxMiddle.getChildren().addAll(new Label("Difficulty:"), radioVBox);
//
// return hboxMiddle;
// }
private void solveGrid() {
Solver solver = new Solver(N, gridCages);
solver.solvePuzzel();
}
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
private void generateRandomGameEvent() { private void generateRandomGameEvent() {
Stage popupStage = new Stage(); Stage popupStage = new Stage();
...@@ -448,7 +422,7 @@ public class Main extends Application { ...@@ -448,7 +422,7 @@ public class Main extends Application {
resetGrid(); resetGrid();
int difficulty; int difficulty;
if (easy.isSelected()) { if (easy.isSelected()) {
difficulty = 1; difficulty = 1;
} }
else if (medium.isSelected()) { else if (medium.isSelected()) {
difficulty = 2; difficulty = 2;
...@@ -463,7 +437,7 @@ public class Main extends Application { ...@@ -463,7 +437,7 @@ public class Main extends Application {
gridCages = rg.generate(); gridCages = rg.generate();
}); });
popupStage.setScene(new Scene(vbox, 250, 250)); popupStage.setScene(new Scene(vbox, 240, 170));
popupStage.show(); popupStage.show();
} }
......
...@@ -12,7 +12,7 @@ public class RandomGenerator { ...@@ -12,7 +12,7 @@ public class RandomGenerator {
private int N; private int N;
private int[][] grid; private int[][] grid;
private int difficult; // 1 = easy | 2 = medium | 3 = hard private int difficulty; // 1 = easy | 2 = medium | 3 = hard
private List<Integer> uncagedGrids = new ArrayList<Integer>(); private List<Integer> uncagedGrids = new ArrayList<Integer>();
private List<Integer> possibleMoves = new ArrayList<Integer>(); private List<Integer> possibleMoves = new ArrayList<Integer>();
...@@ -20,6 +20,7 @@ public class RandomGenerator { ...@@ -20,6 +20,7 @@ public class RandomGenerator {
public RandomGenerator(int N, int difficulty) { public RandomGenerator(int N, int difficulty) {
this.N = N; this.N = N;
this.difficulty = difficulty;
grid = new int[N][N]; grid = new int[N][N];
} }
...@@ -37,15 +38,52 @@ public class RandomGenerator { ...@@ -37,15 +38,52 @@ public class RandomGenerator {
int cageProbability = random.nextInt(100); int cageProbability = random.nextInt(100);
int cageSize; int cageSize;
if (cageProbability < 50) {
switch (difficulty) {
case 1:
if (cageProbability < 15) {
cageSize = 1;
}
else if (cageProbability < 80) {
cageSize = 2;
}
else if (cageProbability < 95) {
cageSize = 3;
}
else {
cageSize = 4;
}
break;
case 2:
if (cageProbability < 50) {
cageSize = 2;
}
else if (cageProbability < 85) {
cageSize = 3;
}
else {
cageSize = 4;
}
break;
case 3:
if (cageProbability < 45) {
cageSize = 2;
}
else if (cageProbability < 75) {
cageSize = 3;
}
else if (cageProbability < 97) {
cageSize = 4;
}
else {
cageSize = 5;
}
break;
default:
cageSize = 2; cageSize = 2;
} }
else if (cageProbability < 85) {
cageSize = 3;
}
else {
cageSize = 4;
}
if (uncagedGrids.size() <= cageSize) { if (uncagedGrids.size() <= cageSize) {
cageSize = uncagedGrids.size(); cageSize = uncagedGrids.size();
...@@ -373,14 +411,14 @@ public class RandomGenerator { ...@@ -373,14 +411,14 @@ public class RandomGenerator {
grid = temp; grid = temp;
} }
private void output() { // private void output() {
for (int i = 0; i < N; i++) { // for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) { // for (int j = 0; j < N; j++) {
System.out.print(grid[i][j] + " "); // System.out.print(grid[i][j] + " ");
} // }
System.out.print("\n"); // System.out.print("\n");
} // }
System.out.print("\n"); // System.out.print("\n");
} // }
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment