diff --git a/bin/coursework/Main.class b/bin/coursework/Main.class index b3a2d151a82b17458c09c455a755a84257e3d373..ad335423a42f6e1153dad4b17f07b9fe36756ed1 100644 Binary files a/bin/coursework/Main.class and b/bin/coursework/Main.class differ diff --git a/bin/coursework/RandomGenerator.class b/bin/coursework/RandomGenerator.class index a8f01bdbc87bbb87844746bc98f29c1b24e0f285..7efe1c3f3f5edb7c8e9beb8d16c29525d3325525 100644 Binary files a/bin/coursework/RandomGenerator.class and b/bin/coursework/RandomGenerator.class differ diff --git a/src/coursework/Main.java b/src/coursework/Main.java index 6f5bc3b3ccdc0fde638531152880472612a24982..cbb2058f6cd7f649a7fd736bc0ea2ca6ed129dd6 100644 --- a/src/coursework/Main.java +++ b/src/coursework/Main.java @@ -9,7 +9,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Stack; import java.util.stream.Collectors; -import java.util.stream.Stream; import javafx.application.*; import javafx.geometry.Insets; @@ -27,8 +26,6 @@ import javafx.scene.control.Slider; import javafx.scene.control.TextArea; import javafx.scene.control.TextField; import javafx.scene.control.ToggleGroup; -import javafx.scene.image.Image; -import javafx.scene.image.ImageView; import javafx.scene.input.MouseEvent; import javafx.scene.layout.BorderPane; import javafx.scene.layout.GridPane; @@ -190,7 +187,7 @@ public class Main extends Application { Button generateRandomGameButton = new Button("Generate Random\nGame"); generateRandomGameButton.setPrefWidth(loadGameFileButton.getPrefWidth()); - generateRandomGameButton.setPrefHeight(50); + generateRandomGameButton.setPrefHeight(60); generateRandomGameButton.setStyle("-fx-text-alignment:center;"); VBox leftVBox = new VBox(); @@ -373,29 +370,6 @@ public class Main extends Application { 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() { Stage popupStage = new Stage(); @@ -448,7 +422,7 @@ public class Main extends Application { resetGrid(); int difficulty; if (easy.isSelected()) { - difficulty = 1; + difficulty = 1; } else if (medium.isSelected()) { difficulty = 2; @@ -463,7 +437,7 @@ public class Main extends Application { gridCages = rg.generate(); }); - popupStage.setScene(new Scene(vbox, 250, 250)); + popupStage.setScene(new Scene(vbox, 240, 170)); popupStage.show(); } diff --git a/src/coursework/RandomGenerator.java b/src/coursework/RandomGenerator.java index 8eddff0922c525e9367db1983f509b4af33bd710..7cda69ebd543949d71d4f200bb85769e0f4dbeee 100644 --- a/src/coursework/RandomGenerator.java +++ b/src/coursework/RandomGenerator.java @@ -12,7 +12,7 @@ public class RandomGenerator { private int N; 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> possibleMoves = new ArrayList<Integer>(); @@ -20,6 +20,7 @@ public class RandomGenerator { public RandomGenerator(int N, int difficulty) { this.N = N; + this.difficulty = difficulty; grid = new int[N][N]; } @@ -37,15 +38,52 @@ public class RandomGenerator { int cageProbability = random.nextInt(100); 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; } - else if (cageProbability < 85) { - cageSize = 3; - } - else { - cageSize = 4; - } + if (uncagedGrids.size() <= cageSize) { cageSize = uncagedGrids.size(); @@ -373,14 +411,14 @@ public class RandomGenerator { grid = temp; } - private void output() { - for (int i = 0; i < N; i++) { - for (int j = 0; j < N; j++) { - System.out.print(grid[i][j] + " "); - } - System.out.print("\n"); - } - System.out.print("\n"); - } +// private void output() { +// for (int i = 0; i < N; i++) { +// for (int j = 0; j < N; j++) { +// System.out.print(grid[i][j] + " "); +// } +// System.out.print("\n"); +// } +// System.out.print("\n"); +// } } \ No newline at end of file