diff --git a/images/startBot.png b/images/startBot.png index 743e36c..2273518 100644 Binary files a/images/startBot.png and b/images/startBot.png differ diff --git a/images/startLeft.png b/images/startLeft.png index a40ccc3..1705cec 100644 Binary files a/images/startLeft.png and b/images/startLeft.png differ diff --git a/images/startRight.png b/images/startRight.png index 108a427..dac5643 100644 Binary files a/images/startRight.png and b/images/startRight.png differ diff --git a/images/startUp.png b/images/startUp.png index a98bafd..a94f803 100644 Binary files a/images/startUp.png and b/images/startUp.png differ diff --git a/universe/Universe.java b/universe/Universe.java index d5fc66f..3fb6dd6 100644 --- a/universe/Universe.java +++ b/universe/Universe.java @@ -403,7 +403,15 @@ public class Universe { } public int[][] copyGrid() { - return this.grid.clone(); + int [][] newGrid = new int[this.height][this.width]; + + for (int i = 0; i < this.height; i++) { + for (int j = 0; j < this.width; j++) { + newGrid[i][j] = this.grid[i][j]; + } + } + + return newGrid; } public int getWidth() { diff --git a/userInterface/Grid.java b/userInterface/Grid.java index 8e25f79..e7edfa5 100644 --- a/userInterface/Grid.java +++ b/userInterface/Grid.java @@ -216,6 +216,7 @@ public class Grid extends JPanel { this.solving = true; Thread computeThread = new Thread(new Runnable() { + int [][] bestGrid; @Override public void run() { int [] startCoords = universe.getStartCoords(); @@ -232,11 +233,13 @@ public class Grid extends JPanel { Stack stack = new Stack (); Situation currentState = new Situation(firstState_i, firstState_j, start_dir, 0); - int [][] bestGrid = universe.copyGrid(); + this.bestGrid = universe.copyGrid(); + System.out.println(this.bestGrid[2][3] + " " + this.bestGrid + " " + universe.getGrid()); int best_filled_boxes = 0; int best_nb_mirrors = 0; long start = Instant.now().toEpochMilli(); + long lastRefresh = start; do { if (universe.canEvolve(currentState)) { @@ -244,10 +247,10 @@ public class Grid extends JPanel { currentState = universe.evolve(currentState); if ((universe.getFilledBoxes() > best_filled_boxes) || (universe.getFilledBoxes() == best_filled_boxes && universe.getNbMirrors() < best_nb_mirrors)) { - bestGrid = universe.copyGrid(); + this.bestGrid = universe.copyGrid(); best_filled_boxes = universe.getFilledBoxes(); best_nb_mirrors = universe.getNbMirrors(); - printUniverseGrid(bestGrid); + //printUniverseGrid(this.bestGrid); } } else if (stack.size() > 0) { @@ -256,8 +259,15 @@ public class Grid extends JPanel { } else { break; } + if (Instant.now().toEpochMilli() - lastRefresh > refreshRate) { + lastRefresh = Instant.now().toEpochMilli(); + printUniverseGrid(this.bestGrid); + + } } while (stack.size() != 0 && solving == true); + printUniverseGrid(bestGrid); + solving = false; String message = "Solved in " + ((Instant.now().toEpochMilli() - start)/1000) + "s and " + ((Instant.now().toEpochMilli() - start)%1000) + "ms \nMirrors : " + best_nb_mirrors + "\nLaser length : " + best_filled_boxes; alert(message);