bug resolution
Before Width: | Height: | Size: 424 B After Width: | Height: | Size: 428 B |
Before Width: | Height: | Size: 456 B After Width: | Height: | Size: 428 B |
Before Width: | Height: | Size: 451 B After Width: | Height: | Size: 393 B |
Before Width: | Height: | Size: 475 B After Width: | Height: | Size: 374 B |
|
@ -403,7 +403,15 @@ public class Universe {
|
||||||
}
|
}
|
||||||
|
|
||||||
public int[][] copyGrid() {
|
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() {
|
public int getWidth() {
|
||||||
|
|
|
@ -216,6 +216,7 @@ public class Grid extends JPanel {
|
||||||
this.solving = true;
|
this.solving = true;
|
||||||
|
|
||||||
Thread computeThread = new Thread(new Runnable() {
|
Thread computeThread = new Thread(new Runnable() {
|
||||||
|
int [][] bestGrid;
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
int [] startCoords = universe.getStartCoords();
|
int [] startCoords = universe.getStartCoords();
|
||||||
|
@ -232,11 +233,13 @@ public class Grid extends JPanel {
|
||||||
Stack <Situation> stack = new Stack <Situation>();
|
Stack <Situation> stack = new Stack <Situation>();
|
||||||
Situation currentState = new Situation(firstState_i, firstState_j, start_dir, 0);
|
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_filled_boxes = 0;
|
||||||
int best_nb_mirrors = 0;
|
int best_nb_mirrors = 0;
|
||||||
|
|
||||||
long start = Instant.now().toEpochMilli();
|
long start = Instant.now().toEpochMilli();
|
||||||
|
long lastRefresh = start;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if (universe.canEvolve(currentState)) {
|
if (universe.canEvolve(currentState)) {
|
||||||
|
@ -244,10 +247,10 @@ public class Grid extends JPanel {
|
||||||
currentState = universe.evolve(currentState);
|
currentState = universe.evolve(currentState);
|
||||||
|
|
||||||
if ((universe.getFilledBoxes() > best_filled_boxes) || (universe.getFilledBoxes() == best_filled_boxes && universe.getNbMirrors() < best_nb_mirrors)) {
|
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_filled_boxes = universe.getFilledBoxes();
|
||||||
best_nb_mirrors = universe.getNbMirrors();
|
best_nb_mirrors = universe.getNbMirrors();
|
||||||
printUniverseGrid(bestGrid);
|
//printUniverseGrid(this.bestGrid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (stack.size() > 0) {
|
else if (stack.size() > 0) {
|
||||||
|
@ -256,8 +259,15 @@ public class Grid extends JPanel {
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (Instant.now().toEpochMilli() - lastRefresh > refreshRate) {
|
||||||
|
lastRefresh = Instant.now().toEpochMilli();
|
||||||
|
printUniverseGrid(this.bestGrid);
|
||||||
|
|
||||||
|
}
|
||||||
} while (stack.size() != 0 && solving == true);
|
} while (stack.size() != 0 && solving == true);
|
||||||
|
|
||||||
|
printUniverseGrid(bestGrid);
|
||||||
|
|
||||||
solving = false;
|
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;
|
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);
|
alert(message);
|
||||||
|
|